Transcribed TextTranscribed Text

Fractional Numbers with Structure Create a structure called Fract ion 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. Input Format The first line contains a single integer T. denoting the number of test cases. (1 <-T<-25). Each line i of the subsequent lines consists of a character representing command c, followed by a set of fractions of the form numerator denominator, separated by a space. The possible commands are: Command Instruction Example Example Explanation input output a Add the two fractions 1 2 1 4 3 4 1/2 + 1/4 = 3/4 3 Subtract the second fraction 3 2 1 4 3/4 - 1/2 = = from the first fraction 1/4 m Multiply the two fractions 5 10 14 7 1 1 5/10 * 14/7 1/1 d Divide the first fraction by the 1 4 2 1/2 3/4 = second fraction 2/3 All resulting fractions should be in their reduced form. e.g.: 5/10 + 1/10 6/10 After reduction, the result is 3/5. Sample Input Sample Output 4 a 1 2 5 10 1 3 1 2 1 10 m 1 6 3 4 1 8 d 1 8 2 32 2 1

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/* Include files */
#include <stdio.h>
#include <stdlib.h>

// Declare fraction structure
struct Fraction
int numerator;
int denominator;

// Declare fractional math operation functions
struct Fraction addition(struct Fraction a, struct Fraction b);
struct Fraction subtraction(struct Fraction a, struct Fraction b);
struct Fraction multiplication(struct Fraction a, struct Fraction b);
struct Fraction division(struct Fraction a, struct Fraction b);

// Beginning of Main Function
int main()
// Declare varibles
struct Fraction a;
struct Fraction b;
struct Fraction result;
int x = 0;
int i = 0;
int j = 0;
int T = 0;
char c;
FILE *iFile = fopen("input.txt", "r");
FILE *oFile = fopen("output.txt", "w");
if (iFile == NULL)
printf("Error! opening input file");
if (oFile == NULL)

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats