Hmmmm...I suppose it would help if you told is
what the errors were.
However I did notice that you're not ending these two lines with semi-colons when you should be:
Vehicles Car(5,40,30)
Vehicles Truck(4,50,12)
Here's the fixed code, it compiles fine for me:
#include <iostream>
using namespace std;
class Vehicles {
public:
int pass;
int fuelcap;
int mpg;
Vehicles(int p, int f, int m);
int get_data(int type);
void set_data(int type, int data);
};
int Vehicles::get_data(int type) {
int data;
switch(type) {
case 1:
data = pass;
break;
case 2:
data = fuelcap;
break;
case 3:
data = mpg;
break;
}
return data;
}
void Vehicles::set_data(int type, int data) {
switch(type) {
case 1:
pass = data;
break;
case 2:
fuelcap = data;
break;
case 3:
mpg = data;
break;
}
}
int main()
{
Vehicles Car(5,40,30);
Vehicles Truck(4,50,12);
cout << "Old Data:n";
cout << "The car can take " << Car.get_data(1) << " passengers " << Car.get_data(2) * Car.get_data(3) << " milesn";
cout << "The truck can can carry " << Truck.get_data(1) << " passengers " << Truck.get_data(2) * Truck.get_data(3) << " milesnn";
//change data using set_data
Car.set_data(3,20);
Truck.set_data(2,5);
cout << "New Data:n";
cout << "The car can take " << Car.get_data(1) << " passengers " << Car.get_data(2) * Car.get_data(3) << " milesn";
cout << "The truck can can carry " << Truck.get_data(1) << " passengers " << Truck.get_data(2) * Truck.get_data(3) << " milesnn";
system("Pause");
return 0;
}
Vehicles::Vehicles(int p, int f, int m) {
pass = p;
fuelcap = f;
mpg = m;
}
EDIT:
I wasn't fast enough.
i like orange