member function overloading

Hi,

I am new to c++ and managed to write this much of code, i dont know what should I write inside of Vehicle and get_line functions. Could you point me how to do it? or provide a pseudocode please? I am confused a bit:

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
#include<iostream>
  #include<cstdlib>
  #include<string>
  #include<vector>
  #include <fstream>
      using namespace std;
      class Vehicle
      {
      
public:
        Vehicle();
	void get_line(ifstream&);
	void display_data();
private:
      char make[11];
      char model[21];
      char numberPlate[8];
      int registration_date[9];
      char registeredKeeper[21];
      int taxiLicence[11];
      int numWheels[9];
      double weight[9];
      bool is_taxi;
      };
      
      
  int main()
      {
      Vehicle temp;
      vector<Vehicle> vehicle;
      ifstream infile("vehicles.txt");


      //Provide simple error checking
      if(!infile.is_open())
      {
      cout << "\n\aError! File could not be opened!";
      cout << "\nFile may have been moved, renamed, or deleted...";
      exit(1);
      }
      
      //Load the text file into a vector of 'vehicle' objects
      while(infile)
      {
      
      //Load the .txt file 'line-at-a-time'

      temp.get_line(infile);
      vehicle.push_back(temp);
      }
 
      //We are done with the file i/o, so we can go ahead and clean-up the ifstream object
      
      infile.close();
      
      //Display file contents to the user
 
      for(int i=0, size=vehicle.size(); i<size; i++)
      {
	vehicle[i].display_data();
      }
      return 0;
      }
  

void Vehicle() {
}   //what should I put here?


void Vehicle::get_line(ifstream&)
{
 
}  //and what should I put here?
 

void Vehicle::display_data() //is this done correctly?
 {
 	cout<<make;
	cout<<"";
	cout<<model;
	cout<<"";
	cout<<weight;
	cout<<"";
	cout<<numberPlate;
	cout<<"";
	cout<<registration_date;
	cout<<"";
	cout<<registeredKeeper;
	cout<<"";
	cout<<taxiLicence<<"\n";
	
}


That would depend on the layout of the file and what you want to read in. The constructor ought to establish at least some sensible default values for the class.
Topic archived. No new replies allowed.