Cpp-Program for single inheritance

 Advanced C++ : Introduction to C++ & C++ Structures | by Khushboo Patel |  Medium

 

 //program for single inheritance
#include <iostream>
#include<conio.h>
class student
{
    private:
    int rollno;
    char name[30];
    public:
    void getdata()
    {
        cout<<"\n\t\tEnter rollno and name";
        cin>>rollno>>name;
    }
    void putdata()
    {
        cout<<"\n\t\tRollno="<<rollno;
        cout<<"\n\t\tName="<<name;
    }

};
    class marks:public student
    {
        private:
        int m1, m2, m3;
        int total;
        float avg;
        public:
        void getmark()
        {
            cout<<"\n\t\tEnter 3 subject marks";
            cin>>m1>>m2>>m3;
        }
        void calculate()
        {
            total=m1+m2+m3;
            avg=total/3;
        }
        void display()
        {
            cout<<"\n\t\tTotal="<<total;
            cout<<"\n\t\tAverage="<<avg;
        }
    };
    int main()
    {
        marks obj;
        clrscr();
        cout<<"\n\t\t\tOUTPUT";
        cout<<"\n\t\t\t------";
        obj.getdata();
        onj.getmark();
        obj.calculate();
        obj.putdata();
        onj.display();
        getch();
        return 0;
        
    }


                OUTPUT

                ------------

Enter rollno and name 1 Ram

Enter 3 subjects marks 99 98 100

Rollno=1

Nmae=Ram

Total=297

Average=99


Comments

Popular posts from this blog

DS - Representation of linked list in memory.

Cpp- Program for call by reference

NUMERICAL ABILITY