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
emmasim [6.3K]
3 years ago
13

Write a calculator program using a switch statement that: a) Prompts the user to enter two numbers b) Prompts the user to select

between the four arithmetic operations using a choice from 1-4; for example, prompt the user with: "Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide)" c) Calculates the result of performing the selected operation on the numbers, and d) Displays the answer on the screen (15 pts)
Computers and Technology
1 answer:
dlinn [17]3 years ago
5 0

Answer:

// calculator program in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int x,y;

int ch;

   cout<<"Enter 1st number:";

   // read first number

   cin>>x;

   cout<<"Enter 2nd number:";

   // read second number

   cin>>y;

   cout<<"Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide):";

   // read choice

   cin>>ch;

   switch(ch)

   {

       // if choice is 1, find Addition

       case 1:

       cout<<"Addition of two numbers is:"<<(x+y)<<endl;

       break;

       // if choice is 2, find subtraction

       case 2:

       cout<<"Subtract the second from the first is:"<<(x-y)<<endl;

       break;

       // if choice is 3, find multiplication

       case 3:

       cout<<"Multiplication of two numbers is:"<<(x*y)<<endl;

       break;

       // if choice is 4, find division

       case 4:

       cout<<"Division the first by the second is:"<<(x/y)<<endl;

       break;

       // if choice is other

       default:

       cout<<"Wrong choice:"<<endl;

       break;

   }

return 0;

}

Explanation:

Read two numbers from user.Then read the choice of operation from user.If choice is 1, then print the Addition of both numbers.If choice is 2, then print the subtraction. If the choice is 3, then print the multiplication.If choice is 4, then print the  division.If choice is other than these, then print wrong choice.

Output:

Enter 1st number:10                                                                                                      

Enter 2nd number:2                                                                                                      

Choose 1) for add, 2) for subtract, 3) for multiply or 4) for divide):3                                                    

Multiplication of two numbers is:20

You might be interested in
One of the most toxic components of a computer is the
Cloud [144]
The most common is usually lead found in the glass or some circuits in rare cases
6 0
3 years ago
WHAT DOES THE SCRATCH CODE BELOW DO?
Natasha_Volkova [10]

Answer:

the first one

Explanation:

3 0
2 years ago
How does naming affect a variable’s creation and use?
Evgen [1.6K]

Answer:

Each variable is named so it is clear which variable is being used at any time. It is important to use meaningful names for variables: ... The name given to each variable is up to the programmer, but ideally a variable name should have meaning, ie it should reflect the value that it is holding.

Variables make code more than a static set of instructions. They allow logic to occur, enabling developers to measure time, analyze data, and customize the program to the user. Variables are so important to the code that they deserve a good name that accurately describes their purpose

Explanation:

4 0
2 years ago
Perform algorithm time measurement for all three quadratic sorting algorithms for Best Case (already sorted), Average Case (rand
Kaylis [27]

Answer:

Experiment size : 50,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Insertion sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Bubble sort:

--------------------------------------------------------

Worst case : 0.211

Average case : 0.154

Best case : 0.117

Experiment size : 100,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Insertion sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Bubble sort:

--------------------------------------------------------

Worst case : 0.482

Average case: 0.487

Best case : 0.480.

Experiment size : 200,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Insertion sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Bubble sort:

--------------------------------------------------------

Worst case : 1.990

Average case : 2.009.

Best case : 1.950

Explanation:

[NB: since it is very long there is the need for me to put it it a document form. Kindly check the doc. Files. The file A is the sort Analysis.Java file and the file B is the sort.Java file].

The concept of algorithm time measurement strictly depends on the following;

=> The measurement of time, space or energy on different sizes.

=> Plotting of the measurements and characterizing them.

=> Running or implementation of the algorithm.

Programming language such as Java can be used in accessing the operating system clock and Java had two static methods.

KINDLY CHECK BELOW FOR THE ATTACHMENT.

Download doc
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
5 0
3 years ago
A new laptop was delivered to your home and left on the porch while you were at work. It is very cold outside, and you don't kno
kifflom [539]

Answer:

Let the computer warm up to room temperature before turning it on.

Explanation:

The laptop has been shipped to the user's home when he were at work and found on the deck. Outside it is really cool and he don't remember how long it has been there. Then, the user open his laptop and want to know whether it is functioning properly. Instead, let the machine warm up while switching it on to room temperature.

When a computer is still in a cold climate, they have to let it heat up to room temperature apx. 6-24 hours before switching it on. Otherwise, its heat the elements generate could cause water moisture within the laptop. That water could then harm elements of the system.

7 0
3 years ago
Other questions:
  • The operation of the waste spark Ignition system is being discussed. technician a says that the spark that occurs on the exhaust
    14·1 answer
  • In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa
    10·2 answers
  • A. True
    8·2 answers
  • Your company received a call from a historical society inquiring about the possibility of networking a two-century-old building
    15·1 answer
  • Many 12-15 yrs hv access to the internet which cannot be supervised by an adult.i need 5 problems tht this might cause
    5·1 answer
  • Of the measures of feasibility in the accompanying figure, ____ considers points such as "Does the proposed platform have suffic
    8·1 answer
  • If you do not specify any criteria in a delete query, Access will delete all the records in the table. Truth or False
    11·1 answer
  • Which TWO objects are likely to have SSD chips in them?
    5·2 answers
  • 100 POINTS!!!!!!!
    15·2 answers
  • I want to start a debate about something
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!