CS 202 Fall 2013 > In-Class Challenge for Thursday, October 31, 2013 |
CS 202 Fall 2013
In-Class Challenge for Thursday, October 31, 2013
Program multiprint.cpp
I have written part of a program,
in file
multiprint.cpp
.
This program calls a function
that does not exist.
Your job is to write it,
as a function template that signals an error
by throwing an exception.
What to Do
- Write a function template
multiPrint
in filemultiprint.cpp
, so that it conforms to the following specification.multiPrint
takes two parameters: anint
namedn
, and another parameter that can be of any type.- If parameter
n
is negative, then the function throws an exception of typedomain_error
, with an explanatory message in the string member. - Otherwise, the function prints its second parameter
to
cout
,n
times, each on a separate line, ending with a newline. For example “multiprint(3, 42)
” should print the following.42 42 42
- Make it so that
multiPrint
treats its second parameter a bit differently if it is anint
. In that case, the second parameter should be printedn
times on each line. So “multiprint(3, 42)
” will now print the following.42 42 42 42 42 42 42 42 42
But “
multiprint(2, "abc")
” will still print the same thing as before.abc abc
CS 202 Fall 2013: In-Class Challenge for Thursday, October 31, 2013 /
Updated: 31 Oct 2013 /
Glenn G. Chappell