Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.11, Problem 4.34CP
Rewrite the following if / else statements as conditional expressions.
A) if (x > y)
z = 1;
else
z = 20;
B) if (temp > 45)
population = base * 10;
else
population = base * 2;
C) if (hours > 40)
wages * = 1.5;
else
wages *= 1;
D) if (result >= 0)
cout << "The result is positive\n";
else
cout << "The result is negative. \n";
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
c++ programming
if…else and switch case are types of conditional selection statements used in many programming languages such as C++. Write your own codes for question (a), (b) and (c) to demonstrate how the selection statement works.
(a) Using if….else selection statement, allow user to key in a number then check whether the number is positive or negative number.
(b) Using if….else...if selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 ..
(c) Using nested if..else selection statement, ask user to key in their age. Then define whether the user should go to nursery, primary school, secondary school or university based on their input.
(d) Using switch case selection statement, allow user to key in a mark for one subject and display the grade for the subject. A for >80, B for >60, C for >50, D for >40, F for <40 .
a. Assuming that x is 1, show the result of the following Boolean expressions.(true) && (3 > 4)!(x > 0) && (x > 0)(x > 0) || (x < 0)(x != 0) || (x == 0)(x >= 0) || (x < 0)b. Write a Boolean expression that evaluates to true if age is greater than 13 and less than18.c. Write a Boolean expression for |x - 5| < 4.5d. Rewrite the following if statements using the conditional operator.if (ages >= 16)ticketPrice = 20;elseticketPrice = 10;e. Explain what the following conditional expression does.(int)(Math.random() * 2) == 0 ? -1 : 1;
A contractor charges for wood flooring based on the amount of flooring to be installed. Total flooring under 200 square feet is $10/sq ft, flooring measuring 200-1000 square feet is $7/sq ft and anything over 1000 square feet is $5/sq ft. Write conditional statements to determine the appropriate outcome.
Chapter 4 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 4.1 - Prob. 4.1CPCh. 4.1 - Indicate whether each of the following statements...Ch. 4.1 - Prob. 4.3CPCh. 4.1 - What will the following program segment display?...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - Write an if statement that multiplies payRate by...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - TRUE or FALSE: Both of the following if statements...Ch. 4.2 - Write an if statement that performs the following...Ch. 4.2 - Write an if statement that prints The performance...
Ch. 4.2 - Although the following code segments are...Ch. 4.3 - Write an if/else statement that assigns 0.10 to...Ch. 4.3 - Write an if / else statement that assigns 1 to x...Ch. 4.3 - Write an if /else statement that assigns .10 to...Ch. 4.3 - True or false: The following if / else statements...Ch. 4.3 - Will the if / else statement shown on the right...Ch. 4.4 - What will the following program segment display?...Ch. 4.4 - The following program is used in a bookstore to...Ch. 4.4 - Write an if/else if statement that carries out the...Ch. 4.4 - Write an if/else if statement that performs the...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.6 - If you execute the following code, what will it...Ch. 4.7 - Prob. 4.23CPCh. 4.7 - If a = 2, b = 4, and c = 6, indicate whether each...Ch. 4.7 - If a = 2, b = 4, and c = 6, is the following...Ch. 4.7 - Rewrite the following using the ! operator so that...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Write an if statement that prints the message The...Ch. 4.9 - Find and fix the errors in the following code...Ch. 4.10 - Prob. 4.30CPCh. 4.10 - Indicate whether each of the following relational...Ch. 4.10 - Prob. 4.32CPCh. 4.10 - Indicate whether each of these character testing...Ch. 4.11 - Rewrite the following if / else statements as...Ch. 4.11 - Rewrite the following conditional expressions as...Ch. 4.11 - Prob. 4.36CPCh. 4.12 - Explain why you cannot convert the following i...Ch. 4.12 - What is wrong with the following switch statement?...Ch. 4.12 - What will the following program segment display?...Ch. 4.12 - Complete the following program segment by writing...Ch. 4.12 - Rewrite the following program segment using a...Ch. 4.13 - Prob. 4.42CPCh. 4.13 - Follow the instructions to complete the following...Ch. 4 - An expression using the greater-than, less-than,...Ch. 4 - Prob. 2RQECh. 4 - The if statement regards an expression with the...Ch. 4 - For an if statement to conditionally execute a...Ch. 4 - In an if / else statement, the if part executes...Ch. 4 - The trailing else in an if / else if statement has...Ch. 4 - If the subexpression on the left of the logical...Ch. 4 - If the subexpression on the left of the || logical...Ch. 4 - The ____ logical operator has higher precedence...Ch. 4 - Logical operators have _____ precedence than...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - The _____ logical operator works best when testing...Ch. 4 - A variable with _____ scope is only visible when...Ch. 4 - The expression that is tested by a switch...Ch. 4 - A program will fall through to the following case...Ch. 4 - Prob. 16RQECh. 4 - Write an if statement that assigns 100 to x when y...Ch. 4 - Write an if/else statement that assigns 0 to x...Ch. 4 - Write an if / else statement that prints Excellent...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Convert the following conditional expression into...Ch. 4 - Convert the following if/else if statement into a...Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Assume the variables x = 5, y = 6, and z = 8....Ch. 4 - Minimum / Maximum Write a program that asks the...Ch. 4 - Roman Numeral Converter Write a program that asks...Ch. 4 - Magic Dates The date June 10, 1960, is special...Ch. 4 - Areas of Rectangles The area of a rectangle is the...Ch. 4 - Book Club Points An online book club awards points...Ch. 4 - Change for a Dollar Game Create a change -counting...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - Math Tutor Version 2 This is a modification of the...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - Bank Charges A bank charges 15 per month plus the...Ch. 4 - Prob. 11PCCh. 4 - Running the Race Write a program that asks for the...Ch. 4 - Personal Best Write a program that asks for the...Ch. 4 - Body Mass Index Write a program that calculates...Ch. 4 - Fat Gram Calculator Write a program that asks for...Ch. 4 - Prob. 18PCCh. 4 - The Speed of Sound in Gases When traveling through...Ch. 4 - Spectral Analysis If a scientist knows the...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Mobile Service Provider A mobile phone service has...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Further modify the C++ program that you already modified in Practice Program 2. Change the multiplication sign ...
Problem Solving with C++ (9th Edition)
If a member variable is declared ______________, all objects of that class have access to the same variable.
Starting Out with C++ from Control Structures to Objects (9th Edition)
(Game: hangman) Rewrite Programming Exercise 7.35. The program reads the words stored in a text file named hang...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
(Greatest Common Divisor) The greatest common divisor (GCD) of two integers is the largest integer that evenly ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
A __________ structure executes a set of statements only under certain circumstances. a. sequence b. circumstan...
Starting out with Visual C# (4th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Rewrite the following expressions using the conditional operator. (Assume that all variables are declared properly.)a. if (x == y)z = x + y;elsez = (x + y) / 2;b. if (hours >= 40.0)wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);elsewages = hours * 7.50;c. if (loanAmount >= 200000)closingCosts = 10000;elseclosingCosts = 8000;arrow_forwardUsing C++ program 1. ( Use if-else statement ) Write a program for asking for a quiz score. The program then will display a remark if FAILED or PASSED. The passing score is 50. Display also the lacking score points. 2. Why does the following section of code always print "ByeHi" no matter what x is? int x; cin>> x; if x(x < 0); cout<< "Bye"; cout<< "Hi\n"; 3. Write the general form of an if-else statement.arrow_forwardAn Auto Insurance Program Example - Write a program to determine the cost of an automobile insurance premium, based on driver's age and the number of accidents that the driver has had. The basic insurance charge is 500 Rs. There is a surcharge of 100 Rs if the driver is under 25 and there is an additional surcharge for accidents as can be seen below: No. of accidents Accident Surcharge 1 50 2 125 3 250 4 375 5 575 6 or more No insurance Note: Use switch cases when you check the total number of accidents.arrow_forward
- Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has seat belts." If 1990 or later, print "Probably has antilock brakes." If 2000 or later, print "Probably has airbags." End each phrase with a period and a newline.arrow_forwardWrite an if-else statement that works like this: If the sales variable is greater- than or equal-to 50,000, the commissionRate variable should be assigned the value 0.2. Otherwise, the commissionRate variable should be assigned the value 0.1.arrow_forwardIN C LANGUAGE USING LADDERIZED IF-ELSE Create a program that will calculate Body Mass Index (BMI) and will indicate the status of your BMI. Using ladderized if-else. BMI = ([Weight in Pounds) / (Height in inches) x (Height in inches)] x 703 BMI = (Weight in Kilograms) / (Height in meters) x (Height in meters) Your program must accept weight in pounds or kilogram, and height in inches or meters. Formula: 1 ft = 12 inches 1 meter = 39.3701 iches 1 in = 0.0254 m 1 kg = 2.2 lb 1 lb = 0.454 kg BMI Categories: Underweight = <18.5 Normal weight = 18.5 - 24.9 Overweight = 25 - 29.9 Obesity = BMI of 30 or greater Sample Program: Weight (Input 1 for Lb, input 2 for kg): 1 Input weight in Lb: 220 Height (Input 1 for inches, input 2 for meters): 2 Input height in meters: 2 Your BMI is: 24.9 BMI Category: NORMAL WEIGHTarrow_forward
- Using the following chart, write an if-else-if statement that assigns: S, M, L, depending on the weight: Weight Size Up to 120 lb S 120 lb to 175 lb M Over 175 lb Larrow_forwardConvert each if-else statement to a single assignment statement using a conditional expression, using parentheses around the condition. Enter "Not possible" if appropriate. 1) if x < 100: y = 0 else: y = xarrow_forward4. Write an if statement that increases pay by 3% if score is greater than 90, otherwise increases pay by 1%.arrow_forward
- Write if-else if statements that will compare "price" variable with below values and output statements based on the conditions price>=500 : “Extremely Expensive” price>=300 : “Very Expensive” price>=100: “Reasonable price “arrow_forwardthis is c program Write program that ask the user to enter int mark (0-100) for test Physics. Thencategorise the student based on the following grading system. Use else-if and switchstatements.Value output80-100 Gred A; Excellent60-79 Gred B; Very Good.40-59 Gred C;Good.0-39 Gred F;Failarrow_forward1. Write an if statement that assigns 0 to x if y is equal to 20. 2. Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000. In Python Programming, please.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Python Tutorial #10; Math Functions in Python; Author: Art of Engineer;https://www.youtube.com/watch?v=OviXsGf4qmY;License: Standard YouTube License, CC-BY