.
class PAIR {private: int a; int b; public: void print(); PAIR(); PAIR(int); PAIR(int,int); ~PAIR(); void swap(); int diff(); int big(); int area(); }; int main() { PAIR c, d(2), e(12,13); int ans; c.print(); d.print(); e.print(); d.swap(); d.print(); e.swap(); e.print(); ans = c.diff(); cout << "\nThe answer to c.diff() is " << ans << endl; int big = e.big () ; cout << "\nThe larger number of e.big() is " << big << endl << endl; return 0; } PAIR::PAIR() { a = 2; b = 3; } void PAIR::print() {cout << a << " " << b << endl;} PAIR:: ~PAIR() { cout << "Display Destructor Message" << endl; } PAIR::PAIR(int p1) {a=p1; b=p1;} PAIR::PAIR(int p1,int p2) { a=p1; b=p2; } void PAIR::swap() { int c; c=a; a=b; b=c; } int PAIR::diff() { return b - a; } int PAIR::big() { if (a > b) { return a; } else { return b; } } // this was missing int PAIR::area() { int z; z=(a*b); { return z; } } // } // this is extra brace
The things marked in red by me are the culprits. WHy dont u format the code properly so that typographic errors will be minimised. Do you write your code in Notepad. If so grab your self a syntax highlighter code editor which makes automatically proper indentations like Code::BLocks or Dev Bloodshed.
The links for the above IDE can be found at teh top of this forum in the thread named "Starting C".
Hope it helped, bye.
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734