Task: 5 Working with Characters and StringsExercise 1: Retrieve program stringchar.cpp from the Lab 2 folder. Thisprogram illustrates the use of characters and strings. The char data typeallows only one character to be stored in its memory location. The stringdata type (actually a class and not a true data type built into the language)allows a sequence of characters to be stored in one memory location. Thecode follows: // This program demonstrates the use of characters and strings// PLACE YOUR NAME HERE#include <iostream>#include <string>using namespace std;// Definition of constantsconst string FAVORITESODA = "Dr. Dolittle"; // use double quotes for stringsconst char BESTRATING = 'A'; // use single quotes for charactersint main(){ char rating; // 2nd highest product ratingstring favoriteSnack; // most preferred snackint numberOfPeople; // the number of people in the surveyint topChoiceTotal; // the number of people who prefer the top choice// Fill in the code to do the following:// Assign the value of "crackers" to favoriteSnack// Assign a grade of 'B' to rating// Assign the number 250 to the numberOfPeople// Assign the number 148 to the topChoiceTotal// Fill in the blanks of the following:cout << "The preferred soda is " << << endl;cout << "The preferred snack is " << << endl;cout << "Out of " << << " people "<< << " chose these items!" << endl;cout << "Each of these products were given a rating of " << ;cout << " from our expert tasters" << endl;cout << "The other products were rated no higher than a " << rating<< endl;return 0;} Exercise 2: Fill in the indicated code, then compile and run the program.Continue to work on the program until you have no syntax, run-time, orlogic errors.The output should look similar to the following:The preferred soda is Dr. DolittleThe preferred snack is crackersOut of 250 people 148 chose these items!Each of these products were given a rating of A from our expert tastersThe other products were rated no higher than a BExercise 3: Is it possible to change the choice of FAVORITESODA by addingcode within the main module of the program? Why or why not?Exercise 4: Is it possible to change the choice of favoriteSnack by adding codewithin the program? Why or why not?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

Task: 5 Working with Characters and Strings
Exercise 1: Retrieve program stringchar.cpp from the Lab 2 folder. This
program illustrates the use of characters and strings. The char data type
allows only one character to be stored in its memory location. The string
data type (actually a class and not a true data type built into the language)
allows a sequence of characters to be stored in one memory location. The
code follows:

// This program demonstrates the use of characters and strings
// PLACE YOUR NAME HERE
#include <iostream>
#include <string>
using namespace std;
// Definition of constants
const string FAVORITESODA = "Dr. Dolittle"; // use double quotes for strings
const char BESTRATING = 'A'; // use single quotes for characters
int main()
{

char rating; // 2nd highest product rating
string favoriteSnack; // most preferred snack
int numberOfPeople; // the number of people in the survey
int topChoiceTotal; // the number of people who prefer the top choice
// Fill in the code to do the following:
// Assign the value of "crackers" to favoriteSnack
// Assign a grade of 'B' to rating
// Assign the number 250 to the numberOfPeople
// Assign the number 148 to the topChoiceTotal
// Fill in the blanks of the following:
cout << "The preferred soda is " << << endl;
cout << "The preferred snack is " << << endl;
cout << "Out of " << << " people "
<< << " chose these items!" << endl;
cout << "Each of these products were given a rating of " << ;
cout << " from our expert tasters" << endl;
cout << "The other products were rated no higher than a " << rating
<< endl;
return 0;
}

Exercise 2: Fill in the indicated code, then compile and run the program.
Continue to work on the program until you have no syntax, run-time, or
logic errors.
The output should look similar to the following:
The preferred soda is Dr. Dolittle
The preferred snack is crackers
Out of 250 people 148 chose these items!
Each of these products were given a rating of A from our expert tasters
The other products were rated no higher than a B
Exercise 3: Is it possible to change the choice of FAVORITESODA by adding
code within the main module of the program? Why or why not?
Exercise 4: Is it possible to change the choice of favoriteSnack by adding code
within the program? Why or why not?

AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT