CMSC 202 Spring 2003
Lab Assignment 6
Name:_____________________________________ Checked:__________________________________
SSN:______________________________________ Date:_____________________________________
Purpose
- Introduction to dynamic memory allocation: Pointers and the
new and delete operators.
- Overloading the assignment operator.
The Assignment
- Copy the file
/afs/umbc.edu/users/a/n/aniket1/pub/202/labs/lab6/Rectangle.H to a
convenient directory for this lab.
- 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.
- 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.
- Implement the member functions to calculate the perimeter and the
area of the rectangle.
- Implement accessor functions for the two attributes.
float GetLength(void) const;
float GetWidth(void) const;
- Implement mutator functions for the two attributes.
void SetLength(float length);
void SetWidth(float width);
- Provide a destructor that frees all memory allocated
dynamically.
- Overload the assignment operator so that statements like
Rectangle r1, r2;
r2 = r1;
are allowed.
- 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.
- 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.
- Run the program.
- Have the TA verify your work so that you receive credit for today's lab.
Feedback
- Please tell us how helpful this lab was to you on a scale of 1 (waste
of time) to 10 (very helpful):______
- If you have comments you can write them on this page, or email
aniket1@cs.umbc.edu