Project03
Home ] Up ]

 

CSIS 250 Spring 2000 Assignment #3

Date Assigned: February 9, 2000

Date Due: February 18, 2000

 

1.      Create a class CRectangle.

2.      The class has attributes length and width of integer type, each of which defaults to 1.

3.      It has member functions that calculate the perimeter and the area of the rectangle.

4.      It has set and get functions for both length and width.  The set function should verify that length and width are each integer values larger than 0 and less than 20.

5.      A display function to show the dimensions of a rectangle.

6.      Another constructor with given values for length and width.

7.      A function to set the length and width of the rectangle.

8.      A function to get the length and width of the rectangle.

Use the following class declaration and the comments as a guide.

Write the necessary test functions (one test function for each function) to make sure that each function works properly.

Submit the following items:

1.      Printed source code

2.      Output from the sample runs

3.      Self-evaluation sheet

 

class CRectangle

  {

  private:

    int length;

    int width;

  public:

    CRectangle(void);                       //default constructor

    CRectangle(int len, int wid);           //another constructor

    int perimeter(void);                    //returns perimeter

    int area(void);                         //returns area

    void setDimension(int len, int wid);    //sets length and width

    void setLength(int len);                //sets length

    void setWidth(int wid);                 //sets width

    int getLength(void);                    //returns length

    int getWidth(void);                     //returns width

    void getDimension(int &len, int &wid);  //gets length and width

    void display(void);                     //displays length and width

  };

 

Self-Evaluation Form

Function member

 

Maximum Score

Your Score

CRectangle(void);

3

 

CRectangle(int len, int wid);

3

 

int perimeter(void);

3

 

int area(void);

3

 

void setDimension(int len, int wid);

3

 

void setLength(int len);

3

 

void setWidth(int wid);

3

 

int getLength(void);

3

 

int getWidth(void);

3

 

void getDimension(int &len, int &wid);

3

 

void display(void);

3

 

Total points for source code, test function, and sample output for all the functions above

33