Struct as a class

I keep getting an "error: no matching function for call to 'Vehicles::setYear()'" for each of my function calls

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
104
#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;
	
Last edited on
Sounds like you created a struct in lab2 and your teacher wants you to turn it into a class and add additional features(add, remove, print and list). Converting from a struct to a class is pretty straight forward. Classes have everything private by default and structs have everything public by default. So if you wish to make things public you need public: before those things.

http://www.cplusplus.com/doc/tutorial/structures/
http://www.cplusplus.com/doc/tutorial/classes/
Topic archived. No new replies allowed.