CLASS HIERARCHY || EXP-8 || CS-1

write a program in C++ to implement the following class hierarchy class student to obtain roll number, class test to obtain marks scored in two different subjects, Class sports to obtain weightage (marks) in sports and class result to calculate the marks. The program must print the roll number of individual marks obtained in two subject, sports, and total marks

#include<iostream.h>
#include<conio.h>
class student
{
    int roll_no;
public:
    void get_no(int a) {
        roll_no = a;
    }
    void put_no(void)
    {
        cout << "roll_no:0" << roll_no;
    }
};
class test :public student
{
public:
    float s1, s2;
public:
    void get_marks(float x, float y)
    {
        s1 = x;s2 = y;
    }
    void put_marks(void)
    {
        cout << "marks obtained : \ns1=" << s1 << "\n s2=" << s2;
    }
};
class sports
{
public:
    int score;
    void get_score(int x)
    {
        score = x;
    }
    void put_score(void)
    {
        cout << "sports marks:" << score;
    }
};

class result :public test, public sports
{
    float tot;
public:
    void display(void)
    {
        tot = s1 + s2 + score;
        put_no();
        put_marks();
        put_score();
        cout << "total score=" << tot;
    }
};
void main()
{
    result st1;
    st1.get_no(101);
    st1.get_marks(39, 65);
    st1.get_score(29);
    st1.display();
    getch();
    clrscr();
}

Leave a Comment

Scroll to Top