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
________ is the set of instructions that programmers have written in a higher-level language. select one:
kicyunya [14]
The answer is a. Source Code.   It is the set of instructions that programmers have written in a higher-level language.  When a programmer types a sequence of C language<span> statements into Windows Notepad, for example, and saves the sequence as a text file, the text file is said to contain the source code. </span>
6 0
4 years ago
Which of these utility tools would you least expect a support agent to find useful to increase security for end users?
tia_tia [17]

Answer:

b. Network performance monitor

Explanation:

A utility tool can be defined as a software application or program designed to add more functionality to a computer system, as well as to improve its performance efficiently. Some examples of commonly used utility tools in computer are file and folder backup tools, file management, antivirus, hard disk diagnostics, registry cleaner, network performance monitor, screensavers etc.

In the context of increasing security for the end users, the most important utility tools are;

1. Antivirus utility: to scan, detect, remove and prevent computer viruses such as Malware, Trojan horses, keyloggers, botnets, adwares etc.

2. Rootkit utility: it can be used to detect and remove any rootkit program that is hidden in a computer.

3. Spyware utility: this is used to detect, remove and prevent malicious adware that are found in software applications.

<em>However, a network performance monitor is a utility tool that would be found to least support an agent in increasing security for end users because it is a utility tool that is primarily used to monitor network traffic and amount of data usage. </em>

7 0
3 years ago
How can I get more views on my you tube channel "Braeden Eischen" without paying anything
ehidna [41]
I’m just post video and there
5 0
3 years ago
To most efficiently distribute IP address pools in networks, system administrators typically set up services that automatically
zhuklara [117]

Answer:

Explanation:

Dynamic host configuration protocol DHCP help us to assign an IP automatically, with this method is not necessary to get more IP blocks because this method use lease time or rental IP, this means, if an IP is not being used, this is save for the next user, in this case, we're reciclyn the IP bloks, and this is the most efficient way to administrate our IP address.

8 0
3 years ago
Jacinta registered herself on a social-networking site. She receives one or two emails every day about promotional offers as wel
Rainbow [258]
It would be Spam. . . . 

3 0
4 years ago
Other questions:
  • A company ABC asked you to design a simple payroll program that calculates and employee's weekly gross pay, including any overti
    9·1 answer
  • Steve wants to become a successful graphic design entrepreneur. Which entrepreneurial approach will help him succeed? A. working
    14·1 answer
  • // PrintStrings // Traverse the 2D character array "strings" and print each of the contained strings.// See the example outputs
    10·1 answer
  • How many apostrophes or quotation marks in a row should you use to begin and end a multi-line string?
    14·2 answers
  • When you’re in the Normal view, what are the visible panes?
    15·2 answers
  • True / False<br> 1. A byte is a standardized unit of measure that is always 8-bits.
    7·1 answer
  • Put the following five steps in the order in which you would perform them to use the Paste Special function. 1. Select and copy
    6·1 answer
  • Implementing information systems has economic, organizational, and behavioral effects on firms. Information technology, especial
    14·1 answer
  • In a linked chain implementation of a queue, the performance of the enqueue operation
    10·1 answer
  • Write convert() method to cast double to int
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!