Question: Add these three functions to this code in C++ A function that displays the current value of the vector ( ttYour favorite category is item

Add these three functions to this code in C++

  • A function that displays the current value of the vector (" \t\tYour favorite category is item") and returns nothing
  • A function that takes in and validates user input for the vector and returns a string
    • The vector should not be built in the function
  • A function that takes in and validates user input to determine if we continue or not and returns a bool

Code:

#include

#include

using namespace std;

int main()

{

string choice;

string category2;

string favourite2;

//Vectors declaration

vector category;

vector favourite;

//Do-while loop, if anything other than y is entered, loop will stop

do{

//Ask for user input

cout<<"Please enter a category: ";

cin>>category2;

//Saving data in category vector.

category.push_back(category2);

cout<<"Please enter your favourite thing of that category: ";

cin>>favourite2;

//Saving data in favourite vector.

favourite.push_back(favourite2);

cout<

cout<<"Do you have more favourites ?(y/n) ";

cin>>choice;

}while(choice=="Y"||choice=="y");

cout<

//Print favourite vector by using for loop

for (auto& it : favourite) {

cout <<"Your favourite is "<< it << endl;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!