//This program demonstrates the use of characters and strings. // Place Your Nam
ID: 671036 • Letter: #
Question
//This program demonstrates the use of characters and strings. // Place Your Name Here. #include #include using namespace std; // definition of constants const string Favoritesoda = "Brand X"; // strings get double quotes const char Bestrating = 'A'; //characters get single quotes int main() { char rating2; // 2nd highest product rating string favoritesnack; // most preferred snack int numberofpeople; // number of people in the survey int topchoiceTotal; // number of people who prefer the top choiceExplanation / Answer
Excercise 1
#include<iostream>
#include <string>
using namespace std;
//definition of constants
const string FAVORITESODA = "Brand X";
const char BESTRATING = 'A';
int main()
{
char raitng2;
string favoriteSnack;
int numberOfPeople;
int topChoiceTotal;
favoriteSnack="crackers";
raitng2='B';
numberOfPeople=250;
topChoiceTotal=148;
cout<<"The number one soda is "<<FAVORITESODA<<endl;
cout<<"The number one snack is "<<favoriteSnack<<endl;
cout<<"Out of "<<numberOfPeople<<" people "<<topChoiceTotal<<" chose these items"<<endl;
cout<<"Each of these products recieved a rating of "<<raitng2<<" from our expert tasters.";
cout<<" The other products were rated no higher than a "<<BESTRATING<<endl;
}
Excercise 2
You cannot change the value of FAVORITESODA as it has been declared as a constant using the keyword "const". Constants do not change their values throughout the length of a code/program.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.