so i cant find the solution yet so i will upload a part of my code if sb can help me more .... when i put vector it says that does not name a type in namespace std...
Code:
class book{
private:
string name;
string author;
int year;
int price;
public:
//book(string,string,int,int);
void setall(string,string,int,int);
void display();
int price1(){return price;}
};
void book::setall(string str1,string str2,int p1,int p2)
{
name=str1;
author=str2;
year=p1;
price=p2;
}
void book::display()
{
cout << "name : " << name << " author : " << author << " year : " << year << " price: "<<price<<endl;
}
void binary_search(const std::vector<book>& S,int *,int,int);
int main()
{
int result;
int N;
string str1,str2;
int p1,p2;
int i=0;
book *b=new book[N];
ifstream myfile ("book.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
if (i==0)
myfile >> N;
else {
myfile >> str1 >> str2 >> p1 >> p2;
//cout << "str1 : " << str1 << " str2 : " << str2 << " p1 : " << p1 << " p2: "<<p2<<endl;
b[i-1].setall(str1,str2,p1,p2);}
i++;
}
myfile.close();
}
int x;
std::vector<book> v(N);
binary_search(v,&result,N, x);
cout <<result<<endl;
if (result!=0)
cout<<"It has been found at the position : "<<result;
else cout<<"there is no such element";
system("pause");
}
void binary_search(const std::vector<book>& S,int *result,int N,int keynum){
int mid;
int high=N-1;
int low=0;
do
{
mid= (low + high) / 2;
if ( keynum < S[mid].price1() )
high = mid - 1;
else if ( keynum > S[mid].price1())
low = mid + 1;
} while( keynum!=S[mid].price1() && low <= high);
if( keynum == S[mid].price1() )
{
//cout<<"It has been found at the position : "<<mid+1;
*result= mid+1;
}
else
{
*result=0;
}
system("Pause");
}