| CS 202 Fall 2013 > In-Class Challenge for Thursday, September 19, 2013 |
CS 202 Fall 2013
In-Class Challenge for Thursday, September 19, 2013
This challenge deals with a C++ class StarRect.
It is initially specified as follows.
What you are actually to do is found below.
Class StarRect Initial Specification
- Class
StarRectshould be implemented in header filestarrect.hand source filestarrect.cpp. - An object of type
StarRectshould act as if it maintains two pieces of data:- An
intholding the width of a rectangle. - An
intholding the height of a rectangle.
- An
- Class
StarRectshould have the following member functions:- A default constructor. This can set the data members however you want.
- A two-parameter constructor that takes two
intparameters. It sets its width equal to the first parameter and its height equal to the second. - Get and set functions for the two numbers,
written as usual, and named
getWidth,setWidth,getHeight,setHeight. - Function
print. This should take an optionalostreamparameter; usecoutif the parameter is not given. It should print to the given stream a rectangle of stars (“*”) with the given width and height, ending with a newline. For example, if the width is4and the height is3, then the following should be printed to the stream.**** **** ****
- The class should be implemented according to standard conventions regarding header & source file separation, etc.
- The
constqualifier should be used correctly. - Your package should compile with the test program
test_starrect.cpp.
What to Do
Do as many of the following as you can before class ends. After each, please show me your work.
- Write minimal versions of files
starrect.handstarrect.cppthat compile with the test programtest_starrect.cpp. - Implement class
StarRectas above, so that all tests pass. - Add an additional option to the class:
allow a character other than “
*” to be used in the rectangle. The resulting class should still compile with the test program and pass all tests.
CS 202 Fall 2013: In-Class Challenge for Thursday, September 19, 2013 /
Updated: 19 Sep 2013 /
Glenn G. Chappell