98 875
Assignments Done
98.6%
Successfully Done
In April 2021

# Answer to Question #16432 in C++ for arif hussain

Question #16432
Q#3 Write a program that creates four function calculator, so that it uses functions for each of the four arithmetic operations. They can be fadd, fsub, fmul, and fdiv. Each of these functions should take three arguments two of int type and one is of character type for the opera
1
2012-10-16T09:42:59-0400
#include<iostream>

#include<conio.h>

using namespace std;

struct fraction{int numerator; int denominator;};

fraction fsub(fraction a, fraction b);

fraction fmul(fraction a, fraction b);

fraction fdiv(fraction a, fraction b);

void main(void)

{

fraction f[3]; char c, op;

do{

cin >>f[0].numerator>>c>>f[0].denominator>>op>>f[1].numerator>>c>>f[1].denominator;

if(!f[0].denominator || !f[1].denominator) {cout<<"Illeagle fraction !"<<endl; op=false;}

switch(op) {

case '-':f[2]=fsub(f[0], f[1]); break;

case '*':f[2]=fmul(f[0], f[1]); break;

case '/':f[2]=fdiv(f[0], f[1]); break;

default:cout<<"Unknow operator please try again !"<<endl;}

cout<<"

!Press c to continue or any key to exit."<<endl<<endl;

}while(getch()=='c');

}

fraction f;

f.numerator =a.numerator*b.denominator+a.denominator*b.numerator;

f.denominator=a.denominator*b.denominator; return f;}

fraction fsub(fraction a, fraction b){

fraction f;

f.numerator =a.numerator*b.denominator-a.denominator*b.numerator;

f.denominator=a.denominator*b.denominator; return f;}

fraction fmul(fraction a, fraction b){

fraction f;

f.numerator =a.numerator*b.numerator;

f.denominator=a.denominator*b.denominator; return f;}

fraction fdiv(fraction a, fraction b){

fraction f;

if(b.numerator != 0){

f.numerator =a.numerator*b.denominator;

f.denominator=b.numerator*a.denominator;}

else cout<<"Math error !"<<endl; return f;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!