REQUIREMENTS: Problem Description: Implement an immutable Fraction Class described in the readings. Then add the following methods to emulate arithmetic operations and I/O operations on Fractions. Arithmetic operators: + - * / Relational operators: < <= > >= Equality operators: == != Stream Extraction: >> (i.e. 3/7 form) Stream Insertion: << (i.e. 3/7 form) Method to reduce fraction Assignment Operator = that evaluates right to left only Demonstrate all capabilities (methods) implemented. Implement a test program to demonstrate your class methods.
Fraction.h
#ifndef FRACTION_H
#define FRACTION_H
class Fraction
{
public:
Fraction();
Fraction(int numer, int denom);
// Setter and getter methods
void setNumerator(int);
void setDenominator(int);
int getNumerator() const;
int getDenominator() const;
Fraction operator+(const Fraction& f) const; //
operator+()
Fraction operator-(const Fraction& f) const; //
operator-()
Fraction operator*(const Fraction& f) const; //
operator*()
Fraction operator/(const Fraction& f) const; // operator*()
bool operator!=(const Fraction& f) const; //
operator!=()
bool operator==(const Fraction& f) const; // operator==()
bool operator<=(const Fraction& f) const; //
operator<=()
bool operator>=(const Fraction& f) const; //
operator>=()
bool operator<(const Fraction& f) const; //
operator<()
bool operator>(const Fraction& f) const; //
operator>()
/**
* Friend function declarations
* Output fraction number to an output stream, Example 3+4i
*/
friend std::ostream& operator<<(std::ostream& dout,
const Fraction&);
/**
* read fraction number to an input stream
*/
friend std::istream& operator>>(std::istream& din,
Fraction&);
private:
int numer;
int denom;
};
#endif
_________________
Fraction.cpp
#include <iostream>
using namespace std;
#include "Fraction.h"
Fraction::Fraction()
{
this->numer = 0;
this->denom = 1;
}
Fraction::Fraction(int num, int den)
{
numer = num;
denom = den;
}
// Setters and getters
void Fraction::setNumerator(int n)
{
this->numer = n;
}
void Fraction::setDenominator(int n)
{
this->denom = n;
}
int Fraction::getNumerator() const
{
return numer;
}
int Fraction::getDenominator() const
{
return denom;
}
Fraction Fraction::operator+(const Fraction& f) const
{
Fraction frac;
int a = numer;
int b = denom;
int c = f.numer;
int d = f.denom;
int sumnumer = (a * d + b * c);
int denom = (b * d);
frac.setNumerator(sumnumer);
frac.setDenominator(denom);
return frac;
}
Fraction Fraction::operator-(const Fraction& f) const
{
Fraction frac;
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
int subnumer = (a * d - b * c);
int denom = (b * d);
frac.setNumerator(subnumer);
frac.setDenominator(denom);
return frac;
}
Fraction Fraction::operator*(const Fraction& f) const
{
Fraction frac;
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
int mulnumer = (a * c);
int muldenom = (b * d);
frac.setNumerator(mulnumer);
frac.setDenominator(muldenom);
return frac;
}
Fraction Fraction::operator/(const Fraction& f) const
{
Fraction frac;
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
int divnumer = (a * d);
int divdenom = (c * b);
frac.setNumerator(divnumer);
frac.setDenominator(divdenom);
return frac;
}
/*
void Fraction::print()const
{
cout<<getNumerator()<<"/"<<getDenominator();
}
*/
bool Fraction::operator<=(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
// cout<<f1<<" "<<f2<<endl;
if ((n1 / d1) <= (n2 / d2))
return true;
else
return false;
}
bool Fraction::operator>=(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
// cout<<f1<<" "<<f2<<endl;
if ((n1 / d1) >= (n2 / d2))
return true;
else
return false;
}
bool Fraction::operator<(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
// cout<<f1<<" "<<f2<<endl;
if ((n1 / d1) < (n2 / d2))
return true;
else
return false;
}
bool Fraction::operator>(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
if ((n1 / d1) > (n2 / d2))
return true;
else
return false;
}
// Function implementation which display Fraction numbers by
using the operator overloading '<<'
ostream& operator<<(ostream& dout, const
Fraction& c)
{
dout << c.numer << "/" << c.denom;
return dout;
}
// Function implementation which read Fraction numbers by using
the operator overloading '>>'
istream& operator>>(istream& din, Fraction&
c)
{
char ch;
din >> c.numer;
din >> ch;
din >> c.denom;
return din;
}
bool Fraction::operator!=(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
// cout<<f1<<" "<<f2<<endl;
if ((n1 != n2) || (d1 != d2))
return true;
else
return false;
}
bool Fraction::operator==(const Fraction& f) const
{
int a = this->numer;
int b = this->denom;
int c = f.numer;
int d = f.denom;
double n1 = a * d;
double d1 = b * d;
double n2 = c * b;
double d2 = d * b;
// cout<<f1<<" "<<f2<<endl;
if ((n1 == n2) && (d1 == d2))
return true;
else
return false;
}
_______________________
Main.cpp
#include <iostream>
using namespace std;
#include "Fraction.h"
int main()
{
Fraction f1, f2, result;
// int tmpN, tmpD;
// char divideSign;
// Fraction 1
cout << "Enter fraction 1:
<numerator>/<denominator>" << endl;
cin >> f1;
// cin >> tmpN >> divideSign >> tmpD;
// f1.setNumerator( tmpN );
// f1.setDenominator( tmpD );
// Fraction 2
cout << "Enter fraction 2:
<numerator>/<denominator>" << endl;
// cin >> tmpN >> divideSign >> tmpD;
// f2.setNumerator( tmpN );
// f2.setDenominator( tmpD );
cin >> f2;
result = f1 + f2;
cout << f1;
cout << "+";
cout << f2;
cout << "=";
cout << result;
cout << endl;
result = f1 - f2;
cout << f1;
cout << "-";
cout << f2;
cout << "=";
cout << result;
cout << endl;
result = f1 * f2;
cout << f1;
cout << "*";
cout << f2;
cout << "=";
cout << result;
cout << endl;
result = f1 / f2;
cout << f1;
cout << "/";
cout << f2;
cout << "=";
cout << result;
cout << endl;
bool boolean = f1 < f2;
if (boolean)
cout << f1 << " is less than " << f2 <<
endl;
else
cout << f1 << " is not less than " << f2 <<
endl;
boolean = f1 > f2;
if (boolean)
cout << f1 << " is greater than " << f2 <<
endl;
else
cout << f1 << " is not greater than " << f2
<< endl;
boolean = f1 <= f2;
if (boolean)
cout << f1 << " is less than or equal to " << f2
<< endl;
else
cout << f1 << " is not less than or equal to " <<
f2 << endl;
boolean = f1 >= f2;
if (boolean)
cout << f1 << " is greater than or equal to " <<
f2 << endl;
else
cout << f1 << " is not greater than or equal to "
<< f2 << endl;
boolean = f1 == f2;
if (boolean)
cout << f1 << " is equal to " << f2 <<
endl;
else
cout << f1 << " is not equal to " << f2 <<
endl;
boolean = f1 != f2;
if (boolean)
cout << f1 << " is not equal to " << f2 <<
endl;
else
cout << f1 << " is equal to " << f2 <<
endl;
}
_____________________
Output:

