Question

Allow the user to enter a list of movie titles until typing "Done". Add each movie...

Allow the user to enter a list of movie titles until typing "Done". Add each movie title to a vector. After populating the vector, print all the titles. Then, remove from the vector all the titles from the list that include the word "the" (or "The") in its title and print the remaining titles.

Sample Input:

Captain Marvel
The Lego Movie 2
Aladdin
The Dark Knight
Ant-Man and the Wasp
Done

Sample Output:

Initial List:
Captain Marvel
The Lego Movie 2
Aladdin
The Dark Knight
Ant-Man and the Wasp

Titles without "the":
Captain Marvel
Aladdin
  • Note - you must actually remove the elements from the vector before printing the updated list. You may not just print out the titles without "the" (5 point deduction)

c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include "string"
#include <string>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v1;
cout<<"Please Enter movie names. Enter Done to exit\n";
string name;
while(true){
   getline(cin,name);
   if(name=="Done") break;
   else
   {
   v1.push_back(name);
   }
}
cout<<"\nInitial List:\n";
for(vector<string>::iterator itr=v1.begin();itr!=v1.end();++itr)
cout<<*itr<<"\n";

cout<<"\nTitles without \"the\":\n";
for(vector<string>::iterator itr=v1.begin();itr!=v1.end();++itr)
{
   string s1 = *itr;
   if (s1.find("the") != std::string::npos || s1.find("The") != std::string::npos)
   {
      
   }
   else
   {
       cout<<*itr<<"\n";
   }
}

return 0;   
}

Add a comment
Know the answer?
Add Answer to:
Allow the user to enter a list of movie titles until typing "Done". Add each movie...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT