Question: Make a Fraction class with two int members (numerator and denominator). Create the following member functions: Create an Input function to allow the user to

Make a Fraction class with two int members (numerator and denominator). Create the following member functions:

  • Create an Input function to allow the user to enter the numerator and denominator. Make sure to have exception or if condition to deal with a denominator of 0 (zero).
  • Create a Print function which will print out the Fraction in the form numerator/denominator i.e. 2/3
  • Empty constructor which initializes the Fraction zero
  • A one-parameter constructor for just a numerator (int). This would make the Fraction represent a whole number.
  • A one-parameter constructor with a double. This would make a Fraction by multiplying the double by 100000, then creating a numerator and denominator as the result. For example; PI, 3.14159, would be saved in a Fraction object as 314159/100000
  • A two-parameter constructor with both numerator (int) and denominator (int). This would make a Fraction with both a numerator and denominator
  • Add function taking a Fraction as a parameter and returning a Fraction
  • Subtract function taking a Fraction as a parameter and returning a Fraction
  • Multiply function taking a Fraction as a parameter and returning a Fraction
  • Divide function taking a Fraction as a parameter and returning a Fraction
  • Add function taking two Fractions as parameters and updating the current object
  • Subtract function taking two Fractions as parameters and updating the current object
  • Multiply function taking two Fractions as parameters and updating the current object
  • Divide function taking two Fractions as parameters and updating the current object

Make sure to use exception handling in the event there is ever a divide by zero or any other error condition that would cause the program to terminate unexpectedly.

part 2:

Expand on Assignment #2 using Fractions and write functions for all the math operators available and properly overloading them. Write operator overloaded functions for the following operators:

These binary functions return Fraction objects:

+= -= *= /= + - / * =

These unary functions return Fraction objects:

- ~ ++ -- (both prefix & postfix)

These extraction/insertion functions for printing and inputting Fraction objects:

>

Theses return boolean True / False: These casting functions:

= == != ! ( double ) ( float )

Examples: Fraction a, b, c ;

a = b + c ; a = b - c ; a += b ; a -= b ;

a = b * c ; a = b / c ; a *= b ; a /= b ;

if ( a == b ) if ( a != b ) int x = !a ; // 0 or 1

if ( a b ) float f = (float) a ;

if ( a

In the ++ and --, these function increment or decrement by 1/1.

So if b is 6/5, then at the end of each line a and b are:

a = ++b ; // a is 11/5 b is 11/5

a = b++ ; // a is 6/5 b is 11/5

a = --b ; // a is 1/5 b is 1/5

a = b-- ; // a is 6/5 b is 1/5

When a = 2/5, for - b = -a // a is 2/5 and b is 2/5

When a = 2/5, for ~ b = ~a // a is 2/5 and b is 5/2

Printing and Inputting

cout > b;

Create a private LowTerm/Reduce() function within the class which reduces the Fraction to lowest terms. For example, Fractions like these would become these

2/4 -> 1/2

5/8 -> 5/8

76/32 -> 19/8

17/17 -> 1/1

24/12 -> 2/1

45/65 -> 9/13 Make a Fraction class with two int members (numerator and denominator). Create

the following member functions: Create an Input function to allow the user

#include using namespace std;

//creating class to store information of fractions class Fraction { private: long int numerator; long int denominator; void Reduce(void); // to get the lowest term public: void input(void); void print(void)const;

//default constructor //set numerator to 0, and denominator to 1 explicit Fraction(); //constructor for numerator int to make a fraction whole number explicit Fraction(long n, long d); //constructor with double explicit Fraction(double); //setters method void setNumerator(int); void setDenominator(int); //getter method long getNumerator(void)const; long getDenominator(void)const;

//constructor with two parameter for both int numerator and denominator Fraction(const Fraction& obj_f);

//overloading math binary operators Fraction operator +(const Fraction& obj_f)const;// overloading the operator + Fraction operator -(const Fraction& obj_f)const;//overloading the operator - Fraction operator * (const Fraction& obj_f)const;//overlaoding the operator * Fraction operator /(const Fraction& obj_f)const;//overloading the opertaor /

Fraction operator +=(const Fraction& obj_f ); Fraction operator -=(const Fraction& obj_f); Fraction operator *=(const Fraction& obj_f); Fraction operator /=(const Fraction& obj_f);

//unary functions //increment and decrement oeprators Fraction operator++(void ); Fraction operator ++(int); Fraction operator --(void); Fraction operator --(int); Fraction operator ~(void)const; Fraction operator -(void)const;

//extraction and insertion operation friend ostream& operator>(istream& din, const Fraction&);

//bool operator for comparison bool operator== (const Fraction& )const; bool operator !=(const Fraction&)const; bool operator (const Fraction&)const; bool operator =(const Fraction&)const;

my question:

1)I want in help c++. part 2 please

2)please complete it further i need help urgently

Another output sample 23 AUsers Whiyam\Desktop\CPS171Winter21\cp=271 Testing Programs\Debug cps271 TestingPrograms.exe You will be asked to enter 2 fractions and 1 mathematical operator. Enter Numerator: 6 Enter Denominator: 8 Enter Numerator: 3 Enter Denominator: 7 Please enter mathematical operator (+,-,',I, -, --, -, -, -, ++, --) to peform operation on your fractions, OR Enter comparison operator to compare your 2 fractions (, -, -, !-) Enter q orl to quit: The solution is: 7/4 Enter Numerator: 2 Enter Denominator: 7 Enter Numerator: 4 Enter Denominator: 5 Please enter mathematical operator (+,-, I, -, -, -, -, -, ++,-) to peform operation on your fractions, OR Enter comparison operator to compare your 2 fractions (, -, -, I-) Enter q or to quit: Would you like to decrement fraction 1 or fraction 2? The solution is: -5/7 Enter Numerator: 1 Enter Denominator: 7 Enter Numerator: 3 Enter Denominator: 8 Please enter mathematical operator (+, ... /. +, --, -, , -, ++, --) to peform operation on your fractions, OR Enter comparison operator to compare your 2 fractions (, 1/7 is not greater than or equal to 3/8 Enter Numerator: 8 Enter Denominator: 9 Enter Numerator: 7 Enter Denominator: 3 Please enter mathematical operator (+. , , -, -, -, -, ++, .-) to peform operation on your fractions, OR Enter comparison operator to compare your 2 fractions (, b) Flag: (a = b) = 0 Flag: (a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!