Assignment 03
Home ] Up ]

 

CSIS 250 2002 Spring

Assignment 03

Date Assigned: 03/01/2002

Date Due: 03/08/2001

 

Add the following member/friend functions/operators and corresponding test functions to the CRectangle implementation (crect05.cpp) as discussed in the class.

§         int area(void);
to calculate and return the area of a rectangle

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

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

§         friend istream & operator >> (istream &bob, CRectangle &rec);
extraction operator for CRectangle 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 detailed documentation as mentioned in the class, 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 (will be posted later on the Web)

 

Your Name:

Self-evaluation Table for CSIS 250 Project 03

 

 

Max Score

Score

area

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Class member/friend of

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Shared member names

1

 

Local variables used

1

 

Source code

1

 

operator <

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Class member/friend of

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Shared member names

1

 

Local variables used

1

 

Source code

1

 

operator <=

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Class member/friend of

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Shared member names

1

 

Local variables used

1

 

Source code

1

 

operator >>

Name

1

 

Description

1

 

Examples

1

 

Algorithm

1

 

Class member/friend of

1

 

Prototype

1

 

Returns

1

 

Parameters

1

 

Shared external names

1

 

Shared member names

1

 

Local variables used

1

 

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

76

 


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)

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