Help with my compiler error problem?

Hey everyone! I was recently assigned this program in class and have finished it but i have some compiler errors i cant fix. I was just hoping that some of you could give it a shot and share what kind of code you came up with. Well here it is any help would be very appreciative.

Create a base class called Vehicle that has the manufacturer's name (type string), number of cylinders in the engine (type int.), and owner (type person given below instructions). Then create a class called Truck that is derived from Vehicle and has additional properties, the load capacity in tons (type double since it may contain a fractional part), and towing capacity in pounds (type int.) Be sure your classes have a reasonable complement of constructors and accessor methods, an overloaded assignment operator, and a copy constructor. Write a driver program that tests all your methods.

The definition of the class Person (as stated above) is below. The implementation of the class is part of this programming assignment.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Person
{

public:
      Person();
      Person(string theName);
      Person(const Person& theObject);
      string getName() const;
      Person& operator=(const Person& rtSide);
      friend istream& operator >>(istream& inStream, Person& personObject);
      friend ostream& operator >>(ostream& outStream, const Person& personObject);

private:
      string name;

};



Ok so that finishes the instructions for the assignment and here's what i have come up with myself.



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
#include <iostream>
#include <string>

using namespace std;

//Provided Person class.
class Person{
      public:
             Person();
             Person(string theName);
             Person(const Person& theObject);
             Person(const char* theName); //allows const char[number] inputs
             string getName() const;
             Person& Person::operator =(const Person& rtSide);
             friend istream& operator >>(istream& inStream,
                                                  Person& personObject);
             friend ostream& operator <<(ostream& outStream,
                                                  const Person& personObject);
      private:
              string name;
      };

//Required Vehicle class.      
class Vehicle{
      public:
            Vehicle();
            Vehicle(string manuName, int numCyl, const Person& owner);
            Vehicle(const Vehicle& theVehicle);
            Vehicle& operator =(const Vehicle& theVehicle);
            string getManuName();
            int getNumCyl();
            Person getOwner();
      private:
              string manuName;
              int numCyl;
              Person owner;
      };

//Required derived class Truck from base class Vehicle.      
class Truck : public Vehicle{
      public:
             Truck();
             Truck(double capTons, int capPounds, string manuName, int numCyl, const Person& owner);
             Truck(const Truck& theTruck);
             Truck& Truck::operator =(const Truck& theTruck);
             double getCapTons();
             int getCapPounds();
      private:
              double capTons;
              int capPounds;
      };
      
//Person Implementation
//Constructors
Person::Person() : name(""){}
Person::Person(string theName) : name(theName){}
Person::Person(const char* theName) : name(theName){}
Person::Person(const Person& theName): name(theName.name){} //Copy Constructor
//Overloaded assignment operator
Person& Person::operator =(const Person& thePerson){
        this->name = thePerson.name;
        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;
        }
//Accessor methods
string Person::getName() const{
       return name;
       }
       
//Vehicle Implementation
//Constructors
Vehicle::Vehicle() : manuName("No Manufacturer"), numCyl(0), owner("No Owner"){}
Vehicle::Vehicle(string theManuName, int theNumCyl, const Person& theOwner)
                        : manuName(theManuName),
                          numCyl(theNumCyl),
                          owner(theOwner){}
Vehicle::Vehicle(const Vehicle& theVehicle)//Copy Constructor.
                       : manuName(theVehicle.manuName),
                         numCyl(theVehicle.numCyl),
                         owner(theVehicle.owner){}
//Overloaded Assignment Operator
Vehicle& Vehicle::operator =(const Vehicle& theVehicle){
         this->manuName = theVehicle.manuName;
         this->numCyl = theVehicle.numCyl;
         this->owner = theVehicle.owner;
         return *this;
         }
//Accessor methods
string Vehicle::getManuName(){
       return manuName;
       }
int Vehicle::getNumCyl(){
    return numCyl;
    }
Person Vehicle::getOwner(){
       return owner;
       }
       
//Truck Implementation
//Constructors
Truck::Truck() : capTons(0.0), capPounds(0){}
Truck::Truck(double theCapTons, int theCapPounds, string theManuName, int theNumCyl, const Person& theOwner)
                    : Vehicle(theManuName, theNumCyl, theOwner),
                      capTons(theCapTons),
                      capPounds(theCapPounds){}
Truck::Truck(const Truck& theTruck) //Copy Constructor.
                   : Vehicle(theTruck),
                     capTons(theTruck.capTons),
                     capPounds(theTruck.capPounds){}
//Overloaded Assigment Operator
Truck& Truck::operator =(const Truck& theTruck){
       Vehicle::operator =(theTruck);
       capTons = theTruck.capTons;
       capPounds = theTruck.capPounds;
       return *this;
       }
//Accessor methods
double Truck::getCapTons(){
       return capTons;
       }
int Truck::getCapPounds(){
    return capPounds;
}

//Driver Program
int main(){
    Vehicle v1("Honda", 4, "Brian Valle");
    
    cout << "Vehicle v1 Data: " << endl;
    cout << "Manufacturer's Name: " + v1.getManuName() << endl;
    cout << "Number of Cylinders: " + v1.getNumCyl() << endl;
    cout << "Owner: " + v1.getOwner() << endl;
    
    Truck t1(72.0, 18000, "Ford", 8, "Brian Valle");
    
    cout << "Truck t1 Data: " << endl;
    cout << "Manufacturer's Name: " + t1.getManuName();
    cout << "Number of Cylinders: " + t1.getNumCyl();
    cout << "Owner: " + t1.getOwner() << endl;
    cout << "Load Capacity (Tons): " + t1.getCapTons();
    cout << "Towing Capacity (Pounds): " + t1.getCapPounds();
    }



Again any help in fixing these compiler errors would be awesome thanks again!
Well there are about five errors, and I'm not even sure what they mean so i was hoping maybe some one could just copy my code and compile it themselves to see if they knew what they meant.
*cough*cough*
http://cplusplus.com/forum/articles/40071/#msg216270
*cough*cough*

Well there are about five errors, and I'm not even sure what they mean


We would know what they mean. Post them so we can read them. Then we can explain what they mean so you can understand them.

i was hoping maybe some one could just copy my code and compile it themselves to see if they knew what they meant.


I don't have a compiler available on this computer (I'm at work)

And even if I did, that'd be extra work for me. Why should I have to copy the code and compile it to find the errors, when you could just post them.

It shouldn't be like pulling teeth to help you. If you want help, make it as easy for us as you can.
Last edited on
well there were issues in my main function that i fixed where i was using the + operator where i should have used <<...so thats fine now....there are the two remaining error messages

Extra qualification 'Person::' on member 'operator='
Extra qualification 'Truck::' on member 'operator='

any help would be greatly appreciated :)
1
2
(line 14) Person& Person::operator =(const Person& rtSide);
(line 45) Truck& Truck::operator =(const Truck& theTruck);


Remove the scope qualifications ("Person::" and "Truck::").
haha yes thats it....thank you so much i rolled right over that :)
Topic archived. No new replies allowed.