What I'm trying to so is have calc grab the add, mult, sub, div from the fraction.cpp and do that one thing I curious and can't figure out it the how to do the formula in the function and return the value to add the fractions. Can anyone give me an idea or somewhere to begin with that? I know the formulas like for addition its a/b + c/d = (ad + bc) / (b*d) I'm just not sure how to implement this any help is appreciated.
calc.cpp
#include <iostream>
#include "fraction.h"
using namespace std;
int main()
{
fraction f;
char choice;
int numerator;
int denominator;
do
{
cout << "A\tAdd\n";
cout << "S\tSub\n";
cout << "M\tMult\n";
cout << "D\tDiv\n";
cout << "E\tExit\n";
cout << "\nChoice?: ";
cin >> choice;
cin.ignore();
switch (choice)
{
case 'A':
case 'a':
f.read();
break;
case 'S':
case 's':
f.read();
break;
case 'M':
case 'm':
f.read();
break;
case 'D':
case 'd':
f.read();
break;
case 'e':
case 'E':
break;
default :
cerr << "Unrecognized choice: " <<
choice << endl;
break;
}
}
while (choice != 'e' && choice != 'E');
return 0;
}
fraction.cpp
#include <iostream>
#include "fraction.h"
using namespace std;
/*fraction fraction::add(){
}*/
/*fraction fraction::sub(fraction f2){
}*/
/*fraction fraction::mult(fraction f2){
}*/
/*fraction fraction::div(fraction f2){
}*/
void fraction::print()
{
cout << numerator << "/" << denominator << endl;
}
void fraction::read(){
cout << "Please enter a numerator: ";
cin >> numerator;
cout << "Please enter a denominator: ";
cin >> denominator;
}
fraction.h
class fraction{
private:
int denominator;
int numerator;
public:
fraction() : numerator(0), denominator(1) {}
//fraction add();
//fraction sub(int, int, int, int);
//fraction mult(int, int, int, int);
//fraction div(int, int, int, int);
void print();
void read();
};