You are using a version without Ads of this website. Please, consider donating:

### who can help me ^_^

If i have a class school ....

how can i write this function because i cant understand it !!

 ``12345678910`` ``````c) Function called Add which takes two school objects and return a school object. The resulted object contains the name and the type of the first object, while it contains the sum of the number of students found in the two objects, and the sum of the number of teachers found in the two objects. ``````

 ``1234567`` ``````e) Function called Larger which takes two school objects as parameters and return 1 if the first school has larger number of students, 0 if they are equal, and -1 if the first school has smaller number of students than the second.``````
c) `School Add(School& sc1, School& sc2);`

e) `int Larger(School& sc1, School& sc2);`

That should get you started.
ok thx i will see what can i do ^_^
no i cant do it :( please some one help me am tired !!
Larger is pretty easy.
 ``1234567`` ``````int Larger(School& sc1, School& sc2) { if (sc1.num_students > sc2.num_students) return 1; if (sc1.num_students < sc2.num_students) return -1; return 0; // must be equal }``````

Add is not much harder. You just need a temporary instance.
 ``1234567`` ``````School Add(School& sc1, School& sc2) { School temp; temp = sc1; // Copy sc1 temp.num_students = sc1.num_students + sc2.num_students; temp.num_teachers = sc1.num_teachers + sc2.num_teachers; return temp; }``````

what's the temp mean in add function !!

and they give me a syntax on num_students!!

 what's the temp mean in add function

It's simply a temporary object of type School. It goes out of scope at the end of the function, but we need it to construct the resulting object that we're going to return. We could have named it result instead. We don't want to modify either sc1 or sc2.

 and they give me a syntax on num_students

You didn't post the declaraction of School in this thread, so I had to guess what the variable was called. I picked the most obvious variable name I could think of. If you named it something else, you're going to have to change the code I posted accordingly.
Last edited on
mmmm look am changing the name but they tell me there's wrong in constructor

i will chick some thing to see if it's write or no ^_^
all of my code is :

so what's do you think !!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244`` ``````#include #include #include using namespace std; class School { public: School(string,string ,int ,int ,string[],int ); void setname(string); string getname(); void settype(string); string gettype(); void settot_student(int); int gettot_student(); void settot_teachers(int); int gettot_teachers(); void setArray(string[],int); string getArray(int); void Display(); void sc1(); void sc2(); School Add(School , School ); int Find(int); // int Larger(School , School ); int Even(); private: string name; string type; int tot_student; int tot_teachers; string Array[6]; }; School::School(string n,string s,int st,int teach,string course[],int A) { name=n; type=s; tot_student=st; tot_teachers=teach; for(A=0;A<6;A++) { Array[A]=course[A];} } void School::setname(string n) { name=n; } string School::getname() { return name; } void School::settype(string s) { type=s; } string School::gettype() { return type; } void School::settot_student(int st) { tot_student=st; } int School::gettot_student() { return tot_student; } void School::settot_teachers(int teach) { tot_teachers=teach; } int School::gettot_teachers() { return tot_teachers; } void School::setArray(string course[],int s) { for(s=0;s<6;s++) { Array[s]; cout<<"the name of course: "; cin>>Array[s]; cout<>Array[s]; return Array[s]; } void School::Display() { cout<<"Information about school :"<>s; if((Array[s]==Array[0])||(Array[s]==Array[1])||(Array[s]==Array[2])||(Array[s]==Array[3])||(Array[s]==Array[4])||(Array[s]==Array[5])) {return 1; cout< sc2.tot_student) return 1; if (sc1.tot_student < sc2.tot_student) return -1; return 0; // must be equal } int School::Even() { int sum; sum=tot_student+tot_teachers; if(sum % 2==0) return 1; else return 0; } int main() { string Array[6]; School T("hu","secoundry ",450,150,Array,6); School sc1(); School sc2(); cout<<"calling the setname fun"<
oh thx lool i found the error ^_^
lool hhhh

if i want return

 ``12`` ``````cout<<"calling the Add fun"<

what must i do here ! !
What do the instructions tell you?
 Add which takes two school objects and returns a school object.

Hint. You need to do something with the returned object.
so !! , did you men i must put abject !!

look my friend this is all me code so is there any thing lost !!

help me my friend really i need help am beginner teach me please ^_^
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: