Problem: Write a class that defines a car. The car class stores the following data about a car:
Member Name Data Type
make string
model string
vin string
owner string
doors int
mileage float
gas tank float
trip float
gas remaining float
Create methods to set data into the data members and to read the data from the data members. Write a method to determine the gas mileage.
What I got so far is:
#include <iostream>
#include <string>
using namespace std;
class car
{
private:
string make,
model,
vin,
owner;
int doors;
float mileage,
gasTank,
trip,
gasRemaining;
public:
string getMake();
string getModel();
string getOwner();
int getDoors();
float getMileage();
float getGasTank();
float getTrip();
float getGasRemaining();
double getGasMilease();
};
int main()
{
car cars;
cout << " Please enter Make of car: ";
cin >> cars.make;
return 0;
}
string car::getMake()
{
return make;
}
I am getting the following errors:
1>.\CH 7 Addendum 2 Car Class.cpp(41) : error C2248: 'car::make' : cannot access private member declared in class 'car'
1> .\CH 7 Addendum 2 Car Class.cpp(15) : see declaration of 'car::make'
1> .\CH 7 Addendum 2 Car Class.cpp(13) : see declaration of 'car'
This week we just started to learn about classes so I am totally lost even after reading the textbook several times and looking over their examples. Can anyone help me understand what I am doing wrong with the class?