Assume a string object has been defined as follows: string description; A) Write a cin statement that reads in a one word description. B) Write a statement that reads in a description that can contain multiple words separated by blanks.

Short Answer

Expert verified
Answer: To read a one-word description, use the 'cin' statement like this: cin >> description; To read a description with multiple words separated by blanks, use the 'getline' function like this: getline(cin, description);

Step by step solution

01

Part A: Read in a one word description

To read in a one-word description, just use the 'cin' statement as normal. The statement will be: cin >> description;
02

Part B: Read in a description with multiple words separated by blanks

To read in a description containing multiple words separated by blanks, you need to use the 'getline' function, which can handle multiple words separated by a specified delimiter. The statement will be: getline(cin, description);

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

inc… # Trace the following programs and tell what each will display. (Some require a calculator.) A) \(\text {(Assume the user enters } 38711 \text {. Use a calculator.})\) # include { iostream } using namespace std; int main ( ) \\{ double salary, monthly; cout \(<<\) "What is your annual salary? " \(\operatorname{cin} \quad>>\operatorname{salar} y\) month1y \(=\) static cast \(\langle\text { int }>(\text { salary ) } / 12\) cout \(<<\) "Your monthly wages are " \(<<\) monthly \(<<\) end1 return 0 B) #include using namespace std; int main () \\{ \\[ \begin{array}{l} \log g \quad x, \quad y, \quad z ; \\ x=y=z=4 \\ x+=2 \\ y-=1 ; \\ z \quad x=3 ; \\ \operatorname{cout}< using namespace std; # define WHO "Columbus" # define DID "sailed" #define WHAT "the ocean blue." int main () \\{ const int WHEN = 1492 cout \(<<\) "In \("<<\) WHEN \(<<\) " \("<<\) WHO \(<<\) " \\[ <

Complete the following table by writing statements with combined assignment operators in the right-hand column. The statements should be equivalent to the statements in the left-hand column.

Little Italy Pizza charges \(\$ 12.00\) for a 12 -inch diameter sausage pizza and \(\$ 14.00\) for a 14 -inch diameter sausage pizza. Write the pseudocode algorithm that calculates and displays how much each of these earns the establishment per square inch of pizza sold. (Hint: you will need to first calculate how many square inches there are in each pizza.)

Write a definition statement for a character array large enough to hold any of the following strings: "Billy Bob's Pizza" "Downtown Auto Supplies" "Betty Smith School of Architecture" "ABC Cabinet Company"

Write a cout statement so the variable profit is displayed in a field of 12 spaces, in fixed-point notation, with a decimal point and four decimal digits.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free