Assignment 3: Functions, due Monday, 10/4/99
For this assignment, write the three functions
described below. A few notes:
- You will need to test the functions using a main program
of your own devising, but you should hand in a source file
that contains only the functions themselves, along with
any #include statements they require. Do not include
a main() in the file you hand in.
- For this assignment, please work on your own. You may
still discuss the assignment and approaches to it with
friends, Robin the SI leader, or lab assistants, but please
write and submit your own code.
- Note that none of these three functions should communicate
directly with the user. That is, they should not have
any input (cin) or output (cout) statements in them. The main
program(s) you use to test your functions may very well want
to talk to the user, but the functions themselves should remain
silent.
If you have any questions, let me know. Have fun, start early, and keep in touch.
//////////////////////////////////////////////////////////////////
//
// IsPerfect returns true if the given integer N is
// a perfect number, and false otherwise.
//
// N is perfect if it is positive and the sum of its
// factors (not including N itself) is equal to N.
// For example, 28 is perfect, since 1 + 2 + 4 + 7 + 14 = 28.
// 12 is not perfect, since 1 + 2 + 3 + 4 + 6 != 12.
//
//////////////////////////////////////////////////////////////////
bool IsPerfect( int N )
{
}
//////////////////////////////////////////////////////////////////
//
// ReduceFraction
//
// Preconditions: numerator and denominator contain the
// numerator and denominator of a fraction to be reduced.
//
// Postconditions:
// 1. The parameters contain the numerator and denominator
// of the reduced fraction.
//
// 2. If the fraction is positive, both numerator and
// denominator of the reduced fraction should be
// positive.
//
// 3. If the fraction is negative, the numerator of the
// reduced fraction should be negative, and the
// denominator positive.
//
// 4. If denominator is initially zero, neither numerator
// nor denominator should be changed.
//
//
// Examples. Before After
// n=6, d=9 n=2, d=3
// n=6, d=-9 n=-2, d=3
// n=-7, d=0 n=-7, d=0
//
//////////////////////////////////////////////////////////////////
void ReduceFraction( int& numerator, int& denominator )
{
}
//////////////////////////////////////////////////////////////////
//
// RemovePunctuation replaces the contents of theString with
// the same contents, but with all punctuation removed.
// Punctuation characters are defined to be those characters
// for which the standard library function "ispunct" returns
// true.
//
// Example. Before After
//
// "Don't shoot!" "Dont shoot"
//
//////////////////////////////////////////////////////////////////
void RemovePunctuation( string& theString )
{
}