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
|
#include <iostream>
#include <string>
using namespace std;
class Cars
{
public:
Cars(); // this is the constructor
void InputCar1(); // this is the prototype to input car1
void InputCar2( int y, string m, string mod, string t, int p, string v, int w, int r);
// this is prototype to request info for car 2
void DisplayCars(); // this is the prototype to display results
~Cars(); //this is the deconstructor
private: // variables for only members of the class objects to access
int year, Year;
string manufacturer, Manufacturer;
string model, Model;
string type, Type;
int price, Price;
string vin, VIN;
int warranty, Warranty;
int rebate, Rebate;
};
Cars::Cars()
{
}
Cars::~Cars(void)
{
cout << "Freeing memory..." << endl;
}
void Cars::InputCar2( int y, string m, string mod, string t, int p, string v, int w, int r)
{
year = y;
manufacturer = m;
model = mod;
type = t;
price = p;
vin = v;
warranty = w;
rebate = r;
}
void Cars::InputCar1()
{
cout << "Please enter the Year, Manufacturer, Model, Type, Price, VIN,
Warranty and Rebate of the 2nd car." << endl;
cout << "Year: ";
cin >> Year;
cout << "Manufacturer: ";
cin >> Manufacturer;
cout << "Model: ";
cin >> Model;
cout << "Type: ";
cin >> Type;
cout << "Price: ";
cin >> Price;
cout << "VIN: ";
cin >> VIN;
cout << "Warranty: ";
cin >> Warranty;
cout << "Rebate: ";
cin >> Rebate;
}
void Cars::DisplayCars(void)
{
cout << endl << "\t\tCar1\t\t\t Car2" << endl;
cout << "Year:\t\t" << Year << "\t\t\t " << year << endl << endl;
cout << "Manufacturer:\t" << Manufacturer << "\t\t\t " << manufacturer << endl << endl;
cout << "Model:\t\t" << Model << "\t\t\t " << model << endl << endl;
cout << "Type:\t\t" << Type << "\t\t\t " << type << endl << endl;
cout << "Price:\t\t" << Price << "\t\t\t " << price << endl << endl;
cout << "VIN:\t\t" << VIN << "\t " << vin << endl << endl;
cout << "Warranty:\t" << Warranty << "\t\t\t " << warranty << endl << endl;
cout << "Rebate:\t\t" << Rebate << "\t\t\t " << rebate << endl;
}
int main ()
{
Cars Car; //Creates object
Car.InputCar1(); // uses object to access variables for car 1
Car.InputCar2(2010, "Chevy", "Corvette", "L6", 50000, "ASDFVVRVR4RFV43334", 50000, 0 );
// uses object to access variables for car 2
Car.DisplayCars(); // uses variables to display both cars
}
|