

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: SI Object-Oriented Programming; Subject: Computer Science; University: Weber State University; Term: Unknown 1989;
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Page 1 of 2
A fraction is composed of two integers: a numerator and a denominator. There are many operations in which fractions can participate; four operations are common: addition, subtraction, multiplication, and division. This is just enough detail (data and functions) to make fractions interesting demonstrations of structures and functions.
int common = gcd(f.numerator, f.denominator); f.numerator /= common; f.denominator /= common;
Page 2 of 2
Strange things happen when you cin a char. The user enters a character and presses the enter key. This places both the entered character AND a new line character in the input stream. The cin reads the input character but leaves the new line. The sequence of operations prescribed here works because a numeric read follows each character read. The numeric read discards the new line while searching for something that can be converted to a number.
A productive way of approaching the assignment is to begin (ASAP) with the chapter 3portion (the loops, branches, input, etc.). In this case it might be useful to explicitly remove the new line character with the ignore function, which may be left in the completed calc function without causing errors. The following three statements accomplish this:
char command; cin >> command; cin.ignore();
Upload three files (fraction.h, fraction.cpp, and calc.cpp) to WSU Online for grading. Please do not zip the files. Please make a sub-directory on WSU Online when uploading these files.