|
|||||||
| ملتقى البرامج والانترنات والجرافيكس كل ما يختص بالكمبيوتر والانترنات من برامج ومعلومات وخدمات مجانية |
|
|
أدوات الموضوع | انواع عرض الموضوع |
|
#18
|
||||
|
||||
|
[quote=zaynubya;671338]****** 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. السلام عليكم ورحمة الله وبركاته ،،، أختي الكريمة zaynubya لقد قمت ببرمجة هذه الجزئية من البرنامج وإن شاء الله تستفيدي منها ، إليك الكود المطلوب والباقي سأحاول برمجته في أسرع وقت ممكن : First: Define the class "Set" # include <iostream.h> class Set { public : Set(){ N = 0; } // Default constructor void add( Set& S, int x); void Remove( Set& S, int x); void print( ); private: int N; int e[20]; } ; Second: This is the function "add" written after main() function void Set :: add( Set& S, int x ) { S.e[ N ] = x; N += 1; } Third: This is the function "Remove" written after main() function void Set :: Remove( Set& S, int x ) { int j = 0; for (int i = 0; i < S.N; i++ ) if (( S.e[i] == x) || j) { S.e[i] = S.e[i + 1]; j = 1; } if ( j ) S.N -= 1; } Fourth: This is the function "print" written after main() function void Set :: print () { cout << " \n\nYour Set is : \n\n\tS = { "; for (int i = 0; i < N -1 ; i++) cout << e[i] << ", "; if (N) cout << e[i] << " } \n\n"; else cout << " } \n\n"; }
__________________
عَنْ عَبْدِ اللَّهِ بْنِ مَسْعُودٍ رَضِيَ اللَّهُ تَعَالَى عَنْهُ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ:
|
| الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
| أدوات الموضوع | |
| انواع عرض الموضوع | |
|
|
|
|
|
Powered by vBulletin V3.8.5. Copyright © 2005 - 2013, By Ali Madkour |