
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
النسخة 8الرقم المعياري الدولي: 978-1285867410
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
النسخة 8الرقم المعياري الدولي: 978-1285867410 تمرين 7
Making Multiple Comparisons in Decision Statements
In this exercise, you use what you have learned about OR logic to study a complete C++ program that uses OR logic in a decision statement. This program was written for a marketing research firm that wants to determine if a customer prefers Coke or Pepsi over some other drink. Take a few minutes to study the code that follows, and then answer Questions.
// CokeOrPepsi.cpp - This program determines if a customer// prefers to drink Coke or Pepsi or some other drink.#include #include using namespace std;int main(){string customerFirstName; // Customer's first namestring customerLastName; // Customer's last namestring drink = ""; // Customer's favorite drinkcout ? "Enter customer's first name: ";cin ? customerFirstName;cout ? "Enter customer's last name: ";cin ? customerLastName;cout ? "Enter customer's drink preference: ";cin ? drink;if(drink == "Coke" || drink == "Pepsi"){cout ? "Customer First Name: " ? customerFirstName? endl;cout ? "Customer Last Name: " ? customerLastName? endl;cout ? "Drink: " ? drink ? endl;}elsecout ? customerFirstName ? " " ? customerLastName? " does not prefer Coke or Pepsi." ? endl;return 0;}
What is the exact output when this program executes if the customer's name is Chas Matson and the drink is Pepsi?
In this exercise, you use what you have learned about OR logic to study a complete C++ program that uses OR logic in a decision statement. This program was written for a marketing research firm that wants to determine if a customer prefers Coke or Pepsi over some other drink. Take a few minutes to study the code that follows, and then answer Questions.
// CokeOrPepsi.cpp - This program determines if a customer// prefers to drink Coke or Pepsi or some other drink.#include #include using namespace std;int main(){string customerFirstName; // Customer's first namestring customerLastName; // Customer's last namestring drink = ""; // Customer's favorite drinkcout ? "Enter customer's first name: ";cin ? customerFirstName;cout ? "Enter customer's last name: ";cin ? customerLastName;cout ? "Enter customer's drink preference: ";cin ? drink;if(drink == "Coke" || drink == "Pepsi"){cout ? "Customer First Name: " ? customerFirstName? endl;cout ? "Customer Last Name: " ? customerLastName? endl;cout ? "Drink: " ? drink ? endl;}elsecout ? customerFirstName ? " " ? customerLastName? " does not prefer Coke or Pepsi." ? endl;return 0;}
What is the exact output when this program executes if the customer's name is Chas Matson and the drink is Pepsi?
التوضيح
OR Logic ( || ):
The OR Logic (||) help...
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
لماذا لم يعجبك هذا التمرين؟
أخرى 8 أحرف كحد أدنى و 255 حرفاً كحد أقصى
حرف 255