I need to create a Rational header file to produce this output. 1/3 + 7/9 = 10/9
ID: 3613790 • Letter: I
Question
I need to create a Rational header file to produce this output.1/3 + 7/9 = 10/9
10/9 = 1.11111
1/3 - 7/9 = -4/9
-4/9 = -0.444444
1/3 * 7/9 = 7/27
7/27 = 0.259259
1/3 / 7/9 = 3/7
3/7 = 0.428571
1/3 = 3
3 = 3.000000
1/3 ^ 4 = 1/81
1/81 = 0.012346
And below is the main.cpp to do it but I'm not sure exactly how tostart it. I've got the printRational stuff working but not sure howto do anything with the x
#include <iostream>
#include "Rational.h"
using namespace std;
int main()
{
Rational c(1, 3), d(7, 9), x;
c.printRational();
cout << " + ";
d.printRational();
x = c.addition(d);
cout << " = ";
x.printRational();
cout << “ ”;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
c.printRational();
cout << " - ";
d.printRational();
x = c.subtraction(d);
cout << " = ";
x.printRational();
cout << ’ ’;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
c.printRational();
cout << " * ";
d.printRational();
x = c.multiplication(d);
cout << " = ";
x.printRational();
cout << ’ ’;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
c.printRational();
cout << " / ";
d.printRational();
x = c.division(d);
cout << " = ";
x.printRational();
cout << “ ”;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
c.printRational();
x = c.reciprocal();
cout << " = ";
x.printRational();
cout << “ ”;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
c.printRational();
cout << " ^ 4";
x = c.power(4);
cout << " = ";
x.printRational();
cout << ’ ’;
x.printRational();
cout << " = ";
x.printRationalFloat();
cout << " ";
return 0;
} // main
Here is my header file so far.
#include<iostream>
#ifndef _RATIONAL_H_
#define _RATIONAL_H_
class Rational
{
public:
Rational (int num, int den);
Rational ();
void printRational();
private:
int numerator;
int denominator;
int totalNumerator;
int totalDenominator;
};
#endif
Here is my Rational.cpp so far
#include "Rational.h"
#include<iostream>
using namespace std;
Rational::Rational (int num, int den)
{
numerator = num;
denominator = den;
}
Rational::Rational()
{
}
void Rational::printRational()
{
cout << numerator << "/" <<denominator;
}
Explanation / Answer
x.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.