#include <cstdlib>
#include <iostream>
#include "Vehicle.h"
#include "Car.h"
#include "Truck.h"
#include "Van.h"
usingnamespace std;
Vehicle *vehicle=0;
int main(int argc, char *argv[])
{
int var1=1;//sentry for the program loop
while(var1==1){
int var2=0;//sentry for the menu control
cout <<"What type of vehcile?:"<<endl
<<"1.Truck"<<endl
<<"2.Car"<<endl
<<"3.Van"<<endl
<<"4.Exit"<<endl;
cin >>var2;
switch(var2){
case 1:vehicle=new Truck;break;
case 2:vehicle=new Car;break;
case 3:vehicle=new Van;break;
case 4:return 0;break;
}//end menu switch
string temp;
//get the make
cout <<"Enter Make of Vehicle:";
cin >>temp;
vehicle->setMake(temp);
//get the model
cout <<"Enter Model of Vehicle:";
cin >>temp;
vehicle->setModel(temp);
//get the color
cout <<"Enter Color(Red, Green, Blue, Yellow, or Black):"<<endl;
cin >>temp;
vehicle->setColor(temp);
//get the type of interior
cout <<"Enter the type of Interior(Leather, Vinyl, or Cloth):"<<endl;
cin >>temp;
vehicle->setInterior(temp);
double temp2;
//get the engine size
while(vehicle->getEngineSize()<4.1){
cout <<"Enter Engine size:(4.1-8.4)"<<endl;
cin >>temp2;
vehicle->setEngineSize(temp2);
}//end engine loop
//get the tire size
while(vehicle->getTireSize()<17){
cout <<"Enter the Tire size:(17-22)"<<endl;
cin >>temp2;
vehicle->setTireSize(temp2);
}//end tire loop
system("CLS");
vehicle->print();
system("PAUSE");
system("CLS");
cout <<"Another Vehicle?"<<endl
<<"1.Yes"<<endl
<<"2.No"<<endl;
cin >>var2;
delete vehicle;
}//close program loop
return EXIT_SUCCESS;
}
#include <iostream>
#include <string>
usingnamespace std;
class Vehicle{
private:
string vColor;//color of the vehicle
double engineSize;//size of the engine
double tireSize;//size of the tires
string interior;//vehicle interior type
public:
//initialize variables
Vehicle(){
setColor("0");
setEngineSize(0.0);
setTireSize(0.0);
setInterior("0");
}
//set the color of the vehicle
void setColor(string color){
vColor=color;
}
//get the color of the vehicle
string getColor(){return vColor;}
//set the size of the engine
void setEngineSize(double size){
engineSize=(size>4.0 && size<8.5)? size:0.0;
}
//get the size of the engine
double getEngineSize(){return engineSize;}
//set the size of the tires
void setTireSize(double size){
tireSize=(size>=17 && size<= 22)? size:0.0;
}
//get the size of the tires
double getTireSize(){return tireSize;}
//set the matieral of the interior
void setInterior(string mat){
interior=mat;
}
//get the matieral of the interior
string getInterior(){return interior;}
//rewritable print function
virtualvoid print()=0;
};//end class
#include <iostream>
#include <string>
usingnamespace std;
class Vehicle{
private:
string vColor;//color of the vehicle
double engineSize;//size of the engine
double tireSize;//size of the tires
string interior;//vehicle interior type
public:
//initialize variables
Vehicle(){
setColor("0");
setEngineSize(0.0);
setTireSize(0.0);
setInterior("0");
}
//set the color of the vehicle
void setColor(string color){
vColor=color;
}
//get the color of the vehicle
string getColor(){return vColor;}
//set the size of the engine
void setEngineSize(double size){
engineSize=(size>4.0 && size<8.5)? size:0.0;
}
//get the size of the engine
double getEngineSize(){return engineSize;}
//set the size of the tires
void setTireSize(double size){
tireSize=(size>=17 && size<= 22)? size:0.0;
}
//get the size of the tires
double getTireSize(){return tireSize;}
//set the matieral of the interior
void setInterior(string mat){
interior=mat;
}
//get the matieral of the interior
string getInterior(){return interior;}
//rewritable print function
virtualvoid print()=0;
};//end class
#include <iostream>
#include <string>
#include <iomanip>
#include "Vehicle.h"
usingnamespace std;
class Truck:public Vehicle{
private:
string make;//make of the truck
string model;//model of the truck
public:
//initialize variables
Truck():Vehicle(){
setMake("0");
setModel("0");
}
//set the make of the truck
void setMake(string input){
make=input;
}
//get the make of the truck
string getMake(){return make;}
//set the model of the truck
void setModel(string input){
model=input;
}
//get the model of the truck
string getModel(){return model;}
//print out the truck object
void print(){
cout <<fixed<<setprecision(2);
cout <<"Truck:"<<endl
<<"Make: "<<getMake()<<endl
<<"Model: "<<getModel()<<endl
<<"Engine: "<<getEngineSize()<<"L"<<endl
<<"Tires: "<<getTireSize()<<endl
<<"Interior: "<<getInterior()<<endl
<<"Color: "<<getColor()<<endl;
}
};//end truck class
#include <iostream>
#include <string>
#include <iomanip>
#include "Vehicle.h"
usingnamespace std;
class Van:public Vehicle{
private:
string make;//make of the van
string model;//model of the van
public:
//initialize variables
Van():Vehicle(){
setMake("0");
setModel("0");
}
//set the make of the van
void setMake(string input){
make=input;
}
//get the make of the van
string getMake(){return make;}
//set the model of the van
void setModel(string input){
model=input;
}
//get the model of the van
string getModel(){return model;}
//print out the van object
void print(){
cout <<fixed<<setprecision(2);
cout <<"Van:"<<endl
<<"Make: "<<getMake()<<endl
<<"Model: "<<getModel()<<endl
<<"Engine: "<<getEngineSize()<<"L"<<endl
<<"Tires: "<<getTireSize()<<endl
<<"Interior: "<<getInterior()<<endl
<<"Color: "<<getColor()<<endl;
}
};//end van class
the errors i am getting are:
line-error message
5 from 13_14main.cpp In file included from Car.h:5, from 13_14main.cpp
7 redefinition of `class Vehicle'
7 previous definition of `class Vehicle'
6 from 13_14main.cpp In file included from Truck.h:5, from 13_14main.cpp
7 redefinition of `class Vehicle'
7 previous definition of `class Vehicle'
7 from 13_14main.cpp In file included from Van.h:5, from 13_14main.cpp
7 redefinition of `class Vehicle'
7 previous definition of `class Vehicle'
In function `int main(int, char**)':
34 'class Vehicle' has no member named 'setMake'
38 'class Vehicle' has no member named 'setModel'
[Build Error] [13_14main.o] Error 1
That is not the point. The point is that car.h and vehicle.h are the exact same thing, only with different names regarding their header files. Sorry, but compilers hate that. Can't they fix it on their own? :)
You also forgot to declare and define setMake() and setModel() in one of the header files that defines the class Vehicle.