COSC 1435 Lab 10

Purpose: To practice writing functions

Due: Before class April 15, 2013

Requirements: This lab is designed to introduce functions. We will be building on what you accomplished in lab 6, by adding the capability to reduce fractions and turning improper fractions to proper fractions. Additionally, if you received a grade less than you wanted for lab 6, this is your opportunity to resubmit lab 6. We will be using Euclids algorithm to do. Do the following:

1. Review your lab 6 program and verify that it works properly. Add validation using a while loop to your program to verify that 0 is not allowed in the denominator of either fraction. Add a do-while loop to your lab 6 to allow the user to add and multiply multiple fractions. Verify that your program works properly, before continuing on with the next step. Ask for help, if it does not.

2. We will be using Euclid's Algorithm to reduce our functions. Here is a complete test program that uses Euclid's Algorithm. This function uses recursion to accomplish the task. Recursion means that the program calls itself. For those going on in computer science, you will learn more about recursion in COSC 1436.

3. Add euclid function to your lab 6 program. Remember you will need include both the function definition and the function prototype. Recompile your program to verify it works properly. Now add code into your program that uses the euclid function to reduce all the fractions. Send the numerator and the denominator of a fraction to the euclid function and it will return the greatest common factor. If you then divide both the numerator and denominator by this common factor, your fraction will be reduced. If the fraction cannot be reduced, it will be unchanged.

4. Next add code that will handle improper fractions. We will develop the pseudocode to do this in the lab.

5. Prepare a lab report/documentation package. All of these items do not need to be in the same file or word document, but the main lab report file must reference each item by name. The lab report must includes the following information:

Program Submission. You will be submitting this lab via Blackboard. Prepare the following:

  • Your program source code. This file should be called lab10***.cpp, where the *** is replaced with your initials.
  • A copy of your program output saved as a file. This file should be called lab10***.txt, where the *** is replaced with your initials. The .txt signifies that this is an ASCII text file.
  • A lab report as described above. The lab report may be in a Microsoft Word document, with a .doc suffix or an ASCII text file with a .txt suffix. Make sure it contains all of the required items. This file should be called either lab10***doc.txt for a text file or lab10***doc.doc for a Microsoft Word file, where the *** is replaced with your initials.

Submit via blackboard following the instructions given during the lab.

Grading Criteria: 100 points available for this lab.