Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4.6, Problem 4.16CP
What will the following code display?
int funny = 7, serious = 15;
funny = serious % 2;
if (funny != 1)
{
funny = 0;
serious = 0;
}
else if (funny == 2)
{
funny = 10;
serious = 10;
}
else
{
funny = 1;
serious = 1;
}
cout << funny << “” << serious << endl;
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule06:44
Students have asked these similar questions
case 3: res=31;break;
case 4: res=30;break;
case 5: res=31;break;
case 6: res=30;break;
case 7: res=31;break;
case
#include int days_in_month(int month,int is_leap){ int res=-1; switch(month) { case 1: res-31;break; case 2: if(is_leap) res=29; else
res=28;break;
8: res=31;break; case 9: res=30;break; case 10: res=31;break;
int m,1; printf("Enter month: "); scanf("%d",&m); printf("Enter
printf("Days %d",days);} Write in c
case 11: res=30;break; case 12: res=31;break; } return res;} int main() {
1 for leap year 0 for non leap: "); scanf("%d",&l); int days-days_in_month(m,1);
case 3: res=31;break;
case 4: res=30;break;
case 5: res=31;break;
#include int days_in_month(int month,int is_leap){ int res=-1; switch(month) { case 1: res=31;break; case 2: if(is_leap) res=29; else
res=28;break;
case 6: res=30;break; case 7: res=31;break; case
case 11: res=30;break; case 12: res=31;break; } return res;} int main() {
int m,l; printf("Enter month: "); scanf("%d",&m); printf("Enter 1 for leap year 0 for non leap: "); scanf("%d",&l); int days-days_in_month(m,1);
printf("Days %d",days);} Write in c
8: res=31;break; case 9: res=30;break; case 10: res=31;break;
C ++
Using the following code:
enum GradeLevel { FRESHMAN, SOPHMORE, JUNIOR, SENIOR };
struct Student
{
string first;
string middle;
string last;
GradeLevel year;
float GPA;
};
Student A0012; // Student ID A0012
Student A0013; // Student ID A0013
A0012.first = "Bjarne";
A0012.last = "Stroustrup";
A0012.GPA = 3.56;
A0013 = A0012;
A0012.year = SENIOR;
A0013.middle = "C++";
A0013.year = static_cast<GradeLevels>(A0012.year - 2);
A0013.GPA = floor(A0012.GPA); // floor() rounds down to whole number
A0012.middle = A0013.middle.at(0) + ".";
What are the contents of the Student variables after this code has executed? Use the chart provided. Who is Bjarne Stroustrup?
Chapter 4 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 4.1 - Prob. 4.1CPCh. 4.1 - Indicate whether the following statements about...Ch. 4.1 - Prob. 4.3CPCh. 4.1 - Prob. 4.4CPCh. 4.2 - Write an if statement that performs the following...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 - True or False: Both of the following i f...Ch. 4.2 - True or false: Both of the following if statements...Ch. 4.3 - Write an if statement that performs the following...
Ch. 4.3 - The following code segment is syntactically...Ch. 4.4 - True or false: The following if/else statements...Ch. 4.4 - Write an if/else statement that assigns 1 to x if...Ch. 4.4 - Write an if/else statement that assigns 0.10 to...Ch. 4.5 - If you executed the following code, what would it...Ch. 4.6 - What will the following code display? int funny =...Ch. 4.6 - The following code is used in a bookstore program...Ch. 4.9 - Prob. 4.18CPCh. 4.9 - Assume the variables a = 2, b = 4, and c = 6....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.12 - Prob. 4.22CPCh. 4.12 - Indicate whether each of the following relational...Ch. 4.13 - Rewrite the following if/else statements as...Ch. 4.13 - The following statements use conditional...Ch. 4.13 - Prob. 4.26CPCh. 4.14 - Explain why you cannot convert the following if...Ch. 4.14 - What is wrong with the following switch statement?...Ch. 4.14 - What will the following program display? #include...Ch. 4.14 - Complete the following program skeleton by writing...Ch. 4.14 - Rewrite the following program. Use a switch...Ch. 4 - Describe the difference between the if /else if...Ch. 4 - In an if/else if statement, what is the purpose of...Ch. 4 - What is a flag and how does it work?Ch. 4 - Can an if statement test expressions other than...Ch. 4 - Briefly describe how the operator works.Ch. 4 - Briefly describe how the | | operator works.Ch. 4 - Why are the relational operators called...Ch. 4 - Why do most programmers indent the conditionally...Ch. 4 - An expression using the greater-than, less-than,...Ch. 4 - A relational expression is either ______ or...Ch. 4 - Prob. 11RQECh. 4 - The if statement regards an expression with the...Ch. 4 - The if statement regards an expression with a...Ch. 4 - For an if statement to conditionally execute a...Ch. 4 - In an if/else statement, the if part executes its...Ch. 4 - The trailing else in an if/else if statement has a...Ch. 4 - The if/else if statement is actually a form of the...Ch. 4 - If the subexpression on the left of the _________...Ch. 4 - If the subexpression on the left of the __________...Ch. 4 - The ________ logical operator has higher...Ch. 4 - The logical operators have _________...Ch. 4 - The _________ logical operator works best when...Ch. 4 - The __________ logical operator works best when...Ch. 4 - A variable with _________ scope is only visible...Ch. 4 - Prob. 25RQECh. 4 - An expression using the conditional operator is...Ch. 4 - The expression that is tested by a switch...Ch. 4 - Prob. 28RQECh. 4 - A program will fall through a case section if it...Ch. 4 - What value will be stored in the variable t after...Ch. 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 - Using the following chart, write an if/else if...Ch. 4 - Write an if statement that sets the variable hours...Ch. 4 - Write nested if statements that perform the...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Write an if statement that prints the message The...Ch. 4 - Assume str1 and str2 are string objects that have...Ch. 4 - Convert the following if/else if statement into a...Ch. 4 - Match the conditional expression with the if /else...Ch. 4 - T F The = operator and the == operator perform the...Ch. 4 - Prob. 43RQECh. 4 - T F A conditionally executed statement should be...Ch. 4 - T F All lines in a block should be indented one...Ch. 4 - T F Its safe to assume that all uninitialized...Ch. 4 - T F When an if statement is nested in the if part...Ch. 4 - T F When an if statement is nested in the el se...Ch. 4 - T F The scope of a variable is limited to the...Ch. 4 - T F You can use the relational operators to...Ch. 4 - T F x ! = y is the same as (x y || x y)Ch. 4 - T F y x is the same as x = yCh. 4 - T F x = y is the same as (x y x = y)Ch. 4 - T F x == 5 || y 3Ch. 4 - T F 7 = x z 4Ch. 4 - T F 2 != y z != 4Ch. 4 - T F x = 0 || x = yCh. 4 - Each of the following programs has errors. Find as...Ch. 4 - // This program divides a user-supplied number by...Ch. 4 - // This program uses an if/else if statement to...Ch. 4 - // This program uses a switch-case statement to...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 assign 0 to z if a...Ch. 4 - Minimum/Maximum Write a program that asks the user...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 - Body Mass Index Write a program that calculates...Ch. 4 - Mass and Weight Scientists measure an objects mass...Ch. 4 - Time Calculator Write a program that asks the user...Ch. 4 - Color Mixer The colors red, blue, and yellow are...Ch. 4 - Change for a Dollar Game Create a change-counting...Ch. 4 - Days in a Month Write a program that asks the user...Ch. 4 - Math Tutor This is a modification of Programming...Ch. 4 - Software Sales A software company sells a package...Ch. 4 - Book Club Points Serendipity Booksellers has a...Ch. 4 - Bank Charges A bank charges 10 per month plus the...Ch. 4 - Shipping Charges The Fast Freight Shipping Company...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 - Fat Gram Calculator Write a program that asks for...Ch. 4 - Spectral Analysis If a scientist knows the...Ch. 4 - Prob. 20PCCh. 4 - The Speed of Sound in Gases When sound travels...Ch. 4 - Freezing and Boiling Points The following table...Ch. 4 - Prob. 23PCCh. 4 - Long-Distance Calls A long-distance carrier...Ch. 4 - Mobile Service Provider A mobile phone service...Ch. 4 - Mobile Service Provider, Part 2 Modify the Program...Ch. 4 - Wi-Fi Diagnostic Tree Figure 4-11 shows a...Ch. 4 - Restaurant Selector You have a group of friends...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Words that have predefined meaning in a programming language are called _____ .
Starting Out With Visual Basic (8th Edition)
For the circuit shown, find (a) the voltage υ, (b) the power delivered to the circuit by the current source, an...
Electric Circuits. (11th Edition)
(True or False) If is the length of str, then is the string consisting of the last character of str.
Introduction To Programming Using Visual Basic (11th Edition)
What is attrition in an abrasive grit?
Degarmo's Materials And Processes In Manufacturing
File Decryption Filter Write a program that decrypts the file produced by the program in Programming Challenge ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (8th 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
- QUESTION 21 int x1=200; int y1=3003; int z1, z2, z3, z4; int d1, d2, d3; _asm{ mov EAX, x1; 200 mov EBX, y1; 300 mov z1, ESP; assume initial ESP: OFFF FFEA add EAX, x1; 400 push EAX; mov d1, EAX:400 mov z2, ESP; push EBX; SUB EBX, x1; 300-200=100 mov d2, EBX; mov 23, ESP; POP ECX; MOV d3, ECX; MOV z4, ESP; POP EDX; mov d4, EDX; What is z3 in Hexidecimal? O OFFF FFEA O OFFF FFE6 OFFF FFE2 OFFF FFEEarrow_forwardDeclare three structs: Struct TravelInfo{ String name; Double weight; Double newWeight; Int planetChoice; Int speed; }; Struct TravelTimeCalc{ Int totalTravelTime; Int years; Int days; Int hours; }; Struct Planet{ String planetNames; Double distanceFromSun; Double gravity; }; Planets, distance from sun(millions of miles), surface gravity as a percent of earth’s gravity: Mercury 36 0.27 Venus 67 0.86 Earth 93 1.00 Mars 141 0.37 Jupiter 483 2.64 Saturn 886 1.17 Uranus 1782 0.92 Neptune 2793 1.44 Pass the arrays to the FillPlanetInfo function that will load the data into the three arrays. Start a do while loop in main Pass the function AskSpaceTravellerInfo a reference to the TravelerInfo struct variable and the array of planet names. Get the user’s name, Earth weight, the speed they want to travel and the planet they wish to visit. Provide a menu with the planet names and a way for the user to select the chosen destination. Pass the data you obtained…arrow_forwardMicrosoft C# 2019, 7th edition Here's my code help. using System; using static System.Console; using System.Globalization; class MarshallsRevenue { static void Main() { const int INTERIOR_PRICE = 500; const int EXTERIOR_PRICE = 750; string entryString; int numInterior; int numExterior; int revenueInterior; int revenueExterior; int total; bool isInteriorGreater; bool valid; valid = true; int monthnumber; int interiorRate; int exteriorRate; interiorRate = INTERIOR_PRICE; exteriorRate = EXTERIOR_PRICE; Console.Write("Enter number of month being scheduled 1-12 >> "); entryString = Console.ReadLine(); monthnumber = Convert.ToInt32(entryString); while ((monthnumber < 1) || (monthnumber > 12)) { Console.WriteLine("Invalid"); Console.Write("Enter number of month being scheduled 1-12…arrow_forward
- Sea A={luna); B={planetas del sistema solar};C={Marte, Júpiter};D={Mercurio, Venus, Tierra): encontrar CUD =arrow_forwardC# problem when printing Weigh no value shows up code public class HealthProfile{private String _FirstName;private String _LastName;private int _BirthYear;private double _Height;private double _Weigth;private int _CurrentYear;public HealthProfile(string firstName, string lastName, int birthYear, double height, double weigth, int currentYear){_FirstName = firstName;_LastName = lastName;_BirthYear = birthYear;_Height = height;_Weigth = weight;_CurrentYear = currentYear;}public string firstName { get; set; }public string lastName { get; set; }public int birthYear { get; set; }public int height { get; set; }public double weight { get; set; }public int currentYear { get; set; }public int Person_Age{get { return _CurrentYear - _BirthYear; }}public double Height{get { return _Height; }}public double Weight{get { return Weight; }}public int Max_Heart_Rate{get { return 220 - Person_Age; }}public double Min_Target_Heart_Rate{get { return Max_Heart_Rate * 0.65; }}public double…arrow_forward} BMI(struct Person* person) { person->BMI = person->weight / (person->height person->height); return person->BMI; } //Q10: Why is the return type char*? char* determineWeightCategory(struct Person* person) {//assumes BMI is known const double UNDERWEIGHT = 18.5; const double NORMALWEIGHT = 24.9; const double OVERWEIGHT = 29.9; } else { //Q11: If the value in person->BMI is equal to 18.5 and person is athletic, what will be //stored in p- //Q12: The first if statement validates against certain conditions. //What are the conditions it is validating against? //HINT: Think about what causes BMI to be less than 0. if (person->BMI weightCategory, "ERROR"); } else if (person->BMI weightCategory, "Underweight"); } else if (person->BMI weightCategory, "Normalweight"); } else if (person->BMI weightCategory, "Overweight"); strcpy(person->weightCategory, "Obese"); return person->weightCategory; //Q13: Why do we return person->weightCategory? } //Q14: Why is provider passed by value?arrow_forward
- The following declaration, program, and program segment has errors. Locate as many as you can. class Circle: { private double centerX; double centerY; double radius; public setCenter(double, double); setRadius(double);}arrow_forwardpublic Account (double initialBalance){balance = initialBalance;}public Account () {balance = 0;}public void deposit (double amount){balance += amount; // Balance = balance + amount}public void withdraw (double amount){balance -= amount; // balance = balance - amount}public void close (){balance = 0;}public String toString(){return "balance: " + balance;}} Modify the Account class by adding two instance variables containing the customer's name and the account number. Both will be String objects. Modify the primary constructor for the Account class so that it takes three parameters: the balance, the customer's name, and the account number. Add instance methods named getCustomerName and getAccountNumber that return the customer name and account number.arrow_forwardA Car structure is declared as follows: struct Car { string make, model; int year; double cost; Car(string mk, string md, int y, double c) { make = mk; model = md; year = y; cost = c; }};Write a definition statement that defines a Car structure variable initialized with the following information:Make: Ford Year: 2010Model: Mustang Cost: $22,495arrow_forward
- class Lease{ private String name; private int aptNumber; private double rent; private int term; private static final int FEE = 10; public Lease(){ name = "XXX"; aptNumber = 0; rent = 1000; term = 12; } public void setName(String tenant) { name = tenant; } public void setAptNumber(int apt){ aptNumber = apt; } public void setRent(double monthRent) { rent = monthRent; } public void setTerm(int t){ term = t; } public String getName(){ return name; } public int getAptNumber(){ return aptNumber; } public double getRent(){ return rent; } public int getTerm(){ return term; } public void addPetFee(){ rent = rent + FEE; } } Create a class named TestLease as instructed below: Instantiate four Lease objects in the main()method. Change the aptNumber value for the first object to 20 Change the rent value…arrow_forwardC++arrow_forwardMicrosoft Visual C#7th Edition, Joyce ISBN: 9781337102100 chap 5 case problem 5-2. This is my code but it's not working in Cenage Mindtap. What did I do wrong, please? Thank you using System; using static System.Console; using System.Globalization; class MarshallsRevenue { static void Main() { const int INTERIOR_PRICE = 500; const int EXTERIOR_PRICE = 750; string entryString; int numInterior; int numExterior; int revenueInterior; int revenueExterior; int total; bool isInteriorGreater; bool valid; valid = true; int monthnumber; int interiorRate; int exteriorRate; interiorRate = INTERIOR_PRICE; exteriorRate = EXTERIOR_PRICE; Write("Enter number of month being scheduled 1-12 >> "); entryString = ReadLine(); monthnumber = Convert.ToInt32(entryString); while ((monthnumber < 1) || (monthnumber > 12)) {…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY