Question
(C++) Consider the following class definition: class Fraction { private: int numerator; int denominator; public: Fraction(int n = 0, int d = 1) {numerator =
(C++) Consider the following class definition:
class Fraction { private: int numerator; int denominator;
public: Fraction(int n = 0, int d = 1) {numerator = n; denominator = d;} };
and the following main function:
int main() { Fraction X, Y, Z;
cout << "Enter two fractions (in the form numerator/denominator): "; cin >> X; cin >> Y;
Z = X + Y; cout << X << " + " << Y << " = " << Z << endl; Z = X - Y; cout << X << " - " << Y << " = " << Z << endl; Z = X * Y; cout << X << " * " << Y << " = " << Z << endl; Z = X / Y; cout << X << " / " << Y << " = " << Z << endl;
cout << X << " as a double is " << (double)X << endl;
system("pause"); return 0; }
Write the code that would be necessary to get this program to compile and work correctly (i.e. you should overload the appropriate operators for the Fraction class). For full credit, resulting fractions should also be reduced.
Requirements:
You must write separate .h files for each class.
You should also use good commenting and code style. Expect points to be deducted from your score if you do not comment your code and use good coding practices.
You may not use global variables or GOTO statements.
You may work with one other person on this assignment. If you choose to work with a partner, you must do the following: 1) Comment all code with the name(s) of the programmer(s) primarily responsible for the code. If you worked on the portion collaboratively, then state that. 2) In the comments of the file that contains your main function, clearly indicate both of your names as the authors of the project.
What to hand in:
You should upload a single .zip file that contains the entire Visual Studio project you created (all .cpp, .h, .sln, and .exe files should be included). Expect significant points to be deducted from your submission if this is not done correctly. If you worked with a partner both of you should submit identical copies of the project.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started