I am stuck pls help me == I am just a beginner programmer

I need to store all car information using class and sub class.
The user can store 80cars information for maximum.
The user need to input the detail and print out the detail.

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
#include <iostream>
#include <string>
using namespace std;
class Vehicle{
	protected:
		string Manufacturer;
		string Type;
		int Seatnumber;
		int num;
		int* array;
		int sizeofarray;
	public:
		Vehicle(){
			Manufacturer="";
			Type="";
			Seatnumber=1;
		};
		Vehicle(int num,string manufacturer,string type,int seatnumber){
			Manufacturer=manufacturer;
			Type=type;
			Seatnumber=seatnumber;
			array=new int [num];
		};
		void setmanufacturer(string manufacturer){
			cout<<"Welcome!";
			for(int i=0;i<num;i++){
				cout<<"Enter your Car's Manufacturer "<<i+1<<" : ";
				cin>>this->array[i];
			}
		};
		void settype(string type);
		void setseatnumber(int seatnumber);
		string getmanufacturer(){
			int input=0;
			cout<<"Type in the value thath u want to look up: ";
			cin>>input;
			input-=1;
			cout<<array[input]<<endl;
	}
		string gettype();
		int getseatnumber();
};
class Car: public Vehicle{
	protected:
		string Carplatenumber;
		string Model;
	public:
		Car():Vehicle(){
		Carplatenumber="";
		Model="";	
		};
		Car(string carplatenumber, string model);
		void setcarplatenumber(string carplatenumber);
		void setmodel(string model);
		string getcarplatenumber();
		string getmodel();
		void display();
};
int main (){
	int size=0;
	cout<<"How many car of information to you want to key in: ";
	cin>>size;
	Vehicle v(size,"Volvo","MPV",4);
	v.setmanufacturer(size);
	v.getmanufacturer();
	return 0;
}
What are you stuck on? Please be specific.

You have a compile error.
Line 64: You're passing an int to setmanufacturer(), but setmanufacturer() is expecting a string.

You have some logical errors also.
Line 65: You call getmanufacturer() which returns a string, but you ignore the returned result.

Line 10: what is array for? As far as I can see, it serves no purpose.

You have no destructor for your Vehicle class, resulting in a memory leak because array is never released. Also, array is an uninitialized pointer if you use the default constructor.

Line 61: You ask the user how many cars they want to key in, but you don't input any car information from the user. You need a loop for this, plus an array or vector to store the cars.
Last edited on
i know that needed to be store but i just can't think how to write it out so i am stuck
I don't know if you've used vectors yet.
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Vehicle
{
	protected:
		string Manufacturer;
		string Type;
		int Seatnumber;
	public:
		Vehicle()
		{   Seatnumber=0;
		};
		Vehicle(const string & manufacturer,const string & type,int seatnumber)
		{   Manufacturer=manufacturer;
			Type=type;
			Seatnumber=seatnumber;
		};
		void setmanufacturer(string manufacturer)
		{   Manufacturer = manufacturer;
		};
		void settype(string type);
		void setseatnumber(int seatnumber);
		string getmanufacturer()
		{   return Manufacturer;
		}
		string gettype();
		int getseatnumber();
};
class Car: public Vehicle
{
	protected:
		string Carplatenumber;
		string Model;
	public:
		Car():Vehicle()
		{};
		Car(string carplatenumber, string model);
		void setcarplatenumber(string carplatenumber);
		void setmodel(string model);
		string getcarplatenumber();
		string getmodel();
		void display();
};
int main ()
{   int size=0;
	vector<Vehicle> vehicles;
	string  manufacturer;
	string  type;
	int     seats;
	
	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;
	    vehicles.push_back (Vehicle (manufacturer, type, seats));
	}
	return 0;
}

what is mean by vehices,pushback and also the vector

Last edited on
but how can i use an array to store all those information actually i need to use an array to store information
Sorry for just bothering you!
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/192200/
http://www.cplusplus.com/forum/beginner/192169/
Last edited on
Topic archived. No new replies allowed.