Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago