Download presentation
Presentation is loading. Please wait.
1
1 Lab Session-9 CSIT221 Fall 2002 Lab Exercise Based on operator overloading (Demo Required)
2
2 Lab Exercise (Demo Due Nov 5th Sec 01 and Nov 7 th Sec 02) Develop a class definition for pixels. Pixels are points displayed on a computer screen #include using namespace std; class pixel { int x; int y; int intensity; public: pixel(); //default constructor pixel(int,int,int); //parameterized constructor void print_values(); //display function pixel operator+(pixel &p); //overloaded add pixel operator- (pixel &p); //overloaded subtract };
3
3 Client Code void main() { pixel circle1(12,13,15); pixel oval1(2,3,5); pixel circle2; circle1.print_values(); oval1.print_values(); circle2 = circle1-oval1; circle2.print_values(); }
4
4 Test it!! If you are able to develop the implementation part correctly, you will see the following output from the client code: construct it //from default constructor x and y are 12 13 //from print_values function x and y are 2 3 // from print_values function This is the overload //from overloaded operator x and y are 10 10 //from print_values function Press any key to continue
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.