1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NemiM [27]
3 years ago
11

Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, in which a and b a

re integers and b is not equal to 0. Your program must be menu driven, allowing the user to select the operation ( , -, *, or /) and input the numerator and the denominator of each fraction. Furthermore, your program must consist of at least the following function
menu: This function informs the user about the program's purpose, explains how to enter data, how to quit and allows the user to select the operation.
addFractions: This function takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result.
subtractFractions: This function takes as input four integers representing the numerators and denominators of two fractions, subtracts the fractions, and returns the numerator and denominator of the result.
multiplyFractions: This function takes as input four integers representing the numerators and denominators of two fractions, multiplies the fractions, and returns the numerator and denominator of the result.
divideFractions: This function takes as input four integers representing the numerators and denominators of two fractions, divides the fractions, and returns the numerator and denominator of the result.

Here are some sample outputs of the program:

3 / 4 +2 / 5 = 23 / 20
2 / 3 * 3 / 5 = 2 / 5
Computers and Technology
1 answer:
serious [3.7K]3 years ago
8 0

Answer:

Explanation:

The following code is written in Java, It asks the user to enter the numerator and denominator for both fraction 1 and 2. Then it prompts the user with a menu to choose the desired operation. The choice is passed into a switch statement and calls the correct function.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int num1, num2, den1, den2;

       System.out.println("Enter numerator for fraction 1: ");

       num1 = in.nextInt();

       System.out.println("Enter denominator for fraction 1: ");

       den1 = in.nextInt();

       System.out.println("Enter numerator for fraction 2: ");

       num2 = in.nextInt();

       System.out.println("Enter denominator for fraction 2: ");

       den2 = in.nextInt();

       System.out.println("Menu:");

       System.out.println("+ = add fractions");

       System.out.println("- = subtract fractions");

       System.out.println("/ = divide fractions");

       System.out.println("* = multiply fractions");

       String answer = in.next();

       switch (answer.charAt(0)) {

           case '+': add(num1, den1, num2, den2); break;

           case '-': subtract(num1, den1, num2, den2); break;

           case '*': multiply(num1, den1, num2, den2); break;

           case '/': divide(num1, den1, num2, den2); break;

       }

   }

   public static void add(int num1, int den1, int num2, int den2) {

       int num3 = (num1 * den2) + (num2 * den1);

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void subtract(int num1, int den1, int num2, int den2) {

       int num3 = (num1 * den2) - (num2 * den1);

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void divide(int num1, int den1, int num2, int den2) {

       int num3 = num1 * den2;

       int den3 = den1 * num2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void multiply(int num1, int den1, int num2, int den2) {

       int num3 = num1 * num2;

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

}

You might be interested in
What is true about super computers?
lorasvet [3.4K]

Explanation:

Super Computer are expensive computer that are used to provide very quick results. Super computer are used in calculating complex mathematical calculations. Calculations such as weather forecast and Atomic energy research. Therefore Super Computer perform complex calculations rapidly.

5 0
3 years ago
In this exercise, use the following variables : i,lo, hi, and result. Assume that lo and hi each are associated with an int and
Assoli18 [71]

Answer:

result = 0

i = lo

while i <= hi:

       result = result + i

       i += 1

Explanation:

Initialize the <em>result</em> as 0 to hold the summation value.

Since we are asked not to change the value of <em>lo</em> and <em>hi</em>, our loop control variable is <em>i</em> and initially it starts from <em>lo.</em>

Since we are asked to add the number from <em>lo</em> to <em>hi, </em>while loop condition checks it.

While the condition satisfies (during each iteration), the value of <em>i</em> is added to the result and the value of <em>i</em> is incremented by one.

7 0
2 years ago
Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
shusha [124]

Answer:

It can be found on View tab.

Explanation:

The view tab on Microsoft Power point is the 9th tab when counting from the left. When clicked, the view tab displays a number of tools that are aimed at visualizing how slides appear.

The ruler function is one of those tools. It is used to ensure that an object is placed or appears at a specific location in the slides. The ruler tool can be found in the Show Box which is the third box from left after Presentation View and Master View.

8 0
3 years ago
Read 2 more answers
Readability is the level of vocabulary used on the page. True or false
konstantin123 [22]

Answer:

FALSE....john has no idea what hes talking about. i knew this was false yet i looked it up and got it wrong anyway because of john its freaking false

Explanation:

8 0
3 years ago
.WAP to enter monthly sale of Salesman and give him commission i.E. If the monthly sale is more than 500000 then commision will
nexus9112 [7]

sales = float(input("Enter monthly sales amount: $"))

commission = 0.05

if sales> 500000:

   commission = 0.1

print("You earned: $"+str(sales*commission))

I wrote my code in python 3.8. I hope this helps.

5 0
2 years ago
Other questions:
  • Navigational signs on the highway are often which colors?
    10·2 answers
  • Effective note-taking helps support<br><br> action.<br> distinction.<br> distraction.<br> retention.
    9·2 answers
  • The benefits associated with AAA are increased security, increased control over the network, and the capability of auditing your
    12·1 answer
  • Use the Internet and other sources to research the two disadvantages of standard biometrics: cost and error rates. Select one st
    10·1 answer
  • Create the tables and appropriate constraints based on the following ER diagram. Use appropriate data types. Note that the size
    7·1 answer
  • Which hardware device connects your network to the internet? select one:
    15·1 answer
  • 10010 - 1011 binary subtraction​
    5·1 answer
  • Ill give alot of points if you answer: How do I get a 100 dollar ps4
    5·2 answers
  • You looked at the methods used to determine database requirements. Now, research and find a database requirements template. Choo
    9·1 answer
  • Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!