Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Hey Guys , I am having a problem with the following code , please help !?

the code is follows :

#include<iostream.h>

#include<conio.h>

#include<iomanip.h>

class student

{

protected :

int rollno;

public:

void get_roll()

{

cout<<"\nEnter Roll No";

cin>>rollno;

}

void put_roll()

{

cout<<"\nRoll No - "<<rollno;

}

};

class test : public student

{

protected:

int m1,m2;

public:

void get_mark()

{

cout<<"\nEnter marks of two subjects";

cin>>m1>>m2;

}

void put_mark()

{

cout<<"\nm1 = "<<m1;

cout<<"\nm2 = "<<m2;

}

};

class sport

{

protected:

int score;

public:

void get_score()

{

cout<<"\nEnter score";

cin>>score;

}

void put_score()

{

cout<<"\nscore = "<<score;

}

};

class result : public test , public sport

{

private :

int total;

public:

void procdata()

{

total = m1 + m2 + score;

}

void put_total()

{

cout<<"\nTotal = "<<total;

}

};

void main()

{

clrscr();

result x;

x.get_roll();

x.get_mark();

x.get_score();

x.procdata();

x.put_roll();

x.put_mark();

x.put_score();

x.put_total();

}

Error :

After i enter the roll no, marks of two subjects and score , the computers gets back to code window , and doesnot execute the complete program , i am not getting why exactly is it happening , but do help !

Update:

Well , Syed , it did not work for me , the compler or Turbo C++ 3.0 , which i use still leaps out before completeley executing the program , do help , if u can , and thanx for the answer !

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    I have debugged your code in Dev C++, and commented on errors.

    #include<iostream> // iostream.h includes just one file... i am including folder

    #include<conio.h>

    //#include<iomanip.h> // No need to use it

    using namespace std; // For using standard console functions

    class student

    {

    protected :

    int rollno;

    public:

    void get_roll()

    {

    cout<<"\nEnter Roll No";

    cin>>rollno;

    }

    void put_roll()

    {

    cout<<"\nRoll No - "<<rollno;

    }

    };

    class test : public student

    {

    protected:

    int m1,m2;

    public:

    void get_mark()

    {

    cout<<"\nEnter marks of two subjects";

    cin>>m1>>m2;

    }

    void put_mark()

    {

    cout<<"\nm1 = "<<m1;

    cout<<"\nm2 = "<<m2;

    }

    };

    class sport

    {

    protected:

    int score;

    public:

    void get_score()

    {

    cout<<"\nEnter score";

    cin>>score;

    }

    void put_score()

    {

    cout<<"\nscore = "<<score;

    }

    };

    class result : public test , public sport

    {

    private :

    int total;

    public:

    void procdata()

    {

    total = m1 + m2 + score;

    }

    void put_total()

    {

    cout<<"\nTotal = "<<total;

    }

    };

    int main() // main() has to be of return type int.

    {

    system("cls"); //clrscr(); // Consider using native commands for optimizing code.

    result x;

    x.get_roll();

    x.get_mark();

    x.get_score();

    x.procdata();

    x.put_roll();

    x.put_mark();

    x.put_score();

    x.put_total();

    system("pause"); // You need to pause the screen to see the code...!

    return(0); // You must return integer in main()...preferably 0.

    }

    If you are beginner, please use Dev C++. Its easy to use.

    Source(s): I am a Professional C++ programmer having lot of experience in OOP based game programming.
Still have questions? Get your answers by asking now.