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
Which IDEs support multiple high-level programming languages? Select all that apply.
nata0808 [166]

Answer:

eclipse, xcode, and visual studio

6 0
3 years ago
Read 2 more answers
How do I give Brainliest?? I'll give brainliest...
Elodia [21]
Can i have it don’t think i ever got one
8 0
3 years ago
Read 2 more answers
What computer worm was used to sabatoge iran's nuclear program?
Stels [109]
Researches at symantec have uncovered a version of the stuxnet computer virus that was used to attack irans nuclear program in November.
4 0
3 years ago
kate decides to download an extension to her favorite browser to quickly store links on her spreadsheet software. while download
uranmaximum [27]

By ignoring the opt-out check box that allows the extension to download a search toolbar, the error which has occurred here is that: d. Kate has installed a potentially unwanted program (PUP).

<h3>What is a software?</h3>

A software can be defined as a set of executable instructions that is typically used to instruct a computer system on how to perform a specific task (function) and proffer solutions to a particular problem.

<h3>What is a potentially unwanted program (PUP)?</h3>

A potentially unwanted program (PUP) can be defined as a piece of software that's bundled into download packages and may be unwanted by the end user because it offers no benefits or may pose high risk.

In this scenario, we can reasonably infer and logically deduce that the error which has occurred here is that Kate has installed a potentially unwanted program (PUP) because she ignored the opt-out check box which then allowed the extension to download a search toolbar.

Read more on potentially unwanted program here: brainly.com/question/25091456

#SPJ1

Complete Question:

Kate decides to download an extension to her favorite browser to quickly store links on her spreadsheet software. While downloading the software, she ignores the opt-out check box that allows the extension to download a search toolbar.

What has occurred here?

a. Kate has installed an injection.

b. Kate has installed a backdoor.

c. Kate has installed a Trojan.

d. Kate has installed a potentially unwanted program (PUP).

4 0
1 year ago
Outlook 2016 is not only an email client, but it can also be used to schedule meetings and
klio [65]

Answer:

Outlook 2016 is not only an email client, but it can also be used to schedule meetings and <u>Manage appointments</u>.

Explanation:

Microsoft Outlook is a tool that is used to send and receive emails. In outlook 2016 version it has many other advantages such as:

  1. Managing Contact Directory
  2. Managing Address Books
  3. Scheduling Meetings
  4. Managing Appointments
5 0
3 years ago
Read 2 more answers
Other questions:
  • What was the second phone?
    14·1 answer
  • Tricia listed her assets and liabilities. Credit Card Bill Car Loan Bonds Piano Bank Account Bicycle Which are Tricia’s liabilit
    8·2 answers
  • WILL DO A BRIANLY! Use an algorithm to help the Python Turtle get to the finish line in 10 steps by using only the 3 commands be
    12·1 answer
  • The smallest building block of a wireless lan is a ______.
    5·1 answer
  • Define the following term. data, database, DBMS, database system, data- base catalog, program-data independence, user wen', DBA,
    12·1 answer
  • An argument does not always have to be made in words. A piece of music
    12·1 answer
  • How does applying Fontworks effects to text on an advertising flyer change the text?
    14·2 answers
  • Jose would like to have text with predefined styles that can flow around an image in a variety of shapes and sizes
    10·2 answers
  • Which key doesn't relate to keyboard A:return key B :enrollment key C: delete key D:tab key
    9·2 answers
  • What is the output for the following program?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!