So how can I do this ? I tried with friend functions, overloading operators and can't seem to get it done .
class shop {
int price;
string name;
string model;
public:
shop () {
price =0;
name = " NULL" ;
model = " NULL " ;
}
shop ( string n , string m , int p ) {
name = n;
model = m;
price = p;
}
void display () {
cout<<"Name : " << name <<endl;
cout<<"Model : "<<model<<endl;
cout<<"Price : "<<price<<endl;
}
};
How can I sort this by price ?
for ( int i = 1 ; i<=products ; i++) {
cin.ignore();
cout<<"Name "<< i << ": ";
getline(cin,n);
cout<<"Model "<< i << ": ";
cin>>m;
cout<<"Price "<< i << ": ";
cin>>p[i];
e[i] = new shop(n,m,p[i]);
}
I have this vector which I tried sorting. I want to do it without sort as I don't think I declared the vector properly for this method.