Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming in C!!!!!!!! Create a structure called Fraction to store fractions h

ID: 3714588 • Letter: P

Question

Programming in C!!!!!!!!

Create a structure called Fraction to store fractions having numerator and denominator (both of them are integers). Given a command and a pair of fractions, execute the command using the following functions that you have to implement.

(a) Fraction addition (Fraction a, Fraction b)

(b) Fraction subtraction (Fraction a, Fraction b)

(c) Fraction multiplication (Fraction a, Fraction b)

(d) Fraction division (Fraction a, Fraction b)

Your code should contain a main() function where you will take inputs from a file named “input.txt” and write outputs to a file named “output.txt”. All your inputs will be valid fractions, so no need to check for divide by zero error

Create a class called Fraction to store fractions Given a command and a set of fractions, execute the command using operator overloading and print the result. Input Format The first line contains a single integer T, denoting the number of test cases. (1

Explanation / Answer

this is the main logic, now i hope you can do file input output operations

#include<iostream>
using namespace std;
int gcd(int ,int );
int main()
{
   int a,b,c,d,num,dum;
   cout<<"enter a and b";
   cin>>a>>b;
   cout<<"enter c and d";
   cin>>c>>d;

   num=a*d+b*c;
   dum=b*d;
   cout<<"num="<<num<<"dum="<<dum;
   int g=gcd(num,dum);
   cout<<" g="<<g;
   num=num/g;
   dum=dum/g;
   cout<<" "<<num<<"/"<<dum;

}
int gcd(int a,int b)
{
if(a<b)
   return gcd(b,a);
if(a%b==0)
   return b;
else return gcd(b,a%b);
}