Concept explainers
Sometimes either a switch statement or an if /else if statement can be used to implement logic that requires branching to different blocks of program code. But the two arc not interchangeable.
A) Under what circumstances would an if/else if statement be a more appropriate choice than a switch statement?
B) Under what circumstances would a switch statement be a more appropriate choice than an if/else If statement?
C) Under what circumstances would a set of nested if/else statements he more appropriate than either of the other two structures?
Try to come up with at least one example case for each of the three, where it is the best way to implement the desired branching logic.
Learn your wayIncludes step-by-step video
Chapter 4 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Problem Solving with C++ (10th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Concepts Of Programming Languages
- 1. Write a program in C which is a Menu-Driven Program to compute the area of the various geometrical shapes. You are required to use switch... case statement. i. Circle ii. Rectangle iii. Cylinder 2. Write a C program to read electricity unit (kW) and calculate the total electricity bill (RM) according to the given condition by using if... else if statement → For first 100 units RM 0.44/unit ⇒>> For next 100 units RM 0.51/unit For unit above 200 RM 0.65/unit →>> An additional tax (SST) of 6% is added to the bill. RM must be shows in two decimal points. => The output must have the option to choose from a menu as follow: Information of tariff charge; i. ii. Calculate a power consumption (kWh) from the keyboard and display the total bill; If the total bill calculated is less than or equal to RM20, print "Your bill is free". Otherwise, print the total bill. iii. Exit the calculator and say "Thank You", Other than the options, print "Option unavailable"arrow_forward*Computer Fundamentals and Programming using Compound assignmentarrow_forwardIn C Language 1. Can nested if statements be used as an alternative to the logical And and Or operators? (Answer Yes or No only) 2. Assuming resident is a Boolean variable, is if (resident) the same as if(resident==true)? (Answer Yes or No only)arrow_forward
- *Computer Fundamentals and Programming using Compound assignmentarrow_forward(Data processing) Years that are evenly divisible by 400 or are evenly divisible by 4 but not by 100 are leap years. For example, because 1600 is evenly divisible by 400, 1600 was a leap year. Similarly, because 1988 is evenly divisible by 4 but not by 100, it was also a leap year. Using this information, write a C++ program that accepts the year as user input, determines whether the year is a leap year, and displays a message telling the user whether the entered year is or is not a leap year.arrow_forwardsoleve with c++ use case Write a Mark Sheet program that accepts the marks of the different subjects from the user. Calculate total marks, percentage and grade. If per<60 and per >50 then Grade is "C" If per<70 and per >60 then Grade is "B" If per<80 and per >70 then Grade is "A" If per >80 then Grade is "A-1" If per<50 then prints FAIL.arrow_forward
- Use C++ Language Create a program that will determine if a student needs to take a final exam. This decision depends on the course grade average and the student’s attendance. Use the flow chart below for the final exam criteria.arrow_forwardIn C programming languagearrow_forwardWrite a C programarrow_forward
- Matlab programming please helparrow_forward2. | Write a boolean expression in C++ that evaluates to true if variable y is in the interval from 10 to 50, exclusive; or if the value of y is negative. Note that only the boolean expression is expected, and not an entire if statement.arrow_forwardWrite a C programarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage