Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: Consider the following class definition: class Fraction { private: int numerator; int denominator; public: Fraction(int n = 0, int d = 1) {numerator =

Description:

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.

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

=+Are the contracts enforceable?

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago