Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have an error in my code. Can someone help me out so that the code compiles an

ID: 3632981 • Letter: I

Question

I have an error in my code.

Can someone help me out so that the code compiles and executes correctly?

Thanks.


// H3c10p607x10.cpp : Defines the entry point for the console application.
//

#include<iostream>
#include<vector>
#include<string>

using namespace std;

//Function Prototype Declaration

bool seqsearch(vector<string>list, string str);

void main()
{

//variable declaration
vector<string>list;
string s, ser_str;

bool found;
int i, n;

//inputting the number of strings
cout << "Enter number of strings: ";
cin >> n;

//inputting strings into vector "list"

for (i=0; i<n; i++)
{
cin >> s;
list.push_back(s);
}

cout << "Enter string to be searched: ";
cin >> ser_str;

//function call
found=seqsearch(list, ser_str);
if(found)
cout << "String found in Vector " << endl;
else
cout << "String not found in Vector." << endl;

system("pause");
} // end main

//Function Definition

bool seqsearch(vector<string>list, string str)
{
bool found=false;
int i;
for (i=0; i<list.size(); i++)
{
if(list[i]==str)
{ found=true;
break;
}
}
return found;
}// end of search function

Explanation / Answer

please rate - thanks

#include<iostream>
#include<vector>
#include<string>

using namespace std;

//Function Prototype Declaration

bool seqsearch(vector<string>list, string str);

int main()
{

//variable declaration
vector<string>list;
string s, ser_str;

bool found;
int i, n;

//inputting the number of strings
cout << "Enter number of strings: ";
cin >> n;

//inputting strings into vector "list"

for (i=0; i<n; i++)
{cout<<"Enter string "<<i+1<<": ";
cin >> s;
list.push_back(s);
}

cout << "Enter string to be searched: ";
cin >> ser_str;

//function call
found=seqsearch(list, ser_str);
if(found)
cout << "String found in Vector " << endl;
else
cout << "String not found in Vector." << endl;

system("pause");
} // end main

//Function Definition

bool seqsearch(vector<string>list, string str)
{
bool found=false;
int i;
for (i=0; i<list.size(); i++)
{
if(list[i]==str)
{ found=true;
break;
}
}
return found;
}// end of search function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote