Ένα κατάστημα πουλά αντίκες. Κάθε αντίκα περιγράφεται από το όνομα, τη τιμή και έναν ακέραιο κωδικό. Να γράψετε πρόγραμμα που διαβάζει 5 αντικείμενα με τις ιδιότητες τους από το χρήστη, να βρίσκει το όνομα του πιο ακριβού και να τα τυπώνει μορφοποιημένα στην οθόνη από το πιο φθηνό στο πιο ακριβό.
#include <iostream>
#include <string>
using namespace std;
#define SIZE 5
struct antique {
int code;
string aname;
double price;
} antique[SIZE];
int main(){
int i,j,maxi;
double maxPrice=-1;
struct antique temp;
for(i=0;i<SIZE;i++){
cout<<"Antique "<<i+1<<" code: ";
cin>>antique[i].code;
cout<<"Antique "<<i+1<<" name: ";
cin>>antique[i].aname;
cout<<"Antique "<<i+1<<" price: ";
cin>>antique[i].price;
cout<<endl;
}
for(i=0;i<SIZE;i++){
if(antique[i].price>maxPrice){
maxPrice=antique[i].price;
maxi=i;
}
}
cout<<endl<<"Most expensive is "<<antique[maxi].aname;
for(i=0;i<SIZE-1;i++){
for(j=i+1;j<SIZE;j++){
if(antique[i].price>antique[j].price){
temp=antique[i];
antique[i]=antique[j];
antique[j]=temp;
}
}
}
cout<<endl<<endl;
for(i=0;i<SIZE;i++){
cout<<"Code: "<<antique[i].code<<endl<<"Name: "<<antique[i].aname<<endl<<"Price: "<<antique[i].price<<endl<<endl;
}
return 0;
}