help me to solve problem in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vagandhi
    New Member
    • Aug 2008
    • 1

    #1

    help me to solve problem in C++

    Hello friends,
    I am having problem while running below program.

    If anyone can help me....

    // create class car
    #include<conio. h>
    #include<iostre am.h>
    #include<stdio. h>
    // class declaration
    class car
    {
    //data member
    private:
    char *c_nm;
    char *color;

    int model;
    float price;

    //member function
    public:
    void getcar(int n,char *nm,float p)
    {
    model=n;
    c_nm=nm;
    color=c;
    price=p;
    }
    void putcar()
    {
    cout<<endl<<"mo del :="<<model;
    cout<<endl<<"na me :="<<c_nm;
    cout<<endl<<"co lor :="<<color;
    cout<<endl<<"pr ice :="<<price;
    }
    };
    void main()
    {

    int i;
    char *nm1;
    char *c1;
    float p1;
    clrscr();

    car c11; //object of class
    cout<<"enter model:=";
    cin>>i;
    cout<<"enter name:=";
    cin>>nm1;

    cout<<"enter color:=";
    cin>>c1;
    cout<<"enter price:=";
    cin>>p1;

    c11.getcar(i,nm 1,p1);
    c11.putcar();
    getch();
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Firstly, dont use iostream.h...in stead use iostream and using namespace std; for that

    There are few simple compiler issues...
    Try solving that


    Raghu

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by vagandhi
      If anyone can help me....
      Care to tell *what* actually is wrong? Doesn't it compile? Doesn't it do what it's
      supposed to do? Does it crash? Or do you want us to guess? Are deamons
      flying out of your nose?

      kind regards,

      Jos

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        One problem you are having is that your class data membewrs are pointers but you do not appear to be allocating any memory for them to point at.

        Comment

        Working...