Need help in array class

I need some help overhere help please!
I need to store the car detail with array in class i dont know how to continue i just rewrite it but i won't work!

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
 #include <iostream>
#include <string>
using namespace std;

class Vehicle
{
	protected:
		string Manufacturer;
		string Type;
		int Seatnumber;
	public:
		Vehicle()
		{   
			Seatnumber=0;
		};
		Vehicle(string manufacturer,string type,int seatnumber)
		{   Manufacturer=manufacturer;
			Type=type;
			Seatnumber=seatnumber;
		};
		void setmanufacturer(string manufacturer)
		{   Manufacturer = manufacturer;
		};
		void settype(string type)
		{	Type=type;
		};
		void setseatnumber(int seatnumber)
		{	Seatnumber=seatnumber;
		};
		string getmanufacturer()
		{   return Manufacturer;
		}
		string gettype()
		{	return Type;	
		};
		int getseatnumber()
		{	return 	Seatnumber;
		};
};
class Car: public Vehicle
{
	protected:
		string Carplatenumber;
		string Model;
	public:
		Car():Vehicle()
		{
		};
		Car(string carplatenumber, string model)
		{	Carplatenumber=carplatenumber;
			Model=model;
		};
		void setcarplatenumber(string carplatenumber)
		{	Carplatenumber=carplatenumber;
		};
		void setmodel(string model)
		{	Model=model;	
		};
		string getcarplatenumber()
		{	return Carplatenumber;	
		};
		string getmodel()
		{	return Model;	
		};
		void display();
};
int main ()
{   int size=0;
	Car vehicles[80]={manufacturer,type,seats,carplatenumber,model};
	string  manufacturer;
	string  type;
	int     seats;
	string  carplatenumber;
	string  model;
	
	
	cout<<"How many car of information to you want to key in: ";
	cin>>size;
	for (int i=0; i<size; i++)
	{   cout << "Enter manufacturer: ";
	    cin >> manufacturer;
	    cout << "Enter vehicle type: ";
	    cin >> type;
	    cout << "Enter number of seats: ";
	    cin >> seats;
	    cout << "Enter Carplatenumber: ";
	    cin >> carplatenumber;
	    cout << "Enter Model: ";
	    cin >> model;
	}
	
	return 0;
}
how can i print the detail with Car.getmanufaturer()........ am i really storing in the class array
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
#include <iostream>
#include <string>

class Vehicle
{
    protected:
        std::string Manufacturer;
        std::string Type;
        int Numseats = 0 ;

    public:
        Vehicle() = default ;

        Vehicle( std::string manufacturer, std::string type, int numberofseats )
            : Manufacturer(manufacturer), Type(type), Numseats(numberofseats) {} // initialise members

        // accessors and modifiers
        // ...
};

class Car: public Vehicle
{
    protected:
        std::string Carplatenumber;
        std::string Model;

    public:
        Car() = default ;

        Car( std::string manufacturer, std::string type, int numberofseats, // for the base class
             std::string carplatenumber, std::string model )
            : Vehicle( manufacturer, type, numberofseats ), // initialise base class object
              Carplatenumber(carplatenumber), Model(model) {} // initialise members of car

        // accessors and modifiers
        // ...
};

int main ()
{
    const int MAX_SIZE = 80 ;
    Car vehicles[MAX_SIZE] ;

    std::cout << "How many car of information to you want to key in: ";
    int size = 0;
    std::cin >> size;
    if( size > MAX_SIZE ) size = MAX_SIZE ;

    std::string  manufacturer;
    std::string  type;
    int seats;
    std::string  carplatenumber;
    std::string  model;

    for( int i = 0; i < size; ++i )
    {
        std::cout << "Enter manufacturer: ";
        std::cin >> manufacturer;
        std::cout << "Enter vehicle type: ";
        std::cin >> type;
        std::cout << "Enter number of seats: ";
        std::cin >> seats;
        std::cout << "Enter Carplatenumber: ";
        std::cin >> carplatenumber;
        std::cout << "Enter Model: ";
        std::cin >> model;

        vehicles[i] = Car( manufacturer, type, seats, carplatenumber, model ) ;
    }

    // ...
}
Last edited on
emmm i dont get it .....
so in your coding it is actually storing in it with
 
vehicles[i]=Car(manufacturer,type,seats,carplatenumber,model);
Last edited on
but how am i going to print out all those with the get...
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/192211/
Topic archived. No new replies allowed.