Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a c++ program Write a driver program // Fraction.h #ifndef FRACTION_H #define FRACTION_H class Fraction { private: int num; int den; int static gcd(int,
Write a c++ program
Write a driver program
// Fraction.h
#ifndef FRACTION_H
#define FRACTION_H
class Fraction
{
private:
int num;
int den;
int static gcd(int, int);
public:
Fraction();
Fraction(int, int);
Fraction(const Fraction &f);
friend std::ostream& operator
friend std::istream& operator>>(std::istream& din, Fraction&);
Fraction& operator=(const Fraction & src);
};
#endif
// Fracion.cpp
#include
using namespace std;
#include "Fraction.h"
//Constructor definitions
Fraction::Fraction()
{
this->num = 0;
this->den = 1;
}
Fraction::Fraction(int n, int d)
{
this->num = n;
this->den = d;
}
Fraction::Fraction(const Fraction &f)
{
num = f.num;
den = f.den; }
// Function implementation which display Fraction numbers by using the
operator overloading '
ostream& operator
{
dout
Define a class for fractions, name it Fraction. A fraction is composed of numerator and denominator. In addition to the member functions that set and get the member attributes (numerator and denominator), define following member functions: l. Constructors a. A constructor uses default parameters. b. Copy constructor 2. Mutators: setNumeratorO, setDenominatorO 3. Assessors: getNumeratorO, getDenominatorO 4 Overload output operators () for Fraction class 5. Overload input operator ) for Fraction class 6. Overload assignment operator for Fraction class 7. Overload arithmetic operators+ and / 8. Overload comparison operators-,-, >, and >, , and , return dout;
}
// Function implementation which read Fraction numbers by using the
operator overloading '>>'
istream& operator>>(istream& din, Fraction& c)
{
cout
din >> c.num;
cout
din >> c.den;
return din; }
Fraction & Fraction::operator=(const Fraction & src)
{
num = src.num;
den = src.den;
return *this;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started