Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.13, Problem 4.43CP
Follow the instructions to complete the following
enum Paint { red, blue, yellow, green, orange, purple };
Paint color = green;
// Write an if/else statement that will print out "primary color"
// if color is red, blue, or yellow, and will print out
// "mixed color" otherwise. The if test should use a relational
// expression.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Rewrite the following expressions using an if . . . else statement. (Assume that all variables are declared properly.)a. (overSpeed > 10) ? fine = 200 : fine = 75;b. (fuel >= 10) ? drive = 150 : drive = 30;c. (bill >= 50.00) ? tip = 0.20 : tip = 0.10;
Answer the following question. TRUE OR FALSE.
1. In if…else
If the test expression is evaluated to true, statements inside the body of if are executed. Statements inside the body of else are skipped from execution.
2. The if…else ladder allows you to check between multiple test expression and execute different statements.
Evaluate the following logical expressions and answer if it's True or False, whereX=True, Y= false, Z= Falsea) Z|| (X && (Y||Z))b) !Y || (Z || !X)
Chapter 4 Solutions
Starting Out With C++: Early Objects, Student Value Edition (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
In an inheritance relationship, the _________ is the specialized class. a. superclass b. master class c. subcla...
Starting Out with Python (3rd Edition)
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (8th Edition)
When a program works with an input file, a special value known as a(n) __________ is internally maintained for ...
Starting out with Visual C# (4th Edition)
Practice Problem 11.3 (solution page 967) Write a program dd2hex.c that converts its dotted-decimal argument to...
Computer Systems: A Programmer's Perspective (3rd Edition)
(Displaying a Square of Asterisks) Write a method squareOfAsterisks that displays a solid square (the same numb...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
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
- What logical operator you will use so that the statements will be performed, if you have atleast one evaluated condition is TRUE? Select one: a. && b. ! c. || d. all of the choices Determine the output of the given program code #include<stdio.h>#include<conio.h> void main(){int sample[5]={1,2,3,4,5};int x,y;x=sample[1];y=sample[x];printf(“The number is %d”,y);getch();} Select one: a. 3 b. 2 c. 4 d. none of the choicesarrow_forwardWrite programs to evaluate the following expressions. The user should enter the variables, and the program should print back an answer. Prompt the user for all variables in the expression, and print the results in a meaningful manner. The results should be as accurate as possible.a) 5x + 3y +zb) ((5x + 3y + z) / 2) * 3arrow_forwardWhat is the output of the following statements? a. if ('+' < '-')cout << "+-";cout << "-+" << endl;b. if (12 / 2 == 4 + 1)cout << "6 ";cout << "12 / 2 != 4 + 1" << endl;c. if ('*' >= '/')cout << "/";cout << "*";cout << endl;d. if ("C++" <= "++C")cout << "C++" << endl;cout << "C++" << endl;e. if ("low" <= "high")cout << "low" << endl;cout << "high" << endl;arrow_forward
- PYTHON-Write multiple if statements: If car_year is before 1968, print "Probably has few safety features." (without quotes). If after 1969, print "Probably has seat belts.". If after 1992, print "Probably has anti-lock brakes.". If after 2001, print "Probably has airbags.". End each phrase with period and newline. Remember that print() automatically adds a newline. Ex: car_year = 1995 prints: Probably has seat belts. Probably has anti-lock brakes.arrow_forwardWrite multiple if statements: If car_year is before 1967, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has seat belts.". If after 1991, print "Probably has electronic stability control.". If after 2002, print "Probably has tire-pressure monitor.". End each phrase with period and newline. Remember that print() automatically adds a newline. Ex: car_year = 1995 prints:arrow_forwardWrite nested if statements that perform the following test : If amount1 is greater than 10 and amount 2 is less than 100, display the greater of the twoarrow_forward
- For each of the following questions, write ONLY what is requested. a. Write a statement(s) that prompts for and reads in a temperature. b. Write a statement(s) that displays a 7 × 7 square of asterisks. c. State the rule for identifiers (the naming rule). d. Given that an int variable s has been initialized, write a statement(s) that declares a new variable andassign it the remainder of 9 times 8 less than s divided by 4. e. Write a statement(s) that initializes the variables named a, b, c and d to false, ''one'', 'y' and 87.9respectivelyarrow_forwardA. Rewrite the following program using switch statement:int main(){int testScore; // Holds a numeric test scorechar grade; // Holds a letter gradecout << "Enter your test score and I will tell you\n";cout << "the letter grade you earned: ";cin >> testScore;if (testScore = = 60)grade = 'F';if (testScore = = 70)grade = 'D';if (testScore = = 80)grade = 'C';if (testScore = = 90)grade = 'B';if (testScore = = 100)grade = 'A';cout << "Your grade is " << grade << ".\n";return 0;} B. Rewrite the following code, replacing the do-while loop with a while loop. When you do this you will no longer need an if statement. int number;cout << "Enter an even number: ";do{ cin >> number;if (number % 2 != 0)cout << "Number must be even. Reenter number: ";} while (number % 2 != 0); C. Given an array definition as follows, write the codes which will determine the highest value.const int SIZE = 10;int numbers[SIZE] = {15, 6, 3, 11, 22, 4, 0, 1, 9, 12}; D.…arrow_forwardSuppose that classStanding is a char variable, gpa and dues are double variables. Write a switch expression that assigns the dues as following: If classStanding is 'f', the dues are $150.00; if classStanding is 's', (if gpa is at least 3.75, the dues are $75.00; otherwise dues are 120.00); if classStanding is 'j', (if gpa is at least 3.75, the dues are $50.00; otherwise dues are $100.00); if classStanding is 'n', (if gpa is at least 3.75, the dues are $25.00; otherwise dues are $75.00). (Note that the code 'f' stands for first year students, the code 's' stands for second year students, the code 'j' stands for juniors, and the code 'n' stands for seniors.)arrow_forward
- Show the value of x after each of the following statements is performed:a) x = fabs(7.5);b) x = floor(7.5);c) x = fabs(0.0);d) x = ceil(0.0);e) x = fabs(-6.4);f) x = ceil(-6.4);g) x = ceil(-fabs(-8 + floor(-5.5)));arrow_forwardGiven: If A AND B, then C. Given: The if-then statement's reverse isalso correct. If A is True, B is True, what is C? Forward and reverse / Forward and reverse False True Not True or Falsearrow_forwardAnswer the following question TRUE or False 1. The condition is evaluated first before executing any statement inside the body of If. 2. The statements inside the body of “if” only execute if the given condition returns true. 3. If statement is always used with a conditionarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Control Structure in Data Structure - Data Structures - Computer Science Class 12; Author: Ekeeda;https://www.youtube.com/watch?v=9FTw2pXLhv4;License: Standard YouTube License, CC-BY