Assignment 3: Functions, due Wednesday, 10/4/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.


//////////////////////////////////////////////////////////////////
//
//	IsPalindrome returns true if the given string s
//	is a strict, case-insensitive palindrome, and false
//	otherwise.
//
//	By strict palindrome, I mean a string that reads the
//	same backwards as forwards, without adjusting 
//	spacing, punctuation, etc.  A case-insensitive
//	palindrome means that, for example, an upper-case
//	'R' is to be considered the same as a lower-case 'r'.
//
//	Examples:
//
//		level							true
//		Level							true
//		madam, I'm Adam					false
//		rats live on no evil star		true
//
//////////////////////////////////////////////////////////////////

bool IsPalindrome( const string& s );


//////////////////////////////////////////////////////////////////
//
//	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 );


//////////////////////////////////////////////////////////////////
//
//	MakeUpper changes all the letters in the given string s
//	to upper-case.  All other characters in s are unchanged.
//
//	Don't forget the library functions isalpha and toupper.
//
//////////////////////////////////////////////////////////////////

void MakeUpper( string& s );