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