troubleshooting Question

I am having trouble overloading my functions and implementating them into my main menu.

I need to write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, where a and b are integers and b is not equal to 0. Your program must be menu driven, allowing the user to select the operation (+, -, *, /) and input the numerator and denominator of each fraction. Your program must consist of at least the following functions:

a. Function menu: This function informs the user about the program's purpose, explains how to enter data, and allows the user to select the operation. (5 points)

b. Function addFractions: This function adds two fractions together (or you can overload the +operator()). (5 points)

c. Function subtractFractions: This function subtracts one fraction from another (or you can overload the -operator()). (5 points)

d. Function multiplyFractions: This function multiplies two fractions together (or you can overload the *operator()). (5 points)

e. Function divideFractions: This function divides one fraction into another (or you can overload the /operator()). (5 points)

Some sample outputs are:

3 / 4 + 2 / 5 = 23 / 20

2 / 3 * 3 / 5 = 6 / 15

Your answers need not be in the lowest terms.

Be sure that your program handles exceptions such as division by zeroand non-integer values . Allow the user to immediately re-enter any values which have thrown an exception Allow the user to continue to use the program until they quit via a menu option.

Here is my program:

I need to write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, where a and b are integers and b is not equal to 0. Your program must be menu driven, allowing the user to select the operation (+, -, *, /) and input the numerator and denominator of each fraction. Your program must consist of at least the following functions:

a. Function menu: This function informs the user about the program's purpose, explains how to enter data, and allows the user to select the operation. (5 points)

b. Function addFractions: This function adds two fractions together (or you can overload the +operator()). (5 points)

c. Function subtractFractions: This function subtracts one fraction from another (or you can overload the -operator()). (5 points)

d. Function multiplyFractions: This function multiplies two fractions together (or you can overload the *operator()). (5 points)

e. Function divideFractions: This function divides one fraction into another (or you can overload the /operator()). (5 points)

Some sample outputs are:

3 / 4 + 2 / 5 = 23 / 20

2 / 3 * 3 / 5 = 6 / 15

Your answers need not be in the lowest terms.

Be sure that your program handles exceptions such as division by zeroand non-integer values . Allow the user to immediately re-enter any values which have thrown an exception Allow the user to continue to use the program until they quit via a menu option.

Here is my program:

```
#ifndef FRACTION_H
#define FRACTION_H
#include <iostream>
#include <cmath>
using namespace std;
class Fraction {
public:
Fraction();
Fraction(int);
Fraction(int, int);
void Read();
void Write() const;
Fraction Add(Fraction) const;
Fraction Subtract(Fraction) const;
Fraction Multiply(Fraction) const;
Fraction Divide(Fraction) const;
private:
int num;
int denom;
Fraction::Fraction()
{
num = 0;
denom = 1;
}
Fraction::Fraction(int n) {
num = n;
denom = 1;
}
Fraction::Fraction(int n, int d) {
num = n;
denom = d;
}
void Fraction::Read() {
char slash;
cout << "Enter fraction(numerator / denominator): ";
cin >> num >> slash >> denom;
while(slash != '/') {
cout << "\nERROR! Work with fractions and use numerator / denominator! REENTER!\n";
cin >> num >> slash >> denom;
}
}
void Fraction::Write() const{
cout << num << " / " << denom ;
}
Fraction Fraction::Add(Fraction someFraction) const {
Fraction result;
result.num = num * someFraction.denom + denom * someFraction.num;
result.denom = denom * someFraction.denom;
return result;
}
Fraction Fraction::Multiply(Fraction someFraction) const {
Fraction result;
result.num = num * someFraction.num;
result.denom = denom * someFraction.denom;
return result;
}
Fraction Fraction::Subtract(Fraction someFraction) const {
Fraction result;
result.num = num * someFraction.denom - denom * someFraction.num;
result.denom = denom * someFraction.denom;
return result;
}
Fraction Fraction::Divide(Fraction someFraction) const {
Fraction result;
result.num = num * someFraction.denom;
result.denom = denom * someFraction.num;
return result;
};
}
#endif
main
#include <iostream>
#include <cmath>
#include <iomanip>
#include "Fraction.h"
using namespace std;
int main()
{
int n1=0;
int d1=0;
int n2=0;
int d2=0;
int na=0;
int da=0;
int num;
cout<<"This program performs operations on fractions"<<endl;
menu(num,n1,n2,d1,d2);
while(num !=9)
{
if (num = 1)
{
Add(Fraction);
}
if (num =2)
{
Subtract(Fraction);
}
if (num =3)
{
Multiply(Fraction);
}
if (num =4)
{
Divide(Fraction);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void menu(int,int,int,int,int)
{
int num;
int n1;
int n2;
int d1;
int d2;
cout<<"Enter:"<<endl;
cout<<"1 :To add a fraction"<<endl;
cout<<"2 :To subtract a fraction"<<endl;
cout<<"3 :To multiply a fraction"<<endl;
cout<<"4 :To divide a fraction"<<endl;
cout<<"9 :To exit the program"<<endl;
cin>>num;
cout<<"For fraction 1"<<endl;
cout<<"Enter the numerator"<<endl;
cin>>n1;
cout<<"Enter the denominator"<<endl;
cin>>d1;
cout<<"For fraction 2"<<endl;
cout<<"Enter the numerator"<<endl;
cin>>n2;
cout<<"Enter the denominator"<<endl;
cin>>d2;
}
```

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert

See if this solution works for you by signing up for a 7 day free trial.

Unlock 1 Answer and 22 Comments.

Try for 7 days”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.