I still stuck in here anyone help me

I need to store array in class to store 80 cars information for maximum and i need to print out the details.

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
#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)
		{   cout << "Enter manufacturer: ";
	   	 	cin >> manufacturer;
		};
		void settype(string type)
		{	cout << "Enter vehicle type: ";
	    	cin >> type;
		};
		void setseatnumber(int seatnumber)
		{	cout << "Enter number of seats: ";
	    	cin >> seats;
		};
		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)
		{	cout << "Enter Carplatenumber: ";
	    	cin >> carplatenumber;
		};
		void setmodel(string model)
		{	 cout << "Enter Model: ";
	    	 cin >> model;	
		};
		string getcarplatenumber()
		{	return Carplatenumber;	
		};
		string getmodel()
		{	return Model;	
		};
		void display();
};
int main ()
{   int size=0;
	Car vehicles[80];
	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++)
	{   
	    vehicles.setmanufacturer();
	    vehicles.settype();
	    vehicles.setseatnumber();
	    vehicles.setcarplatenumber();
	    vehicles.setmodel();
	}
	cout<<"Which Car's detail do u want to view: ";
	cin>>
	return 0;
}
closed account (48T7M4Gy)
Consider the problem this way.
1. A particular 'car' is an instance of a Vehicle.
2. A 'garage' is an instance of a Vehicle_Store, which has a key attribute of an data array of some sort with capacity for 80 Vehicle objects and a store/remove/retrieve set of methods as gets and sets as required.

So instead of a single class, you need two.
but i need to do a single that with a sub class
by the way what do u mean by that i dont get it
why do we need to remove it
Am i doing the right thing with this
 
Car vehicles[80]
closed account (48T7M4Gy)
but i need to do a single that with a sub class

It's up to you. There are lot's of ways to skin a cat. A Car is certainly a sub-class of Vehicle but I think in terms of simplicity and clarity a Vehicle_Store is better treated separately.

by the way what do u mean by that i dont get it

If I had commented that you don't get it, I would probably be able to answer you.

Am i doing the right thing with this
Car vehicles[80]

If you just want to use a simple array then what you have is fine. The advantage of the object -oriented approach is a separate class for the store is more flexible.

(One of the best learning modes for your array is just try it out. 2 or 3 cars instead of 80 makes that aspect even easier. Just having make and model attributes for a car makes it even easier to test the ideas, fill out in more detail later.)

why do we need to remove it

Only you know what is appropriate for your program. It's open-ended. Removal could be modelling a number of activities in possible systems - a car taken out of the garage to be sold, junked, painted, polished, stolen, rented out, loaned to a friend, out for repair and other endlessly possible scenarios. Or maybe cars once added to the list, never come off it. There for eternity.



Last edited on
oo ok thx ~~~~
closed account (48T7M4Gy)
www.cplusplus.com/forum/beginner/192200/
www.cplusplus.com/forum/beginner/192169/
Topic archived. No new replies allowed.