CSC110 C++ Level 1 Name: ______

Lab 2: Reduce a Fraction with GCF Signature: ______

Due Date: March 22, 2018 (has neither given nor received aid on this program)

Purpose: One purpose of this lab is to continue using the skills learned in class about pseudo code and logic ("the What") and translating it into C++ source code ("the How"). Additionally, the student will learn looping, correct syntax, and debugging techniques discussed in class. In addition the student will read data from a file and output the report to another file. Of course, this program is mathematical in content, and reviews high school Algebra concepts. The Greatest Common Factor is a fundamental concept of mathematics. Passing parameters by reference, by value, and reading from / writing to a disk file is demonstrated, too.

Procedures:

1.  Use the pseudo code given in class to write the source code for the Greatest Common Factor program. Notice this algorithm uses looping. Name this program: GreatestCommonFactor.cpp. A while loop is suggested in the pseudo code.

2.  Use positive numerator and denominator examples to verify the validity of your logic. This algorithm should work correctly under any circumstances with two exceptions: negative components & division by zero. We will exclude these in our testing.

3.  Once you're comfortable doing this process: (translating the logic “what” from pseudo code into “how” in source code and testing): Write the complete pseudo code for “Reducing a Fraction”. Informally, the procedures would be: read the numerator & denominator inputs, echo print these to the console and file, determine the greatest common factor, divide both the numerator and denominator by this greatest common factor, and display the reduced fraction to the console and an output file. Use functions for these small modules.

4.  With your formal pseudo code as a guide, write the source code for reducing a fraction. You should reduce the size of the main by calling four functions from the main (such as readPrintInputs( ), gcf( ), title( ), and printFraction( ). Name this program ReduceAFraction.cpp. Test your ReduceAFraction.cpp source code by using my example 50 / 75 that should reduce to 2 / 3. You should test two other examples as well. Format the fractions neatly and consistently by setting the width of both numerator and denominator to 3 shown as examples on the reverse side.

5.  Use Microsoft Word to define the following 10 programming terms: IDE, syntax error, logic error, two types of looping, algorithm, increment, decrement, accumulator, flowchart, and pseudo code.

6.  Before the due date, email me your final version of: greatestCommonFactor.cpp and ReduceAFraction.cpp source code files and both example outputs of your ReduceAFraction.cpp program to: . Attach both files to your email message. Put CSC110 Lab2 as the subject of the email.

Checklist:

a. Email both .cpp source code files (parag. 6) & 3 output .txt files to me before the due date/time.

b. Sign this specification and staple the following hard copy items below it in this order:

c. Source code for GreatestCommonFactor.cpp and ReduceAFraction.cpp (printed in CodeBlocks)

d. Your test for 50/75 (output .txt) for ReduceAFraction.cpp plus two additional test runs.

e. Pseudo code for ReduceAFraction showing the correct heading and indenting throughout.

f. Write the 10 programming terms with definitions from paragraph 5.

g. Exam Prep. Exercises (p. 233 : 1 through 4) + Exam Prep. Exercises (p. 294-5: 1 through 7)

(Below are 3 example outputs each on separate pages from correctly formatted reduced fractions)

R E D U C I N G A F R A C T I O N

Reading numerator: 50

Reading denominator: 75

The Fraction: 50 / 75

Greatest common factor: 25

Reduces to: 2 / 3

R E D U C I N G A F R A C T I O N

Reading numerator: 157

Reading denominator: 348

The Fraction: 157 / 348

Greatest common factor: 1

Reduces to: 157 / 348

R E D U C I N G A F R A C T I O N

Reading numerator: 320

Reading denominator: 200

The Fraction: 320 / 200

Greatest common factor: 40

Reduces to: 8 / 5