Assignment 3: Functions, due Wednesday, 1/26/00

For this assignment, write the three functions described below. A few notes:
  1. 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.

  2. Your functions are more likely to be correct if they work with a friend's independently written main() as well as your own main(). You should feel free to swap main programs for testing purposes.

  3. Here's how I suggest you organize your code for this assignment.

    This way, you don't have to cut and paste main() from here to there, there's no chance you'll accidentally submit a main() with your code, and it's easy to test your program using someone else's main() simply by compiling like so: g++ -Wall -g -o functions functions.cpp othermain.cpp.

  4. For this assignment, you may work alone or with one other person.

  5. 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 will certainly need 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 );