COSC 1435 Lab 6

Purpose: This lab is to look at how to manipulate numbers, by developing a program that allows the input of two fractions, and then the addition and multiplication of those two fractions.

Due: Beginning of class, March 18, 2013

Requirements: Do the following:

1. This lab focuses on fractions. Write a program that inputs two fractions (a numerator and a denominator for each). The program should work properly for all fractions, except those that have a zero in either denominator. If the user enters 0 in a denominator, give an error message and exit the program. You will then use these two fractions to do the following:

• Add the two fractions together and give the resulting fraction and the decimal equivalent. Remember that you can only add fractions that have the same denominator and for this lab you may just multiple the two denominator together (make sure you appropriately multiply the numerators), to give a common denominator, without worrying about the least common denominator. If the two fractions that were entered were 9/13 and 7/12 the output would be shown as both 199/156 and 1.2756.
• Multiply the two fractions together and give the resulting fraction and the decimal equivalent. If the two fractions that were entered were 2/9 and 6/3 the output would be 12/27 and 0.4444

You program does not need to reduce the result or handle improper fractions (you can do this for bonus points).

Hints:

• Complete pseudocode to develop your design of how to solve this problem, before you start coding. Run several test values through your design to make sure it works properly.
• Use all integer variables for your fractions. You will need integer variables to store the numerator and denominator of each input fraction, the numerator and denominator for the two fractions after the common denominator is found, and for the numerator and denominator for the result of the operations.
• You will need one floating point variable near the end of each process which you use for a floating point divide to find the floating point equivalent of your fraction. If you use floating point variables in the addition and/or multiplication of the fractions, your answers will be wrong.

2. One of the key focuses of this program is on the user interface. Make sure both your input and output are clearly labeled so an untrained user can understand what occurred. As a minimum after the input is complete, your program should show the two fractions being added and multiplied, the resulting fraction (numerator and denominator), and the decimal equivalent. Use the output formatting tools to give consistent output. It is possible to make this output look very nice by using the formatting tools.

For example, this file contains acceptable output, which can be much improved:

3. Make sure your program is properly documented and good programming standards are followed, including properly type casting conversions between variable types.

4. Try your program with a variety of input values, to determine it works properly, including positive and negative numbers in the numerator and denominator. The output you provide should demonstrate your program being run multiple times using all types of inputs.

5. This lab requires a lab report/documentation package. All of these items are not typically in the same file (source code and sample output should definitely be in their own files), but the main lab report file must reference each item by name. Here is a sample lab report. The main lab report must either be a text file (with a .txt extension) or a Microsoft Word file (with a .doc extension). The lab report must includes the following or references (the file name that was attached to the mail) to the following information:

• Purpose of this program.
• Pseudocode (this will probably be in two version, before coding and a revised version after coding/debugging)
• Program source code
• Program output, with sample data
• What problems/successes did you have with this program?
• An estimate of how much time you spent working on this lab

6. Bonus: Include code to handle reducing fractions and improper fractions. The instructor and lab assistants will assist you in these techniques, since the syntax required for these operations has not yet been discussed in class.

Program Submission. You will be submitting this lab via Blackboard. The teaching assistant will provide further instructions on how to accomplish this. Prepare the following:

• Your program source code. This file should be called lab06***.cpp, where the *** is replaced with your initials.
• A copy of your program output saved as a file. This file should be called lab06***.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 lab06***doc.txt for a text file or lab06***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. 20 bonus points for item 6.

• The lab will be graded using this grading criteria. The points will then be scaled to the available points.
• Here is a C++ style guide from Dr. Fernandez that should assist you in coding your program. Style guide.
• 100 points if all of the above requirements are met.