1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
const int MAX=2;
class Car
{
public:
Car(){}
Car(int a, int e, int h, int g, string s):aeor(a),eng(e), hand(h), grip(g), name(s){}
void input();
void print_car();
void check_negative(int& n);
private:
int aeor, eng, hand, grip;
string name;
};
int main()
{
Car cars[MAX];
char choice;
string filler;
cout<<"Welcome to the friend car program.\n";
for(int i=0;i<MAX;i++){
do{
if(i==0)filler=" st";
if(i==1)filler=" nd";
if(i==2)filler=" rd";
if(i>=3)filler=" th";
cout<<"Enter the "<<i+1<<filler<<" vehicle\n\n";
cars[i].input();
cout<<endl;
cout<<"You have entered the following car\n";
cars[i].print_car();
cout<<"Is this information correct?(y/n)\n";
cin>>choice;
cin.ignore(1000,'\n');
}while(choice=='n' || choice=='N');
}
cout<<"Car list is\n";
cout<<"+++++++++++++++++++++++++++++++++++++++++++\n";
for(int j=0;j<MAX;j++){
cars[j].print_car();
cout<<"-----------------------\n";
}
cout<<"+++++++++++++++++++++++++++++++++++++++++++\n";
_getch();
return 0;
}
void Car::print_car()
{
cout<<left<<setw(15)<<"Name: "<<name<<endl;
cout<<left<<setw(15)<<"Aerodynamics: "<<aeor<<endl;
cout<<left<<setw(15)<<"Engine: "<<eng<<endl;
cout<<left<<setw(15)<<"Handling: "<<hand<<endl;
cout<<left<<setw(15)<<"Grip: "<<grip<<endl;
}
void Car::check_negative(int& n){
while(n<0){
cout<<"Can't go below zero points, try again: ";
cin>>n;
}
}
void Car::input()
{
int points=40, total;
cout<<"Enter the name of the vehicle: ";
getline(cin,name);
while(name.length()>10){
cout<<"Vehicle name too long, enter again: ";
getline(cin,name);
}
cout<<"Enter points for Aerodynamics: ";
cin>>aeor;
check_negative(aeor);
total=40-aeor;
cout<<"\nPoints remaining: "<<total<<endl;
cout<<"Enter points for Engine: ";
cin>>eng;
check_negative(eng);
total=total-eng;
cout<<"\nPoints remaining: "<<total<<endl;
cout<<"Enter points for Handling: ";
cin>>hand;
check_negative(hand);
total=total-hand;
cout<<"\nPoints remaining: "<<total<<endl;
cout<<"Enter points for Grip: ";
cin>>grip;
check_negative(grip);
total=total-grip;
cout<<"\nPoints remaining: "<<total<<endl;
cout<<"This vehicle has "<<total<<" points remaining.\n";
}
|