array of classes

I keep getting an undefined reference to `Vehicles::Vehicles()' whenever i use Vehicles to declare an object in my main program

also i cant seem to figure out how to initialize my array of classes.

Now that you've learned about classes, you've decided to expand the Vehicle struct from lab2 into a complete class. For now, you've decided to just store the following attributes of a vehicle: price, year and model. Write a computer program in C++ that stores Vehicles in an array and that can add, remove, print and list cars. The commands for adding, removing, printing and listing will come from a file specified on the command-line (Note: STDIN will NOT be used for this lab). Commands are as follows (fields are separated by tabs):
A <price> <year> <model> Add a new Vehicle.
R <price> <year> <model> Remove the specified Vehicle.
P <price> <year> <model> Print the specified Vehicle.
L List all of the Vehicles currently in the database.

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
 #include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include "Vehicles.h"
#ifndef VEHICLES_H
#define VEHICLES_H


using namespace std;


int main()

{
	
	Vehicles inArray[1024];
	Vehicles onecar;
	int numcars=0;
	char actionNeeded;
	
	ifstream inData;
	string infileName;
	
	cout << "Enter the input data file name:" << endl;
	
	cin >> infileName;
	
	inData.open(infileName.c_str());
	

	// make it a loop error message so user doesnt have to restart program. Annoying 
	if(!inData)
	{
		cerr << "Can't open: "  << infileName  << ". Program is stopping" << endl;
		return 1;
		
	}
	
	while (inData)
{

	
	inData>>actionNeeded;
	
	if( !inData)
	{
		break;
	}
		

switch(actionNeeded)
{
  case 'A':
    
    //Add cars into array, addcar function call
  {
	  for( int i=0; i<=numcars; i++)
	  {
	  inArray[i].setPrice();
	  inArray[i].setYear();
	  inArray[i].setModel();
	  }
	  numcars++;
		
	  
  }

  

    break;
  case 'R':
   // remove cars function call
 
  //removeCars(carInfo,inData ,numcars);
  
    break;
  
  case 'L': 
	//List cars function call
  
	
  
	//listCars(carInfo);
  
  break;
  
	case 'P':
		
	//printCars(carInfo[numcars],inData);
	//numcars++;
	
		
	break;

}
}

	


	
	return 0;


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

using namespace std; 

//class for my array data

class Vehicles
{
	public: 
		void	print(); 
		bool	compare(string inmodel, int inprice, int inyear);
		int		getYear();
		void	setYear(int in);
		int		getPrice(); 
		void	setPrice(int in); 
		string	getModel(); 
		void	setModel(string in);
		void	remove(string a, int b, int c);
        Vehicles(); 
		//	non default constructor
		//	Vehicles(char act, string mod, int pri, int yr); 
	private: 
		char actionNeeded; 
		string model; 
		int price; 
		int year; 
};


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 "Vehicles.h"  
  
Vehicles::Vehicles() 
{ 
    price = 0; 
} 
  
void Vehicles::print()  
{  
    cout << price;
	cout << year;
	cout << model;
}  
  
bool Vehicles::compare(string inmodel, int inprice, int inyear) 
{ 
    if(inmodel == model) { 
        if(inprice == price) { 
            if(inyear == year) { 
                return true; 
            } 
        } 
    } 
    return false; 
} 
  
int Vehicles::getYear() 
{ 
    return year; 
} 
  
void Vehicles::setYear(int in) 
{ 
    year = in; 
} 
  
int Vehicles::getPrice() 
{ 
    return price; 
} 
  
void Vehicles::setPrice(int in) 
{ 
    in >> price; 
} 
  
string Vehicles::getModel() 
{ 
    return model; 
} 
  
void Vehicles::setModel(string in) 
{ 
    model = in; 
} 
  
void Vehicles::remove(string a, int b, int c) 
{ 
    if(a == model) { 
        if(b == price) { 
            if(c == year) { 
                model = ""; 
                price = 0; 
                year = 0; 
            } 
        } 
    } 
} 
Last edited on
On line 61 in your main() function, you call the setYear() method, but you don't supply a parameter.
Last edited on
if im getting the data from an file then how does that work?
anyoneee
Topic archived. No new replies allowed.