Concept explainers
Convert the following if/else if statement into a switch statement:
if (choice== 1)
cout <<fixed<< showpoint << setprecision(2);
else if ((choice== 2) || (choice== 3))
cout << fixed << showpoint << setprecision(4);
else if (choice== 4)
cout << fixed << showpoint << setprecision(6);
else
cout << fixed << showpoint << setprecision(8);
Trending nowThis is a popular solution!
Chapter 4 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
SURVEY OF OPERATING SYSTEMS
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Database Concepts (8th Edition)
- Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows: If a customer purchases no books, he or she earns 0 points If a customer purchases 1 through 5 books, he or she earns 5 points for each book. If a customer purchases 6 through 10 books, he or she earns 10 points for each book. If a customer purchases 11 or more books, he or she earns points equal to 20 points for each book. (Use Python) Use the Design Recipe to write the function customer_rewards which consumes the number of books purchased, and returns the total points. Include a docstring! Write 3 assert_equal statements to test your function.arrow_forwardLab: switch Note: switch syntax is only applied for service selection. You can use if – else syntax for other comparison. Using switch syntax to write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minutes. Premium service: $25 plus For calls made from 6:00 a.m to 6:00 p.m., the first 75 minutes are free; charges for more than 75 minutes are $0.10 per minute. For, calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for more than 100 minutes are $0.05 per minute. Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code for r or R means regular service; a service…arrow_forwardLecture Note Form : F = ±(0.d₁d2d3... dm) ße, Normalized Form : F= ±(1.d₁d2d3 ... dm) B Be Denormalized Form : F= ±(0.1d₁d2d3 ·dm) 3 ße ... Let ß = 2, m = 4, emin = -1 and emax = 2. Answer the following questions: (a) Compute the minimum of r for normalized form. (b) Compute the Machine Epsilon value for the normalized form. Compute the maximum delta value for the form given in Eq. (1). (c) .(i) .(ii) .(iii)arrow_forward
- Question text Determine whether the ff hypotheses about a computer program • There is an undeclared variable or there is a syntax error in the first five lines. • If there is a syntax error in the first five lines, then there is a missing semicolon or a variable name is misspelled. • There is not a missing semicolon. • There is not a misspelled variable name. lead to the conclusion • There is an undeclared variable. Let the following symbols represent the corresponding statements: uv - There is an undeclared variable. se - There is a syntax error in the first five lines. ms - There is a missing semicolon. vm - There is a misspelled variable name. Thus, in symbolic form, we have to show whether the argument below is valid: uv V se se → (ms V vm) ~ ms ~ VM ... uvarrow_forwardA one-way if statement performs an action if the specified condition is true. If the condition is false, nothing is done. But what if you want to take alternative actions when the condition is false?arrow_forward5. Write an efficient if statement to assign x the value 1 if x ≤ 1.5, 2 if 1.5arrow_forward
- Write a statement to print the data members of InventoryTag. End with newline. Ex: if itemID is 314 and quantityRemaining is 500, print:Inventory ID: 314, Qty: 500 Only lines 14-16 can be added onto, the rest of the program cannot be changed.arrow_forwardCode Example 3-1 num_widgets = 0 while True: choice input ("Would you like to buy a widget? (y/n): ") if choice. lower () == "y": num_widgets += 1 else: break print ("You bought", num_widgets, "widget (s).") Refer to Code Example 3-1. If the user enters "Y" at the prompt, what does the program print to the console? O a. You bought 1 widget (s) today. O b. You bought 0 widget (s) today. O c. You bought Y widget (s) today. O d. Nothing, the break statement will cause the program to endarrow_forward2-18 Please answer question. my answers are incorrect, thank you!arrow_forward
- Q12: If you have problem with two conditions which type of if construct is preferred to use? O All of the given Oif-elseif-else - end. O if- end O switch - case O if-else - endarrow_forwardWrite an if statement that assigns 20 to the variable y, and assigns 40 to the variable z if the variable x is greater than 100. Write an if statement that assigns 0 to the variable b, and assigns 1 to the variable c if the variable a is less than 10. Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10. Otherwise, it should assign 99 to the variable b. Write nested decision structures that perform the following: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amount2.arrow_forwardTrue or False? Every if statement must have a corresponding else.arrow_forward
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage