Am currently working on a car dealer system. Am trying to design the system in a way that a user can view the number of vehicles available, the type, e.t.c and obviously the user can make a purchase.
At the moment am just trying to deal with the basics. Am trying to get the user to select between different the categories of car, vehicle and bus. If they selected car then the contents of the car file would be displayed and so on. I have kind of hit a wall and don't know where to next.
This is what i've done so far:
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
class Vehicle{//base class
protected:
int category;
string car;
public:
void select_category(){
cout<<"-----------VEHICLE PURCHASE SYSTEM----------"<<endl;
cout<<"To Select A Vehicle Category Enter a number. "<<endl;
cout<<"Enter 1 for Car"<<endl;
cout<<"Enter 2 for Motorcycle"<<endl;
cout<<"Enter 3 for Bus"<<endl;
cout<<"Enter Vehicle Category Number: ";
cin>>category;
if (category==1){
ifstream carfile ("Car File.txt");//open Car file
if(carfile.is_open())
{ while (! carfile.eof() )
{
getline (carfile,car);
cout << car << endl;
}
carfile.close();
}
}else if(category==2){
//open motorcycle file
}else if(category==3){
//open bus file
}
}//end function
};
class Car:public Vehicle{//car class
private:
public:
//void select_car();
// void display_cars(){
// if (category == 1){//open file and display cars.
// ifstream carfile("Car File.txt");
// if(carfile.is_open())
// { while (! carfile.eof() )
// {
// getline (carfile,car);
// cout << car << endl;
// }
// carfile.close();
// }
// }
// }
};
class Motorcycle:public Vehicle{
private:
string motorcycle;
public:
//void select_motorcycle();
};
class Bus:public Vehicle{
private:
string bus;
public:
//void select_bus();
};
int main(){
Vehicle V1;//selection object
// Car C1;//car object
V1.select_category();
// C1.display_cars();
return 0;
system("pause");
}
The problem is that when I run the program instead of it showing me the contents of the class file it just terminates. I want to get it to show me the contents of the file.