

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
Programming assignment #8 for cs 1410, which involves converting member functions in a fraction class into overloaded operators. The assignment covers converting arithmetic functions into operators, creating operator<< and operator>> functions, and using conversion constructors. Students are required to modify their calc program to utilize the overloaded operators and submit three files: fraction.h, fraction.cpp, and calc.cpp.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Page 1 of 2
Convert the member functions in your fraction class (lab #5) into overloaded operators as described below. Modify your calc program to utilize the overloaded operators.
fraction(int n) : numerator(n), denominator(1) {}
is a conversion constructor that converts the integer n into the fraction n/1. By using default parameters, it is often possible to make one constructor serve both as a “normal” constructor and as a conversion constructor. You created a conversion constructor in Lab #4:
fraction(int n, int d = 1)...
Page 2 of 2
fraction f3 = f1 + f2; cout << f3 << " = " << f1 << " + " << f2 << endl;
fraction f7 = f2 + 2; cout << f7 << " = " << f2 << " + " << 2 << endl;
The second addition operation (f2 + 2) automatically calls the conversion constructor to convert the 2 into a fraction, which can then be added to the original fraction object.
fraction f8 = 2 + f2; cout << f8 << " = " << 2 << " + " << f2 << endl;
The same conversion takes place with the expression 2 + f2.
Upload three files to WSU Online: fraction.h , fraction.cpp , and calc.cpp (Note that you must make a new directory to avoid overwriting existing files – instructions are provided on the class web site above the lab assignments). Please do not zip the files.