|
Add the following functions/operators and corresponding test functions to the TRectangle implementation (rect03.cpp) as discussed in the class. §
int area(const TRectangle
&rec); §
bool operator < (const
TRectangle &rec1, const TRectangle &rec2); §
bool operator <= (const
TRectangle &rec1, const TRectangle &rec2); §
istream & operator
>> (istream &bob, TRectangle &rec); §
void testArea(void); §
void
testOperatorLessThan(void); §
void
testOperatorLessThanOrEqualTo(void); §
void
testOperatorExtraction(void); For each function, include a detailed description, detailed algorithm, and properly indented source code. Submit the following: § Printed source code of the working program (to get any credit the program has to work) § Printed output § Self-evaluation table
The main driver should be as follows:
void main(void) { srand(time(NULL)); testArea(); testOperatorLessThan(); testOperatorLessThanOrEqualTo(); testOperatorExtraction(); }
The output from the program should be similar to the following:
============== test area(rec) ============== rect(1, 9) Area = 9 ------------------ rect(7, 2) Area = 14 ------------------ rect(3, 6) Area = 18 ------------------ rect(1, 8) Area = 8 ------------------ rect(6, 6) Area = 36 ------------------ ================ test operator < ================ rec1 = rect(5, 5) rec2 = rect(8, 2) area of rec1 = 25 area of rec2 = 16 area of rec1 is not < area of rec2 ------------------ rec1 = rect(9, 7) rec2 = rect(1, 2) area of rec1 = 63 area of rec2 = 2 area of rec1 is not < area of rec2 ------------------ rec1 = rect(9, 10) rec2 = rect(4, 2) area of rec1 = 90 area of rec2 = 8 area of rec1 is not < area of rec2 ------------------ rec1 = rect(10, 3) rec2 = rect(8, 3) area of rec1 = 30 area of rec2 = 24 area of rec1 is not < area of rec2 ------------------ rec1 = rect(9, 6) rec2 = rect(9, 4) area of rec1 = 54 area of rec2 = 36 area of rec1 is not < area of rec2 ------------------ ================= test operator <= ================= rec1 = rect(8, 1) rec2 = rect(10, 1) area of rec1 = 8 area of rec2 = 10 area of rec1 <= area of rec2 ------------------ rec1 = rect(9, 10) rec2 = rect(4, 2) area of rec1 = 90 area of rec2 = 8 area of rec1 not <= area of rec2 ------------------ rec1 = rect(2, 7) rec2 = rect(3, 4) area of rec1 = 14 area of rec2 = 12 area of rec1 not <= area of rec2 ------------------ rec1 = rect(4, 2) rec2 = rect(1, 2) area of rec1 = 8 area of rec2 = 2 area of rec1 not <= area of rec2 ------------------ rec1 = rect(1, 9) rec2 = rect(7, 2) area of rec1 = 9 area of rec2 = 14 area of rec1 <= area of rec2 ------------------ ================= test operator >> ================= Length: 1 Width: -2 Width: 2 rect(1, 2) ------------------ Length: 3 Width: 4 rect(3, 4) ------------------ Length: 5 Width: 6 rect(5, 6) ------------------ Length: 7 Width: 8 rect(7, 8) ------------------ Length: 9 Width: 10 rect(9, 10) ------------------
|