Question

Create a procedure driven program for performing arithmetic with fractions. Using a switch statement in main...

Create a procedure driven program for performing arithmetic with fractions. Using a switch statement in main to perform the various actions. Similar to this;

Menu

a) Load/Reload first fraction

b) Load/Reload second fraction

c) Add two fractions and display answer

d) Subtract two fractions and display answer

e) Multiply two fractions and display answer

f) Divide two fractions and display answer

g) Exit

Provide functions that allow for The reloading of the fractions.

The addition of two rational numbers.

The result should be displayed in reduced form and as a decimal.

The subtraction of two rational numbers.

The result should be displayed in reduced form and as a decimal.

The multiplication of two rational numbers,

The result should be displayed in reduced form and as a decimal.

The division of two rational numbers.

The result should be displayed in reduced form and as a decimal.

Reducing a fraction

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#include<conio.h>

void main()

{

int ch;

printf("**********************what do want to do****************");

printf("1: For Addition");

printf("2: For subtraction");

printf("3: For multiplication");

printf("4: For Division");

scanf("%d",&ch);

switch(ch)

{

case 1:

{

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

int main()
{
    int T;
    scanf("%d", &T);

    for (int i=1; i<=T; i++)
    {
        int num1, den1;
        int num2, den2;
        scanf("%d%*c%d %d%*c%d", &num1,&den1,&num2,&den2);

        int num3, den3;
        den3 = gcd(den1,den2);
        den3 = (den1*den2)/den3;
        num3 = (num1)*(den3/den1) + (num2)*(den3/den2);
        printf("Case %d: %d/%d\n", i, num3, den3);
    }

    return 0;
}

}

case 2:

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

int main()
{
    int T;
    scanf("%d", &T);

    for (int i=1; i<=T; i++)
    {
        int num1, den1;
        int num2, den2;
        scanf("%d%*c%d %d%*c%d", &num1,&den1,&num2,&den2);

        int num3, den3;
        den3 = gcd(den1,den2);
        den3 = (den1*den2)/den3;
        num3 = (num1)*(den3/den1) - (num2)*(den3/den2);
        printf("Case %d: %d/%d\n", i, num3, den3);
    }

    return 0;
}

}

case 3:

{

  

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

int main()
{
    int T;
    scanf("%d", &T);

    for (int i=1; i<=T; i++)
    {
        int num1, den1;
        int num2, den2;
        scanf("%d%*c%d %d%*c%d", &num1,&den1,&num2,&den2);

        int num3, den3;
        den3 = gcd(den1,den2);
        den3 = (den1*den2)/den3;
        num3 = (num1)*(den3/den1) * (num2)*(den3/den2);
        printf("Case %d: %d/%d\n", i, num3, den3);
    }

    return 0;
}

}

case 4:

{

  

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

int main()
{
    int T;
    scanf("%d", &T);

    for (int i=1; i<=T; i++)
    {
        int num1, den1;
        int num2, den2;
        scanf("%d%*c%d %d%*c%d", &num1,&den1,&num2,&den2);

        int num3, den3;
        den3 = gcd(den1,den2);
        den3 = (den1*den2)/den3;
        num3 = (num1)*(den3/den1) / (num2)*(den3/den2);
        printf("Case %d: %d/%d\n", i, num3, den3);
    }

    return 0;
}

}

}

getch();

}

Add a comment
Know the answer?
Add Answer to:
Create a procedure driven program for performing arithmetic with fractions. Using a switch statement in main...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to...

    (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to h and would be stored in the object as 1 in the numerator...

  • (Rational class) Create a class called Rational for performing arithmetic with fractions. Write a program to...

    (Rational class) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integers variables to represent the private data of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case are no initializers are provided and should store the fraction in reduced form. For example, the fraction 3/6 would be...

  • Please use Java language. Thanks in advance. HOME WORK due 09. 18.2019 (Rational Numbers) Create a...

    Please use Java language. Thanks in advance. HOME WORK due 09. 18.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 2...

  • Can somebody help me with this assignment. I will highly appreciate. Also, please display the output...

    Can somebody help me with this assignment. I will highly appreciate. Also, please display the output as well. I need to use JAVA to to write the program. This is the sample output provided by my professor. HOME WORK: due 09.17.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor...

  • Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an...

    Do not use pointer variables, pointer arithmetic or operater new ITCS-2530    Project                        Write an interactive program that performs fractional calculations. You need define a class CFrac for a fractional number according to the UML diagram below: CFrac - numerator : int - denominator : int - simplify () : void + CFrac (int = 0, int = 1) + ~CFrac() + add (const CFrac&) const : CFrac + subtract (const CFrac&) const : CFrac + multiply (const CFrac&)...

  • PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL. *****PLEASE USE C#(C SHARP)*...

    PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL. *****PLEASE USE C#(C SHARP)***** Also please dont use BigInteger thanks it's really appreciated for all the help PLEASE MAKE IT SO ITS USER INPUT Create a class called Rational for prforming arithmetie with fractions. Write an app to test your class Use integer variables to represent the private instance variables of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized...

  • Description: In the main program create a menu system that will allow a user to choose...

    Description: In the main program create a menu system that will allow a user to choose from 3 option. 1. Fraction calculator 2. Grading schema 3. Biggest integer Program #1 Fraction calculator: You will start by prompting the user for two fractions in the main. The inputs should be two strings in the form #/#. You must account for both positive and negative numerators. Therefor -#/# is also a valid input. In a separate function create a program that will...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int...

    Header file for the Rational class: #ifndef RATIONAL_H #define RATIONAL_H class Rational { public: Rational( int = 0, int = 1 ); // default constructor Rational addition( const Rational & ) const; // function addition Rational subtraction( const Rational & ) const; // function subtraction Rational multiplication( const Rational & ) const; // function multi. Rational division( const Rational & ) const; // function division void printRational () const; // print rational format void printRationalAsDouble() const; // print rational as...

  • C++...please help follow exact steps output needs to be the exact same Create a class called...

    C++...please help follow exact steps output needs to be the exact same Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the elass the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT