0
8,620 answers
1a. Write what the following statements display as output after the program executes.
int temperature = 78;
int month = 6;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6) //temperature greater than or equal to 70 condition satisfies. month >= 6 also satisfies.
cout << "Wear white shoes.\n"; //So, this statement will be executed.
else if (name == "Pat Boone")
cout << "Wear white shoes.\n";
else
cout << "Wear black shoes.\n";
So, the output of the above code is: Wear white shoes.
1b. What is the output of the program in Exercise 1a when temperature = 70, month = 5, and name = “Pat Boone”?
int temperature = 70;
int month = 5;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6) //temperature greater than or equal to 70 condition satisfies. month >= 6 condition fails.
cout << "Wear white shoes.\n";
else if (name == "Pat Boone") //name == Pat Boone condition satisfies.
cout << "Wear white shoes.\n"; //So, this statement will be executed.
else
cout << "Wear black shoes.\n";
So, the output of the above code is: Wear white shoes.
1c. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Pat Boone”?
int temperature = 60;
int month = 5;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6) //temperature greater than or equal to 70 condition fails.
cout << "Wear white shoes.\n";
else if (name == "Pat Boone") //name == Pat Boone condition satisfies.
cout << "Wear white shoes.\n"; //So, this statement will be executed.
else
cout << "Wear black shoes.\n";
So, the output of the above code is: Wear white shoes.
1d. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Your name”?
int temperature = 60;
int month = 5;
string name = "Hershley";
if ( temperature >= 70 && month >=6) //temperature greater than or equal to 70 condition fails.
cout << "Wear white shoes.\n";
else if (name == "Pat Boone") //name == Pat Boone condition also fails.
cout << "Wear white shoes.\n";
else
cout << "Wear black shoes.\n"; //So obviously, this statement will be executed.
So, the output of the above code is: Wear black shoes.
Comment