/* Matthew Giampiccolo & Jason M. Snouffer Computer Science & Programming Wednesday, October 30, 2002 Lab 9 Problem 1 This program takes a numerator and denominator from the user, ensures that the denominator is nonzero; then displays the fraction and its simplest form. Test Suite: Input: 2/4 Output: The fraction is 2/4 The fraction is 1/2 Input: 3/9 Output: The fraction is 3/9 The fraction is 1/3 Input: 5/6 Output: The fraction is 5/6 The fraction is 5/6 Input: 14/16 Output: The fraction is 14/16 The fraction is 7/8 Input: 90/99 Output: The fraction is 90/99 The fraction is 10/11 Input: 10/10 Output: The fraction is 10/10 The fraction is 1/1 Input: 88/100 Output: The fraction is 88/100 The fraction is 22/25 Input: 4/10 Output: The fraction is 4/10 The fraction is 2/5 Input: 16/30 Output: The fraction is 16/30 The fraction is 8/15 All of the sample inputs within this test suite were tested and performed as expected. */ #include #include using namespace std; /* The function reads from the user the numerator and denominator of a fraction, insisting that the denominator not be 0. preconditions: none postconditions: recieves two integers from user, ensures that the second int is nonzero, and modifies arguments that are referenced by the function's 2 pass-by-reference varaiables. */ void get_fraction (int & numerator, int & denominator); /* The function displays the numerator and denominator of a fraction, with a '/' in between them. preconditions: denominator must be nonzero postconditions: prints value of first argument, a slash, and the value of the second argument. */ void display_fraction (int numerator, int denominator); /* The function simplifies the input fraction and returns to its caller with the corresponding values of numerator and denominator. preconditions: denominator must be nonzero postconditions: modifies pass-by-reference variables */ void simplify_fraction (int & numerator, int & denominator); int main () { int numerator, denominator; get_fraction(numerator, denominator); display_fraction (numerator, denominator); simplify_fraction (numerator, denominator); display_fraction (numerator, denominator); return EXIT_SUCCESS; } /* The function reads from the user the numerator and denominator of a fraction, insisting that the denominator not be 0. preconditions: none postconditions: recieves two integers from user, ensures that the second int is nonzero, and modifies arguments that are referenced by the function's 2 pass-by-reference varaiables. */ void get_fraction (int & numerator, int & denominator) { cout<<"Please enter a numerator: "; cin>>numerator; do { cout<<"Please enter a nonzero denominator: "; cin>>denominator; } while(denominator == 0); } /* The function displays the numerator and denominator of a fraction, with a '/' in between them. preconditions: denominator must be nonzero postconditions: prints value of first argument, a slash, and the value of the second argument. */ void display_fraction (int numerator, int denominator) { cout<<"The fraction is: " <