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
StarRect
should be implemented in header filestarrect.h
and source filestarrect.cpp
. - An object of type
StarRect
should act as if it maintains two pieces of data:- An
int
holding the width of a rectangle. - An
int
holding the height of a rectangle.
- An
- Class
StarRect
should have the following member functions:- A default constructor. This can set the data members however you want.
- A two-parameter constructor that takes two
int
parameters. 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 optionalostream
parameter; usecout
if 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 is4
and 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
const
qualifier 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.h
andstarrect.cpp
that compile with the test programtest_starrect.cpp
. - Implement class
StarRect
as 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