CMSC 202 Spring 2003
Lab Assignment 6

Name:_____________________________________ Checked:__________________________________
SSN:______________________________________ Date:_____________________________________

Purpose

  1. Introduction to dynamic memory allocation: Pointers and the new and delete operators.
  2. Overloading the assignment operator.

The Assignment

  1. Copy the file /afs/umbc.edu/users/a/n/aniket1/pub/202/labs/lab6/Rectangle.H to a convenient directory for this lab.
  2. This header file defines an interface to class Rectangle with the float* attributes length and width. Create a file Rectangle.C to implement the member functions.
  3. Implement the constructor for the class, such that both attributes default to 0. Both the attributes have to be dynamically allocated when a Rectangle object is created.
  4. Implement the member functions to calculate the perimeter and the area of the rectangle.
  5. Implement accessor functions for the two attributes.
         float GetLength(void) const;
         float GetWidth(void) const;
  6. Implement mutator functions for the two attributes.
         void SetLength(float length);
         void SetWidth(float width);
  7. Provide a destructor that frees all memory allocated dynamically.
  8. Overload the assignment operator so that statements like
         Rectangle r1, r2;
         r2 = r1;
    are allowed.
  9. Copy the file /afs/umbc.edu/users/a/n/aniket1/pub/202/labs/lab6/RectangleTest.C This file contains a program that will test the class you have created.
  10. Copy the file /afs/umbc.edu/users/a/n/aniket1/pub/202/labs/lab6/Makefile. Then type make at the command prompt to compile the test program and create the executable RectangleTest.
  11. Run the program.
  12. Have the TA verify your work so that you receive credit for today's lab.

Feedback

  1. Please tell us how helpful this lab was to you on a scale of 1 (waste of time) to 10 (very helpful):______
  2. If you have comments you can write them on this page, or email aniket1@cs.umbc.edu