C++ program to illustrate a Single Inheritance

Saturday, March 13th, 2010

SINGLE INHERITANCE

AIM:
A program to illustrate a single inheritance. We have a base class B and a derived class D. The class B contains one private data member, one public data member and three public member functions. The class D contains one private data member and two public member functions

ALGORITHAM:

• Start the process
• Invoke the base class B
• Invoke the derived class D using public derivation
• Get the input data
• Display the inputted data
• Call the derived classes member functions
o Assign a new value for base classes data member
• Display the outputs
• Stop the process

PROGRAM

#include<iostream.h>
#include<conio.h>
class B
{
int a;
public:
int b;
void get_ab();
int get_a();
void show_a();
};
class D: private B
{
int c;
public:
void mul();
void display();
};
void B::get_ab()
{
cout<<"Enter Values for a and b";
cin>>a>>b;
}
int B::get_a()
{
return a;
}
void B::show_a(){
			cout<<"a= "<<a<<"\n";
		}
void D::mul()
{
			get_ab();
			c=b*get_a();
       	}
void D:: display()
{
show_a();
cout<<"b= "<<b<<"\n";
cout<<"c= "<<c<<"\n\n";
}
void main()
{
			clrscr();
			D d;
			d.mul();
			d.display();
			d.mul();
			d.display();
			getch();
		}

OUTPUT

A=5
A=5
B=10
C=50

A=5
B=20
C=100

Avatar of Ranjith

Author Name :
Ranjith

Total : 9 Comments


9 Responses to “C++ program to illustrate a Single Inheritance”

  1. Besides things such as climbing stairs and parking far away, there are a variety of enjoyable methods to help make your daily tasks possibilities to exercise and burn fat

  2. Akhil says:

    please give here vere easy program

    &

    send me in my email

  3. the above program is very simple of the single program. i am join
    this project very enjoy.

  4. ameen sayed says:

    hi sir my name is ameen syd
    & i am B C S IV sem student in aurangabad (MH)

    PLEASE SIR GIVE ME A SIMPLE PROGRAME IN MY E mail ID
    THANK U SO MUCH

    PLZ YOUR GIADANCE IS MUST SIR

  5. this program really very easy. sir i want to another simple
    program of single inheritance and multipal inheritance please
    sir send me on this id krishango@gmail.com

  6. meher sharan says:

    this program for find out factorial value by using for multiple inheritance
    #include
    #include
    class F
    {
    protected:
    int num;
    float fact=1;
    public:
    void dispval;
    };
    class B
    {
    protected:
    int num;
    int table;
    public:
    void show(void)
    };
    class P:: F:B(void)
    {
    void inputval();
    void dispval();
    };
    void p::F
    {
    cout<>num;
    for(int i=1;i<=num;i++)
    {
    fact=fact*i;
    }
    cout<<"\n";
    }
    void:: dispval()
    {
    cout<<"\n "<<fact;
    }
    class q:inputval()
    {
    cout<>num;
    for(int i=1;i<=10;i++)
    {
    table=num*i;
    }
    cout<<"\n ";
    }
    void F::p:q
    {
    dispval();
    }
    void main()
    {
    F f;
    f.dispval();
    f.inputval();
    f.showval();
    getch();
    }

  7. meher sharan says:

    \\ this program for find out pay_roll by using with Array
    #include
    #include
    struct payroll
    {
    char name[10],address[10];
    char desig,city;
    int ta,da,hra,in_tax;
    int salary;
    int net_salary;
    };
    void main()
    {
    int i;
    for(int i=1;i<=10;i++)
    struct payroll p1;
    cout<>name;
    cout<>address;
    cout<>desig;
    cout<>city;
    cout<>salary;
    p1.ta=p1.salary*2/100;
    p1.da=p1.salary*4/100;
    p1.hra=p1.salary*8/100;
    p1.in_tax=p1.salary*1/100;
    net_salary=p1.ta+p1.da+p1.hra+p1.tax;
    cout<<"\n *************Employees Net_Salary is ="<<net_salary;
    getch();
    }

  8. Subash says:

    Sir,i am looking for job now.Give me some useful information for my technical interview.

  9. Mirilla596 says:

    really useful , thanks for sharing
    I will mark this post to find out more

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: