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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#include <cstdlib>
#include <iostream>
using namespace std;
class CarData
{
private:
double year, mileage;
string make, model, name, phone;
public:
CarData(); //constructor
CarData(double, double, string, string, string, string);
void setYear(double);
void setMileage(double);
void setMake(string);
void setModel(string);
void setName(string);
void setPhone(string);
double getYear();
double getMileage();
string getMake();
string getModel();
string getName();
string getPhone();
void valid_mileage(double);
void car_details();
};
int main()
{
int numCar=0, ctr;
cout << "How many new vehicles are being added to the inventory?\n";
cin >> numCar;
CarData car[numCar][6]; //creates an car array of "numCar" amounts of the "CarData4 type
for (ctr = 0; ctr < numCar; ctr++)
{
cout << "\n\nVehicle " << ctr +1; // Helps user keep track vehicle #
cout << "\n\tEnter year #: "; // Input information
cin << CarData::getYear(double);
//CarData::setYear(double year);
}
myCar.car_details();
system("PAUSE");
return 0;
}
//class definition
CarData::CarData()//variable initializer
{
year = 0;
mileage = 0;
make = "null";
model = "null";
name = "null";
phone = "null";
}
CarData::CarData(double year, double mileage, string make, string model, string name, string phone)
{
CarData::year = year;
vaild_mileage(mileage);
CarData::make = make;
CarData::model = model;
CarData::name = name;
CarData::phone = phone;
}
void CarData::setYear(double year)
{
CarData::year = year;
}
void CarData::setMileage(double mileage)
{
vaild_mileage(mileage);
}
void CarData::setYear(string make)
{
CarData::make = make;
}
void CarData::setModel(string model)
{
CarData::model = model;
}
void CarData::setName(string name)
{
CarData::name = name;
}
void CarData::setPhone(string phone)
{
CarData::phone = phone;
}
double CarData::getYear()
{
return year;
}
double CarData::getMileage()
{
return Mileage;
}
string CarData::getMake()
{
return Make;
}
string CarData::getModel()
{
return Model;
}
string CarData::getName()
{
return Name;
}
string CarData::getPhone()
{
return Phone;
}
void CarData::valid_mileage(double mileage)
{
if (mileage>=0)
CarData::mileage=mileage;
else {
CarData::mileage=0;
cout << "Invalid mileage!\n";
}
}
void CarData::car_details()
{
cout << "The current car is a " << year << ' ' << make << ' ' << model
<< "with" << mileage << "miles..\n";
}
| |