/************ stack.h ************/
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
class stack
{
public:
bool find(const string &elem) const;
int count(const string &elem) const;
...
...
private:
vector<string> _stack;
};
/********** stack.cpp **********/
#include "stack.h"
...
...
bool stack::find (const string &elem) const
{
vector<string>::const_iterator it = _stack.begin();
return (::find(it,_stack.end(),elem))!=_stack.end();
}
int stack::count(const string &elem) const
{
return (::count(_stack.begin(),_stack.end(),elem));
}
/*********** main.cpp *************/
#include "stack.cpp"
#include<fstream>
int main()
{
stack st;
string str;
ifstream readfile("sentence.txt");
while(readfile>>str && !st.full())
{
st.push(str);
}
...
cout<<"\nEnter a word to search: ";
cin>>str;
if(st.find(str))
cout<<"The word was found "<<st.count(str)<<" no. of times"<<endl;
else
cout<<"The word was not found"<<endl;
return 0;
}