Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Building a class for Fraction ADT (20 points. submit your two source files named Frac.cpp and Frac.h online only before the due time next week)

Building a class for Fraction ADT (20 points. submit your two source files named Frac.cpp and Frac.h online only before the due time next week)

Create a class called Fraction for performing arithmetic with fractions. Use integer variables to represent the private data of the classthe numerator and the denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions for each of the following: a) Addition of two Fraction numbers. See the solution as an example below. b) Subtraction of two Fraction numbers. c) Multiplication of two Fraction numbers. d) Division of two Fraction numbers. e) Printing Fraction numbers in the form a/b where a is the numerator and b is the denominator. f) Printing Fraction numbers in double floating-point format.

Note: 1. You just need to finish the skeleton codes in two files: the interface Frac.h and the implementation file Frac.cpp. 2. A driver program (do not change it!) to test your class: LabProj4Driver.cpp. 3. For submission, you need to upload the two source files: your Frac.h and Frac.cpp to Canvas (please DO NOT zip them).

Driver program

#include "Frac.h" #include using namespace std; int main() { Fraction x(-3,8), y(-15,-20), z, w(5); x.printFraction(); cout << " + "; y.printFraction(); z = x.add(y); cout << " = "; z.printFraction(); cout << endl; z.printFraction(); cout << " = "; z.printFractionAsFloat(); cout << endl << endl; x.printFraction(); cout << " - "; y.printFraction(); z = x.subtract(y); cout << " = "; z.printFraction(); cout << endl; z.printFraction(); cout << " = "; z.printFractionAsFloat(); cout << endl << endl; x.printFraction(); cout << " * "; y.printFraction(); z = x.multiply(y); cout << " = "; z.printFraction(); cout << endl; z.printFraction(); cout << " = "; z.printFractionAsFloat(); cout << endl << endl; x.printFraction(); cout << " / "; y.printFraction(); z = x.divide(y); cout << " = "; z.printFraction(); cout << endl; z.printFraction(); cout << " = "; z.printFractionAsFloat(); cout << endl; #ifdef _WIN32 // _WIN32 is used by Visual C++ #if (_MSC_VER <= 1916) // check if it Visual Studio 2017 or earlier system("pause"); #endif #endif return 0; } /*Sample run: -3/8 + 3/4 = 3/8 3/8 = 0.375 -3/8 - 3/4 = -9/8 -9/8 = -1.125 -3/8 * 3/4 = -9/32 -9/32 = -0.28125 -3/8 / 3/4 = -1/2 -1/2 = -0.5 Press any key to continue . . . */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago