Question

c++O fe/C/Users/Younis/App ft.Microsoftedgc s Ass06 W19 204).pdf 2 of 2 Question 04 (20 points) Write a version of the sequentia

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

Please find the code below:::

#include<iostream>
#include<vector>
#include<string>
using namespace std;
bool search(vector<string> names,string name){
   for(unsigned int i=0;i<names.size();i++){
       if(names[i]==name){
           return true;
       }
   }
   return false;
}
int main()
{
   vector<string> names;
   cout<<"Enter first names (zzz to end the input)"<<endl;
   string name;
   while(true){
       cin>>name;
       if(name=="zzz"){
           break;
       }else{
           names.push_back(name);
       }
   }

   string searchme;
   cout<<"Enter the name to be searched : ";
   cin>>searchme;
   if(search(names,searchme)){
       cout<<searchme<<" is found in the list."<<endl;
   }else{
       cout<<searchme<<" is not in the list."<<endl;
   }
   return 0;
}

output:

Console 3 terminated> CPP Workspace.exe [C/C++ Application] CAUsers Mo Enter first names (zzz to end the input) salman khan h

Console X terminated> CPP Workspace.exe [C/C++ Application] CAUsers Mo Enter first names (zzz to end the input) salman khan h

Add a comment
Know the answer?
Add Answer to:
c++ O fe/C/Users/Younis/App ft.Microsoftedgc s Ass06 W19 204).pdf 2 of 2 Question 04 (20 points) Write...
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
  • C++ Create an application that searches a file of male and female first names. A link...

    C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....

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