Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program that provides an example of inheritance using private data

Posted By: Mia Brown     Category: C++ Programming     Views: 3041

Write a program that provides an example of inheritance using private data.

Code for Program that provides an example of inheritance using private data in C++ Programming

#include<iostream.h>
#include<conio.h>
class stud
{
    int rno;
    char name[20];
    public:
        void getdata()
        {
            cout<<"Enter Your Roll Number ";
            cin>>rno;
            cout<<"Enter Your Name ";
            cin>>name;
        }
        void putdata()
        {
            cout<<"Roll Number is : "<<rno<<endl;
            cout<<"Name is : "<<name<<endl;
        }
};

class science : public stud
{
    int maths,sci;
    public:
        void getdata()
        {
            stud::getdata();
            cout<<"Enter Maths Marks ";
            cin>>maths;
            cout<<"Enter Science Marks ";
            cin>>sci;
        }
        void putdata()
        {
            stud::putdata();
            cout<<"Maths Marks are : "<<maths<<endl;
            cout<<"Science Marks are : "<<sci<<endl;
        }
};

class commerce :public stud
{
    int acc,stat;
    public:
        void getdata()
        {
            stud::getdata();
            cout<<"Enter Account Marks ";
            cin>>acc;
            cout<<"Enter Statistics Marks ";
            cin>>stat;
        }
        void putdata()
        {
            stud::putdata();
            cout<<"Account Marks are : "<<acc<<endl;
            cout<<"Statistics Marks are : "<<stat<<endl;
        }
};

main()
{
    clrscr();
    science s1;
    s1.getdata();
    s1.putdata();
    commerce c1;
    c1.getdata();
    c1.putdata();
    getch();
}




  
Share: 



Mia Brown
Mia Brown author of Program that provides an example of inheritance using private data is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!