Inheritance

Is this correct so far?

QUESTION:

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 in the code that follows). 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 follows. The implementation of the class is part of this programming project.

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
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 owner; 
};


CODE:

#include <iostream>
#include <string>
using namespace std;

namespace vehicles{
	class vehicle{
		private:
			string Name;
			int NoOfCylinders;
			string owner;
		public:
			vehicle();
			vehicle( string NewName, int NewNoOfCylinders);
			string GetName() const;
            int GetNoOfCylinders() const;
            void SetName(string NewName);
            void SetNoOfCylinders(string NewNoOfCylinders);
            void PrintCheck() const;
	};
}

namespace vehicles{
class Person:public vehicle{    
public:     
	Person( );      
	Person(string theName);      
	Person(const Person& theObject);      
	string getName( ) const;     
	Person& operator=(const Person& rtSide); 

	Person& Person::operator=(const Person& owner){
			vehicle::operator=(owner);
		}
	Person& Person::operator(const Person& object){
			:vehicle(object);
		}
	friend istream& operator >>(istream& inStream, Person& personObject);        
	friend ostream& operator <<(ostream& outStream, const Person& personObject);   
	private:      
		string owner; 
};
}

namespace vehicles{
    class Truck:public vehicle{
	private:
        double tons;
        int pounds;
    public:
        Truck();
        Truck(string NewName, int NewNoOfCylinders, double Newtons, int Newpounds);
        double Gettons() const;
        double Getpounds() const;
        void Settons(double Newtons);
        void Setpounds(double Newpounds);
		Truck& Truck::operator=(const Truck& rightside){
			vehicle::operator=(rightside);
		}
		Truck& Truck::operator(const Truck& object){
			:vehicle(object);
		}
		void PrintCheck() const;
    };
}



Am I on the right track? Does the overloaded assignment operator and copy constructor used properly?
Last edited on
Topic archived. No new replies allowed.