Question
C++ Exercise :- Read the documentation of the header file carefully. Four of the function implementations have documentation and the others do not. Explain how
C++
Exercise :- Read the documentation of the header file carefully. Four of the function
implementations have documentation and the others do not. Explain how these four
are different.
Exercise :- Fill in the missing code in the implementation file, and compile
fraction.cpp. Were there many bugs in your file? Describe any problems that you
had.
Exercise :- Write a driver that uses class Fraction to do the following calculations:
1/2 + 1/4
1/2 1/4
1/2 * 1/2
1/2 / 1/2
Write the output clearly labeled.
// Header file fraction.h declares class Fraction.
class Fraction
// Class Fraction represents the numerator and
// denominator of a fraction.
{
public:
// Constructors
Fraction();
// Post: Numerator and denominator have been set to zero
Fraction(initNumerator, initDenominator);
// Post: Numerator has been set to initNumerator;
// denominator has been set to initDenominator.
Fraction Add(Fraction frac1) const;
// Post: self + frac1 is returned.
Fraction Subtract(Fraction frac1) const;
// Post: self - frac1 is returned.
Fraction Multply(Fraction frac1) const;
// Post: self * frac1 is returned.
Fraction Divide(Fraction frac1) const;
// Post: self / frac1 is returned.
int GetNumerator() const;
// Post: Numerator of frac1 is returned.
int GetDenominator() const;
// Post: Denominator of frac1 is returned.
private:
int numerator;
int denominator;
};
____________________________________________________________
//*******************************************************
// Implementation file fraction.cpp implements the member
// functions of class Fraction.
#include "fraction.h"
Fraction::Fraction()
{
// FILL IN Code for default constructor.
}
Fraction::Fraction(initNumerator, initDenominator)
{
// FILL IN Code for default constructor.
}
Fraction Fraction::Add(Fraction frac1) const
// Pre: frac1 and self have been initialized.
// Post: frac1 + self is returned in reduced form.
{
// FILL IN Code.
}
Fraction Fraction::Subtract(Fraction frac1) const
// Pre: frac1 and self have been initialized.
// Post: self - frac1 is returned in reduced form.are
{
// FILL IN Code.
}
Fraction Fraction::Multiply(Fraction frac1) const
// Pre: frac1 and self have been initialized.
// Post: self - frac1 is returned in reduced form.are
{
// FILL IN Code.
}
Fraction Fraction::Divide(Fraction frac1) const
// Pre: frac1 and self have been initialized.
// Post: self - frac1 is returned in reduced form.are
{
// FILL IN Code.
}
int Fraction::GetNumerator() const
{
// FILL IN Code.
}
int Fraction::GetDenominator() const
{
// FILL IN Code.
}
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