1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <iostream>
using namespace std;
void showFrac();
void add(int N1, int N2, int D1, int D2, int numrator, int denominator);
void subtract(int N1, int N2, int D1, int D2, int numrator, int denominator);
void multiply(int N1, int N2, int D1, int D2, int numrator, int denominator);
void divide(int N1, int N2, int D1, int D2, int numrator, int denominator);
void Quit();
int main()
{
showFrac();
system ("pause");
}
void showFrac()
{
int N1, N2, D1, D2, numrator = 0, denominator = 0;
int choose( '\0' );
while (choose != 5)
{
cout<<" \n 1 : Add fraction";
cout<<" \n 2 : Subtract fraction";
cout<<" \n 3 : Multiply fraction";
cout<<" \n 4 : Divide fraction";
cout<<" \n 5 : Quit";
cout<<" \n Your choice: ";
cin >> choose;
if (choose <=4)
{
cout <<"\n Enter first numerator: ";
cin >> N1;
cout <<"\n Enter first denominator: ";
cin >> D1;
cout <<"\n Enter second numerator: ";
cin >> N2;
cout << "\n Enter second denominator: ";
cin >> D2;
}
switch(choose)
{
case 1:
add(N1, N2, D1, D2, numrator, denominator);
break;
case 2:
subtract(N1, N2, D1, D2, numrator, denominator);
break;
case 3:
multiply(N1, N2, D1, D2, numrator, denominator);
break;
case 4:
divide(N1, N2, D1, D2, numrator, denominator);
break;
case 5:
Quit();
break;
default:
cout<<"Enter correct input"<<endl;
}
}
}
void add(int N1, int N2, int D1, int D2, int numrator, int denominator)
{
if(D1 != 0 && D2 != 0)
{
numrator = ((N1 * D2) + (N2 * D1));
denominator = D1 * D2;
cout << N1 << "/" << D1 << " " << "+" << " " << N2 << "/" << D2 << "=" << numrator << "/" << denominator;
}
}
void subtract(int N1, int N2, int D1, int D2, int numrator, int denominator)
{
if(D1 != 0 && D2 != 0)
{
numrator = ((N1 * D2) - (N2 * D1));
denominator = D1 * D2;
cout << N1 << "/" << D1 << " " << "-" << " " << N2 << "/" << D2 << "=" << numrator << "/" << denominator;
}
}
void multiply(int N1, int N2, int D1, int D2, int numrator, int denominator)
{
if(D1 != 0 && D2 != 0)
{
numrator = N1 * N2;
denominator = D1 * D2;
cout << N1 << "/" << D1 << " " << "*" << " " << N2 << "/" << D2 << "=" << numrator << "/" << denominator;
}
}
void divide(int N1, int N2, int D1, int D2, int numrator, int denominator)
{
if(D1 != 0 && D2 != 0)
{
numrator = N1 * D2;
denominator = N2 * D1;
cout << N1 << "/" << D1 << " " << "/" << " " << N2 << "/" << D2 << "=" << numrator << "/" << denominator;
}
}
void Quit()
{
cout << "\n\tThank You\n\n";
}
| |