Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
Complete the following table by writing statements with combined assignment operators in the right-hand column. The statements should be equivalent to the statements in the left-hand column.
A- Correct the errors in each of the following statements:
1- if (age >= 65 );
else;
2- if (age >= 65)
else
3- int x =1; total;
While(x>i>>j;
cout<<"Age is greater than or equal to65" << endl;
cout << "Age is less than 65 << endl";
cout<
3. Convert the following switch statement into
if-else statements then into if-then
statements:
String dayString1, dayString2, dayString3;
int day = KB.nextInt ();
switch (day) {
case 1: dayStringl
case 2: dayString2
"Saturday";
"Sunday";
break;
case 3: dayString3 = "Monday";
break;
case 4: dayStringl = "Tuesday";
case 5: daystring2 = "Wednesday";
break;
default: dayString3 = "Invalid day";
break;
}
4. Write a program that displays the following
pattern:
A
A
A A
BB
AA A
ССС
AA AA
DDDD
AAAΑ
EEEEE
ΑAAAΑΑ
FFFFFF
Chapter 4 Solutions
Starting Out with C++: Early Objects (9th 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 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 26RQECh. 4 - Write a C++ statement that prints the message The...Ch. 4 - Prob. 28RQECh. 4 - Using the following chart, write a C++ statement...Ch. 4 - Write one or more C++ statements that assign the...Ch. 4 - The following statement should determine if x is...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if count...Ch. 4 - The following statement should determine if x has...Ch. 4 - Each of the following program segments has errors....Ch. 4 - Sometimes either a switch statement or an if /else...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 - Color Mixer The colors red, blue, and yellow are...Ch. 4 - Running the Race Write a program that asks for the...Ch. 4 - Personal Best Write a program that asks for the...Ch. 4 - February Days The month of February normally has...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
You want to write a for loop that displays I love to program 50 times. Assume that you will use a control varia...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Determine the magnitude of the resultant force at A. Prob. F2-23
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
This statement can cause other program statements to execute only under certain conditions. 1. Conditional 2. D...
Starting Out With Visual Basic (8th Edition)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th Edition)
The overhang beam is subjected to the uniform distributed load having an intensity of w=50 kN/m. Determine the ...
Mechanics of Materials (10th Edition)
How do functions help you to reuse code in a program?
Starting Out with Python (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
- programming language c++arrow_forwardRewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;arrow_forwardRewrite the following if I el se statements as cond itional expressions .A) if (x > y)z = 1;elsez = 20 ;B) if (temp > 45)popu latio n = base* 10;elsepopu latio n = base* 2 ;C) if (hours > 40)wages*= 1 .5;elsewages *= 1 .' D) if (result >= 0)cout << "The result iselsecout << "The result ispositi ve\n";negat i ve . \n";arrow_forward
- Using c++ write a program : Write a program in C++ to handle the following scenario: Three friends Asif, Shahid and Bashir start the business. Input following from user. Enter amount invested by Asif (user will enter any value) Bashir’s contribution is equal to 250% of Asif’s contribution and Shahid’s contribution is equal to 75% of Bashir’s contribution. Display amount contributed by Bashir and Shahid. After 6 months business earned profit of 50% of total investment. Display the total profit and the amount each sharer will get (i.e. distribute profit as per percentage of their investment).arrow_forwardPROGRAM DESCRIPTION John dela Cruz is interested in knowing how much his interest earning would be after some time. Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as: amount = principal * (1 + rate/m)" interest = amount - principal Principal is the balance in the savings account, rate is the interest rate (0 to 100), m is the number of times the interest is compounded during a year (m is either 1,2,3 or 4 if the interest is compounded quarterly) and nis the number of year., Write a program that asks for the borrower's lastname, borrower's first name, borrower's middle name, civil status (Single, Married, Widow), principal, the interest rate and the number of times the interest is compounded. Follow the format of the report provided in the example. OUTPUT Example 1 Enter the borrower's lastname : Enter the borrower's firstname : Enter the borrower's middle name: Enter civil status : Married Enter the…arrow_forwardWrite aprogram using nestedif statements that perform the following test: If the variable employed is equal to 'Y' and if worklength is equal or greater than 5, then display the message "Your credit card application is accepted". However, if worklength is less than 5, then display the message "Please provide a guarantor". Otherwise, if the variable employed is equal to 'N', then display the message "Your credit card application is rejected". C.arrow_forward
- Rewrite the following conditional expressions as if/else statements. A) j = k > 90 ? 57 : 12;B) factor = x >= 10 ? y * 22 : y * 35;C) total += count == 1 ? sales : count * sales;D) cout << ((num % 2) == 0) ? "Even\n" : "Odd\n");arrow_forwardStudy the following if statement: if x>10 or x<-10: print('big') elif x>1000000: print('very big') elif x<-1000000: print('very big') else : print('small') For what values of x will the above code print 'very big'?arrow_forwardWrite 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_forward
- c++arrow_forwardRewrite the following conditional expressions using if-else statements: a. score = x > 10 ? 3 * scale : 4 * scale;b. tax = income > 10000 ? income * 0.2 : income * 0.17 + 1000;c. cout << (number % 3 == 0 ? i : j) << end1;arrow_forwardPakistan online Daraz company has four agent (1 to 4) who sell 5 different products ( 1 to5). Once per day, each agent passes in a slip for each different type of product sold. Every agentpasses in between 0 to 5 slips each day. Each slip has the following information on it: The agent number The product number Total rupees of that product sold that day.Write a program in C++ that will read all this information for last month’s sales and brief thetotal sales by agent by product. The output should be in tabular form.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Python Tutorial #10; Math Functions in Python; Author: Art of Engineer;https://www.youtube.com/watch?v=OviXsGf4qmY;License: Standard YouTube License, CC-BY