I'm going to have to break this up into files however I receiving errors when I try to compile this. I am confused about this program Please help.I.m using Visual C++ platform, XP operating system
enclosed are the errors I'm getting and the code
Vehicle.cpp
Vehicle.cpp(35) : error C2511: 'Person::Person(Person &)' : overloaded member fu
nction not found in 'Person'
Vehicle.cpp(10) : see declaration of 'Person'
Vehicle.cpp(40) : error C2511: 'std::string Person::getName(void)' : overloaded
member function not found in 'Person'
Vehicle.cpp(10) : see declaration of 'Person'
Vehicle.cpp(45) : error C2511: 'Person &Person::operator =(Person &)' : overload
ed member function not found in 'Person'
Vehicle.cpp(10) : see declaration of 'Person'
c:\Documents and Settings\Warren Hoskins\My Documents\C++ programs in progress\P
erson.h(7) : error C2011: 'Person' : 'class' type redefinition
Vehicle.cpp(10) : see declaration of 'Person'
Vehicle.cpp(91) : error C2065: 'Manufacturer' : undeclared identifier
Vehicle.cpp(92) : error C2065: 'OwnerName' : undeclared identifier
Vehicle.cpp(93) : error C2065: 'Numofcyl' : undeclared identifier
Vehicle.cpp(96) : error C2061: syntax error : identifier 'Numofcyl'
Vehicle.cpp(97) : error C2511: 'Vehicle::Vehicle(std::string)' : overloaded memb
er function not found in 'Vehicle'
Vehicle.cpp(73) : see declaration of 'Vehicle'
Vehicle.cpp(105) : error C3861: 'Manufacturer': identifier not found, even with
argument-dependent lookup
Vehicle.cpp(108) : error C2039: 'getOwnerName' : is not a member of 'Vehicle'
Vehicle.cpp(73) : see declaration of 'Vehicle'
Vehicle.cpp(110) : error C3861: 'OwnerName': identifier not found, even with arg
ument-dependent lookup
Vehicle.cpp(113) : error C2039: 'getNumofcyl' : is not a member of 'Vehicle'
Vehicle.cpp(73) : see declaration of 'Vehicle'
Vehicle.cpp(116) : error C3861: 'Numofcyl': identifier not found, even with argu
ment-dependent lookup
C:\Documents and Settings\Warren Hoskins\My Documents\C++ programs in progress> I'm programming in C++
#include <iostream>
#include<cstdlib>
#include<string>
using namespace std;
class Person
{
public:
Person ();
Person (string theName);
Person (const Person& theObject);// this is confusing me
string getName()const;
Person& operator=(const Person& rtSide);// and this rtSide; I don't understsnd
friend istream& operator >>(istream& inStream,Person& personObject);
friend ostream& operator <<(ostream& outstream,const Person& personObject);
protected:
string name;
};
Person::Person() : name("Unknown")
{
}
Person::Person(string theName)
{
name = theName;
}
Person::Person( Person& theObject)
{
name = theObject.getName();
}
string Person::getName()
{
return name;
}
Person& Person::operator =(Person& rtSide)
{
name = rtSide.getName();
return *this;
}
istream& operator >>(istream& inStream, Person& personObject)
{
inStream >> personObject.name;
return inStream;
}
ostream& operator <<(ostream& outStream, const Person& personObject )
{
outStream << personObject.name;
return outStream;
}
//#ifndef VEHICLE_H
//#define VEHICLE_H
#include <iostream>
#include <string>
#include "person.h"
using namespace std;
class Vehicle
{
public:
Vehicle();
Vehicle(string, int, Person);
string getManufacturer(){return manufacturer;}
int getCylinders(){return cylinders;}
string getOwner(){return vehicleOwner.getName();}
protected:
string manufacturer;
int cylinders;
Person vehicleOwner;
};
//#endif
Vehicle::Vehicle() // default constructor
{
Manufacturer = "No name";
OwnerName = "None";
Numofcyl = 0;
}
Vehicle::Vehicle( string theManufacturer,Numofcyl, Person theOwnerName)
{
Manufacturer = theName;
OwerName = theOwnerName;
Numofcyl = 0;
}
string Vehicle::getManufacturer() // accessor function to getManuf Name
{
return Manufacturer;
}
string Vehicle::getOwnerName() // accessor function toOwnerName
{
return OwnerName;
}
int Vehicle ::getNumofcyl() // accessor function to getNumofcyl
{
return Numofcyl;
}
//#ifndef truck_h
//#define truck_h
#include <iostream>
#include "person.h"
#include "vehicle.h"
using namespace std;
class Truck : public Vehicle
{
public:
Truck();
Truck(string, int, Person, double, int);
Truck(Truck& rtSide);// the right side of what
double getLoadCapacity(){return loadCapacity;}
int getTowingCapacity(){return towingCapacity;}
Truck& operator=(Truck& rtSide); // need help here
protected:
double loadCapacity;
int towingCapacity;
};
Truck::Truck():Vehicle() // inherited from the base class
{
loadCapcity = 0;
towingcapacity = 0;
}
Truck::Truck():getLoadCapacity(loadCapacity) // inheriting from the vehicle class
{
return loadCapacity;
}
Truck::Truck():getTowingCapacity(towingCapacity)
{
return towingCapacity;
}
int main()
{
//testing implemented person class
Person owner("John Williams");
Person owner2;
//testing constructors
Truck truckObject1;
//manufacturer, no of cylinders, owner, load capacity(tons), towing capacity(pounds)
Truck truckObject2("Ford",8,owner,1.5,1500);
//testing assignment operator
truckObject1 = truckObject2;
//first 3 methods are inherited from vehicle class (getManufacturer,getCylinders, getOwner )
cout <<"Manufacturer: " <<truckObject1.getManufacturer() <<endl;
cout <<"Cylinders: " <<truckObject1.getCylinders() <<endl;
cout <<"Owner: " <<truckObject1.getOwner() <<endl; // should return a string
cout <<"Load Capacity: " <<truckObject1.getLoadCapacity() <<endl;
cout <<"Towing Capacity: " <<truckObject1.getTowingCapacity() <<endl<<endl;
//testing overload stream extraction and insertion operators
cout<<"Enter a new owner name: ";
cin >> owner2;
cout<<"Verify owner: " <<owner2<<endl;
Truck truckObject3("Dodge",8,owner2,1,1200);
//testing copy constructor
Truck truckObject4(truckObject3);
cout <<"Manufacturer: " <<truckObject4.getManufacturer() <<endl;
cout <<"Cylinders: " <<truckObject4.getCylinders() <<endl;
cout <<"Owner: " <<truckObject4.getOwner() <<endl;
cout <<"Load Capacity: " <<truckObject4.getLoadCapacity() <<endl;
cout <<"Towing Capacity: " <<truckObject4.getTowingCapacity() <<endl;
system("pause");
return 0;
{