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
Controlling inflation is the job of the __________________.
n200080 [17]
B. Federal Reserve................
8 0
3 years ago
Read 2 more answers
Which is true of case-based reasoning (CBR)?
DaniilM [7]

Answer:

The correct option is Option C: It matches a new problem with a previously solved problem and its solution.

Explanation:

Case-based reasoning (CBR) is used when someone tries to solve new problems based on old problems that were similar. The person applying case-based reasoning would look for the solutions to these similar past problems and try to apply them to the new case. For example, a doctor who tries to treat a patient based on what was successful with a prior patient with a similar problem is applying case-based reasoning. In some instances, these problems are available in a database and ideally, that is how it is conceived, but it would depend on the field and the kind of problems. There is no universal global network dedicated to CBR as a whole (other than generic searches on the internet in general). One example of a specific CBR database is the European Nuclear Preparedness system called PREPARE.

4 0
3 years ago
Has anyone done the unit 10 lesson 9 encryption/decryption texts on code.org?
Pani-rosa [81]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

5 0
3 years ago
What is the first thing you should do when troubleshooting a computer problem?
hichkok12 [17]

Answer:

A. Identify and locate the problem.

Explanation:

A problem-solving process can be defined as the systematic approach to used to identify and determine the solution to a particular problem.

The first thing you should do when troubleshooting a computer problem is to identify and locate the problem.

Basically, when an administrator or network engineer is trying to proffer a solution to a computer or network-related problem, it is very important and essential for he or she to first identify what the problem is. This is necessary because it will help to ensure that his or her energy is channeled in the right direction.

Hence, once the problem is identified, then a theory of probable cause can be established.

6 0
3 years ago
Read 2 more answers
I have an IPhone 8plus 64gb... should I get another phone like samsung note 9 or s9 ??
laiz [17]

Nah, I think the IPhone would be better than them both


7 0
3 years ago
Other questions:
  • Timing circuits are a crucial component of VLSI chips. Here’s a simple model of such a timing circuit. Consider a complete balan
    10·1 answer
  • The cyclical, multistep process by which designers and engineers design, build, and taste a new product is called:
    9·1 answer
  • If you wish to include a header or footer on all pages in a publication, you will need to insert this by navigating to the _____
    11·2 answers
  • THE bestValue PROBLEM Using the Camera structure defined in file p1.cpp, write the function named bestValue(). The function take
    13·1 answer
  • Which of the following is an example of a formal business standard
    14·2 answers
  • The 7-bit ASCII code for the character ‘&’ is: 0100110 An odd parity check bit is now added to this code so 8 bits are trans
    12·1 answer
  • Difference between positional and non positional number​
    12·1 answer
  • What is the correct order of the phases of the software development process?
    14·1 answer
  • The quickest way to change a word is to double
    11·1 answer
  • Computer professionals known as software engineers, or Blank______, use the software development life cycle to create software r
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!