Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134443829
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.14, Problem 4.29CP
What will the following
#include <iostream>
using namespace std;
int main()
{
int funny = 7, serious = 15;
funny = serious * 2;
switch(funny)
{
case 0: cout << “That is funny.\n”
break;
case 30: cout << “That is serious.\n”
break;
case 32: cout << “That is seriously fun.\n”
break;
default: cout << funny << endl;
}
return 0;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++ programming
2. What is the output of the following program (when embedded in a complete program)?
void Fun( int& x, int y, int& z);
int main( )
{
int a, b, c;
a = 10;
b = 20;
c = 30;
Fun(a, b, c);
cout << a << " " << b << " " << c << endl;
return 0;
}
void Fun( int& x, int y, int& z)
{
cout << x << " " << y << " " << z << endl;
x = 1;
y = 2;
z = 3;
}
C++: Describe how the following call by reference works. Make a comment for each line.
void pxc(int& c, int& d)
{
int k = c;
c = d;
d = k;
}
int main()
{
int a = 15, b = 100;
pxc(a, b);
}
struct date{
int day;
int month;
int year;
};
Write a function named void increaseDay(struct date *d) that increases the value of a variable of struct date type with integer year, month, and day members by one day.
Write a function named void decreaseDay(struct date *d) that decreases the value of a variable of struct date type with integer year, month, and day members by one day.
Write a C program that reads from the user a date in d/m/y format and the amount of increase or decrease as an integer. Display the new date in d/m/y format. You may call related functions as many as given increase or decrease value.
Note 1: You do not need to consider leap years. Use always 28 days for month February.
Note 2: Do not modify the function prototypes.
Sample Input1:
Sample Output1:
12/8/1990 -5
7/8/1990
Sample Input2:
Sample Output2:
26/2/2005 5
3/3/2005
Sample Input3:
Sample Output3:
29/12/1998 7
5/1/1999…
Chapter 4 Solutions
Starting Out with C++ from Control Structures to Objects, Student Value Edition (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...
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
- Need help with a c++ building block question! Nongraded Implement the copy assignment operator= for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. It is possible to get the test case correct but not complete NOTE: Be careful! There are decoys! The this pointer is used extensively.. Assume that StringVar.h has the following declaration: #include <iostream> class StringVar {public:StringVar() : max_length(20) { // Default constructor size is 20value = new char[max_length+1];value[0] = '\0';}StringVar(int size); // Takes an int for sizeStringVar(const char cstr[]); // Takes a c-string and copies itStringVar(const StringVar& strObj); // Copy Constructor~StringVar(); // Destructorint size() const { return max_length; } // Access capacityconst char* c_str() const { return value; } // Access valueint length() const { return strlen(value); } // Access lengthStringVar& operator= (const StringVar&…arrow_forwardIf the new operator cannot allocate the amount of memory requested, it throws_____________arrow_forwardC++ Please! Also please don't use functions, arrays, or classes. Just basic c++ please. Password Verifier Write a C++ program to verify that a user’s password meets the following criteria: 1. The password should be at least 6 characters long. 2. The password should contain at least one uppercase and one lowercase letter. 3. The password should have at least one digit. Your program should ask the user for a password and verify that it meets the following criteria. If it doesn’t a message should be displayed telling the user why.arrow_forward
- In C++ use if-else blocks and play loop for this program Number Text Color Number Text Color0 Black 8 Bright Black1 Blue 9 Bright Blue2 Green 10 Bright Green3 Cyan 11 Bright Cyan4 Red 12 Bright Red5 Purple 13 Bright Purple6 Yellow 14 Bright Yellow7 White 15 Bright White Write a C++ program that asks the user to select a color and a shape to draw. In main, begin by declaring variables and displaying the class header, and cout an explanation of the program. You may include this in your header or make it separate. You will need constants for the maximum color number and for the maximum picture number as well as a value that indicates the user has finished drawing. These will look like://Constantsconst int…arrow_forward.c## Write a Console Application that reads two integers, determines whether the first is a multiple of the second and displays the result. [Hint: Use the remainder operator.]arrow_forwardQuestion 3 Write a program in C, which simulates the game of connect 4, representing the board with coloured tiles, by means of matrices, where the player can choose whether to play with the computer and the computer represents player 2 or with another person, where at the end it shows the winner, the loser or if there was a draw. . Full explain this question very fast solution sent mearrow_forward
- Given the declaration:char myStr[26];char yourStr[26] = "Arrays and Strings";a. Write a C++ statement that stores "Summer Vacation" in myStr.b. Write a C++ statement that outputs the length of yourStr.c. Write a C++ statement that copies the value of yourStr into myStr.d. Write a C++ statement that compares myStr with yourStr and stores the result into an int variable compare.arrow_forwardIn C++ what is the effect of the const keyword in the following statement? int* const intPtr = new intarrow_forward2.6.2: Bool in branching statements. C++ please. I am not sure why I cannot get the second one to work Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" if isBalloon and isRed are both true. Print "Not a balloon" otherwise. End with newline. #include <iostream>using namespace std; int main() { bool isRed; bool isBalloon; cin >> isRed; cin >> isBalloon; isBalloon = (isRed && isBalloon); if (!isRed && isBalloon) { cout << "Balloon" << endl; } else if (isRed && isBalloon) { cout << "Red balloon" << endl; } else { cout << "Not a balloon" << endl; } return 0;} Not all tests passed checkTesting isBalloon = false, isRed = false Your output Not a balloon clearTesting isBalloon = true, isRed = false Output differs. See highlights below. Special…arrow_forward
- Anagram words Write a C code that asks users to enter two words, one after the other and checks if these words are anagrams (permutations of the same letters). For instance, the words “smartest” and “mattress” are anagrams. Examplea Run 1: Please enter first word: lookplease enter the second word: coolSorry! “cool” and “look” are not anagrams. Run 2: Please enter first word: masters please enter the second word: smartes Yes! “masters” and “smartes” are anagrams. Hint: If you sort the two words that are anagrams, they will become identical! For instance, “smartest” and “masters” both sort to “aemrsstt” You can use all functions in <string.h> Sorting a string is exactly similar to sorting an array. You just need to know the length of the string and make sure you do not touch the terminating null.arrow_forwardC# If the call to the following code was: Console.WriteLine(MysterySub(13,4,2)); Trace through the following code by sight (not putting it into a program). What would be displayed on the screen? private int MysterySub(int a, int b, int c) { if (a < 3) { return b; } else { return c + MysterySub(a-2, b, c); } }arrow_forwardVisual Studio 2019 how to loop this code in c# 8.0 using System; namespace ConsoleApp1{class Program{static void Main(string[] args){double cm, meter, kilometer, mili;//primero se declaran las variablesConsole.WriteLine("Introduzca los kilómetros");kilometer = Convert.ToInt32(Console.ReadLine());Console.WriteLine("Introduzca los metros");meter = Convert.ToInt32(Console.ReadLine());Console.WriteLine("Introduzca los centimetros");cm = Convert.ToInt32(Console.ReadLine());Console.WriteLine("Introduzca los milímetros");mili = Convert.ToInt32(Console.ReadLine());Console.WriteLine("Seleccione una opción");Console.WriteLine("\ta-Conversion de kilometros a: ");Console.WriteLine("\tb-Conversion de metros a: ");Console.WriteLine("\tc-Conversion de centimetros a: ");Console.WriteLine("\td-Conversion de milimetros a: ");Console.Write("¿Tú opción? ");switch (Console.ReadLine()){case "a":Console.WriteLine("kilómetro a metro:" + (meter = kilometer * 1000.0));Console.WriteLine("kilómetro a…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License