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
|
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
class Car
{
string reportingMark;
int Carnumber=0;
string kind="other";
bool loaded=0;
string destination="NONE";
int *ptr;
//~Car(); //destructor
public:
Car(){setUp();}
Car(string , int , string , bool , string ){setUp();}
void setUp ();
void outPut();
}mycar;
void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination);
int main(int argc, const char * argv[])
{
string reportingMark;
int Carnumber;
string kind;
bool loaded;
string destination="NONE";
//Car car;
Car car1,car2,car3;
car2=car1;
car3=Car();
input(reportingMark,Carnumber,kind,loaded,destination);
car1.outPut();
car2.outPut();
car3.outPut();
return 0;
}
void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination)
{
cout << "What is your reportingMark: "<< endl;
cin >> reportingMark;
cout << "What is your carNumber"<< endl;
cin >> Carnumber;
cout << "What is your kind of your car?"<<endl;
while (kind != "business")
{
cin >> kind;
if (kind != "business" && kind != "maintenance" && kind!= "other")
{
cout << "Your input is invalid. Please type again "<<endl;
}
else
break;
}
cout << "Is your car loaded: "<<endl;
cout << "If you say yes please type 1. Otherwise please type 0"<<endl;
cin >>loaded;
if (loaded == true)
{
cout << "What is your destination: "<<endl;
cin >> destination;
}
else if (loaded == false)
{
cout << "What is your destination: "<<endl;
cin >>destination;
if(destination == "no")
{
cout <<"Thank you"<<endl;
}
}
}
void Car::setUp()
{
mycar.reportingMark=reportingMark;
mycar.Carnumber=Carnumber;
mycar.kind=kind;
mycar.loaded=loaded;
mycar.destination=destination;
}
void Car::outPut()
{
cout <<mycar.reportingMark<<endl;
cout <<mycar.Carnumber<<endl;
cout <<mycar.kind<<endl;
cout<<boolalpha<<mycar.loaded<<endl;
cout <<mycar.destination<<endl;
}
/*Car::~Car()
{}
*/
|