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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// enumerated type
enum Purpose { BUSINESS, PERSONAL };
struct Car
{
string carMake;
string carModel;
int yearModel;
double cost;
Purpose prps;
};
//function prototype
void displayCar(Car *, int);
int main()
{
const int SIZE = 10;
int purpose;
Car carArray[SIZE] = {
{"Ford", "Taurus", 1997, 21000, BUSINESS},
{"Honda", "Accord", 1992, 11000, BUSINESS},
{"Lamborghini", "Aventador", 2011, 390000, BUSINESS}
};
cout << "Please enter a Car Make: ";
getline(cin, carArray[3].carMake);
cout << "Please enter Car Model: ";
getline(cin, carArray[3].carModel);
cout << "Please enter Car Year: ";
cin >> carArray[3].yearModel;
cin.ignore(10000000, '\n');
cout << "Please enter Car Cost: ";
cin >> carArray[3].cost;
cin.ignore(10000000, '\n');
cout << "Please enter Car Purpose (1=BUSINESS, 2=PERSONAL) : ";
cin >> purpose;
cin.ignore(1000000, '\n');
carArray[3].prps = static_cast <Purpose>(purpose); //static cast to input the purpose of the vehicle
for (int index = 0; index < 4; index++)
{
cout << "\nCar #" << index + 1 << endl;
displayCar(carArray, index);
}
return 0;
}
void displayCar(Car *vehicle, int element)
{
cout << "Make: " << vehicle[element].carMake << endl;
cout << "Model: " << vehicle[element].carModel << endl;
cout << "Year: " << vehicle[element].yearModel << endl;
cout << fixed << setprecision(2);
cout << "Cost: " << vehicle[element].cost << endl;
cout << "Purpose: ";
switch (vehicle[element].prps)
{
case BUSINESS:
cout << "Business" << endl;
break;
case PERSONAL:
cout << "Personal" << endl;
break;
}
cout << endl;
}
|