C++ Review: Classes Exercises


Exercise 1

Using the file point.cpp, add a member function print to the class Point so that it prints out coordinates as:
	(2, 3)
for a point with coordinates (2, 3). Test it in main().

Exercise 2

Write a definition of a class Rectangle using the Point class. A rectangle is specified by two corner points (bottom left and top right). The sides of the rectangle are parallel to the coordinate axes. The implementation of the class should be as follows:
Test the class Rectangle in main(), demonstrate that all member functions work as specified.

Exercise 3

Add two private member functions side1, side2 to the class Rectangle to compute the lengths of the two sides. Using this function, write a public member function to compute the area of the rectangle.



Original page created by Jisook Youn and Jing Zhong for cs111.
Modified by Gali Diamant gali@cs.bu.edu, spring 2003.
Material partially taken from the textbook "Computing Concepts with C++ Essentials", by Horstmann.

Last modified Jan 22, 2003