#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;
class Vehicle
{
public:
Vehicles();
void get_line(ifstream&);
void display_data();
private:
string make;
string model;
string plate;
string registration_date;
string keeper;
string license;
int wheels;
double weight;
bool is_taxi;
};
int main()
{
Vehicle temp;
vector<Vehicle> vehicles;
ifstream infile("data.txt");
//Provide simple error checking
if(!infile.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(ifstream)
{
//Load the .txt file 'line-at-a-time'
temp.get_line(infile);
vehicles.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=vehicles.size(); i<size; i++)
{
vehicles[i].display_data();
}
return 0;
}
well written object oriented approach to doing your assignent. the program will attempt to open a file, load the file into a vector, and display the information to the user. all you have to do is write a few simple function definitions.
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118