Assignment 02
Home ] Up ]

 

CSIS 250 2002 Spring

Assignment 02

Date Assigned: 02/11/2002

Date Due: 02/20/2001

 

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);
to calculate and return the area of a rectangle

§         bool operator < (const TRectangle &rec1, const TRectangle &rec2);
to compare the areas of two rectangles

§         bool operator <= (const TRectangle &rec1, const TRectangle &rec2);
to compare the areas of two rectangles

§         istream & operator >> (istream &bob, TRectangle &rec);
extraction operator for TRectangle type

§         void testArea(void);
to test area function

§         void testOperatorLessThan(void);
to test operator <

§         void testOperatorLessThanOrEqualTo(void);
to test operator <=

§         void testOperatorExtraction(void);
to test operator >>

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)

------------------

 

Your Name:

 

Self-evaluation Table for CSIS 250 Project 02

 

 

Max Score

Score

area

Description

1

 

Algorithm

1

 

Properly indented source code

1

 

operator <

Description

1

 

Algorithm

1

 

Properly indented source code

1

 

operator <=

Description

1

 

Algorithm

1

 

Properly indented source code

1

 

operator >>

Description

1

 

Algorithm

1

 

Properly indented source code

1

 

testArea

Description

1

 

Properly indented source code

1

 

Output from 5 iterations

5

 

testOperatorLessThan

Description

1

 

Properly indented source code

1

 

Output from 5 iterations

5

 

testOperatorLessThanOrEqualTo

Description

1

 

Properly indented source code

1

 

Output from 5 iterations

5

 

testOperatorExtraction

Description

1

 

Properly indented source code

1

 

Output from 5 iterations

5

 

Total Score

40