REQUIREMENTS: Problem Description: Implement an immutable Fraction Class described in the readings. Then add the following...
C++ Question
Your class should support the following operations on Fraction objects: • Construction of a Fraction from two, one, or zero integer arguments. If two arguments, they are assumed to be the numerator and denominator, just one is assumed to be a whole number, and zero arguments creates a zero Fraction. Use default parameters so that you only need a single function to implement all three of these constructors. You should check to make sure that the denominator is...
NEED ASAP PLEASE HELP
Task:
---------------------------------------------------------------------------------------------------------------------------------
Tasks to complete:
----------------------------------------------------------------------------------------------------------------------------------------
given code:
-----------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include <iostream>
#include <iomanip>
#include "fractionType.h"
using namespace std;
int main()
{
fractionType num1(5, 6);
fractionType num2;
fractionType num3;
cout << fixed;
cout << showpoint;
cout << setprecision(2);
cout << "Num1 = " << num1 << endl;
cout << "Num2 = " << num2 << endl;
cout << "Enter the fraction in the form a / b: ";
cin >> num2;
cout << endl;
cout <<...
c++ program Implement a class called Person with the following members: 1a. ????, a private variable of type ?????? 1b. ???, a private variable of type ??? 1c. Default constructor to set name to "" and age to 0 1d. Non-default constructor which accepts two parameters for name and age 1e. A copy constructor 1f. The post-increment operator 1g. The pre-decrement operator 1h. The insertion and extraction stream operators >>and <<
You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and functions. a. Add four arithmetic operators, +, -, *, and /. Remember that to add or subtract two Fractions, you first must convert them to Fractions with a common denominator. You multiply two Fractions by multiplying the numerators and multiplying the denominators. You divide two Fractions by inverting the second Fraction, then multiplying. After any arithmetic operation, be sure the Fraction is in proper...
This in in C# There are two classes, class Fraction and class FractionDemo The user needs to be able to input a value for the numerator and the denominator Create a Fraction class with private fields that hold a positive int numerator and a positive int denominator. In addition, create Properties for each field with the set mutator such that the numerator is greater than or equal to 0 and the denominator is greater than 0 (illegal values should be...
c++
format
Goals . Understand how to implement operator overloading in C++ Warning: Programs must compile using gt+ on the Computer Science Linux systems. If your code does not compile on CS machines you will get 0 for the assignment. Organize your files into folders by lab assignment. For this assignment, create a folder called Lab9. A. Read Chapter 18 B. Create a new class called RationalNumber to represent fractions. The class should have the following capabilities: 1) It should...
You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and functions. a. Add four arithmetic operators, +, -, *, and /. Remember that to add or subtract two Fractions, you first must convert them to Fractions with a common denominator. You multiply two Fractions by multiplying the numerators and multiplying the denominators. You divide two Fractions by inverting the second Fraction, then multiplying. After any arithmetic operation, be sure the Fraction is in proper...
Assignment4: Evaluate Arithmetic Expressions. Requirements: Implement a concrete ArrayStack class that extends the IStack interface as we discussed in the class (any other different Stack class implementation, even if it is implemented by yourself, will not receive any credit). Write a test class called Evaluate and a method that evaluates an arithmatic expression, which is given by a string. import java.util.Scanner; public class Evaluate { public static void main(String[] args) } // your implementation // obtain user's input from keyboard...
Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...
java only no c++ Write a Fraction class whose objects will represent fractions. You should provide the following class methods: Two constructors, a parameter-less constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Arithmetic operations that add, subtract, multiply, and divide Fractions. These should be implemented as value returning methods...