|
|||||||
| ملتقى البرامج والانترنات والجرافيكس كل ما يختص بالكمبيوتر والانترنات من برامج ومعلومات وخدمات مجانية |
|
|
أدوات الموضوع | انواع عرض الموضوع |
|
#17
|
|||
|
|||
|
****** Oriented Programming
Write a program to carry out manipulation on sets. Create a class called set with two private members, the elements of the set and the size of the set. The elements should be an array of integers to hold an appropriate number of elements (e.g. 20). Provide a default constructor to initialize a newly defined set to be the empty set, the size of which should be zero. Provide also three utility functions to add, remove and to print elements of a set. Provide for class set that you have developed member functions to implement the following operations on sets using appropriate member functions: a) Determine the union of two sets and store the result in a third set; b) Determine the intersection of two sets and store the result in a third set; c) To test if a given set is the empty set; d) To test if one set is included in another set. Hint: The class should have data members an array of integers of a large size (for ex 20) and N= number of elements in the set. As you first create the set, N=0 (set by the constructor) The add function should add one element to the set. and not add two sets. void set::add(set &S, int x) will make x an element of the set S. for example, if S1 is still the empty set, and we call function add to add element 2 to S1, then S1 becomes: S1 = {2}, N=1. To add element 3: S1={2,3}, N=2 To remove element 2, S1={3}, N=1 therefore to remove an element, in the implementation of that function, we search the array to see if that element exists, and then if found, you have to slide the remaining elements back one position (i.e. no empty spots should exist in the array.) A utility function is a member function that can return a set. But you don't need the add function to return a set. Whereas the union and intersection functions may return the resulting set. If you really need a function (get or set) you can add it and justify its need in the comments.
__________________
بالصبر تبلغ ما ترجوه من أمل *** فاصبر فلا ضيق إلا بعده فرج ![]() ![]() |
| الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
|
|
|
|
|
Powered by vBulletin V3.8.5. Copyright © 2005 - 2013, By Ali Madkour |