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.

Recommended Answers

All 17 Replies

>The problem is that when I run the program instead of it showing
>me the contents of the class file it just terminates.
Probably because you've commented out all of the stub code that displays anything. The program isn't going to do something that you haven't written code to do. :icon_rolleyes:

I edited it and carried everything to the main function. Now what I need to do is create a functions in the classes that will enable purchasing.
*heads off to brain-storm*

hi , how can I see the complete program ? I couldnt found it here :(

>I couldnt found it here
that made me smile. thanks.

>I couldnt found it here
that made me smile. thanks.

im not student , and also I dont wanna study here !

i dont think so is funny!

my appologies.
What is it exactly that you're looking for?

hi , how can I see the complete program ? I couldnt found it here :(

I haven't done the entire program. Am still trying to work on it. So far it's features are very limited. I'll post up later.

>and also I dont wanna study here !
Then you don't need to see the complete code. :icon_rolleyes:

could someone please give me the full code for this program?
my lecturer asked me to do an assignment which is totally same with this one
the problem is i'm really weak in programming that requires me to do the whole program
please please i really need the full code asap

i need some feedbacks

> could someone please give me the full code for this program?
Seriously, what would be the point of that?

If you already know you're not going to make it to the end of the course, then just quit now and resume your search for a path which you can succeed in.

Programming isn't for everyone, and if your combination of natural talent + determination isn't going to get it done, there isn't much point in pretending otherwise.

Giving you the answers just prolongs the agony for everyone involved.

Next week, the problem will be harder, and you'll be even further behind than you are now.

firza_gee, salem is right...If you use the code given before and a work a bit...you will easily do it on your own....

i've tried to work on the program by putting my own coding in between.
but it ends up messing up things. that's why i thought i may get positive feedbacks in here.

anyway thanks u guys

be more specific about the parts you need help and i think that everyone will what he can to help you!

> i've tried to work on the program by putting my own coding in between.
So post something we can talk about.

There is no need to try to do the whole program at once. Pick one aspect of it and try to get that working. Then build on it.

> that's why i thought i may get positive feedbacks in here.
You'll get a much better response if you offer up some evidence that you're trying to do the work yourself.

Your first post was basically "hey geeks, I'm stupid, gimme the code".

before that i was trying to wrote some program like this not excat this one cause of this I want to see the complete program :) becuase I had a problem on class ! :(

But there is no such thing as a "standard" complete program to any given problem. How you might write the program has nothing to do with how I might write the program.

For example, I could easily use a bunch of techniques which would leave you just as baffled as you are now, and no further forward in understanding the problem.

> becuase I had a problem on class
So post what you have, and ask your specific question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.