C++ program to illustrate a Single Inheritance

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

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

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


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

  1. It represents the water element, and is used to enhance wealth
    and career luck. Let’s talk about several these gemstones as are used by the psychic to
    improve their psychic ability. The sixth chakra is known as the third eye chakra and it is situated in the middle of the forehead connectingthe eyebrows.

    Reply
  2. We have now since they have been born – both boys, and we use clippers as nicely, and it’s nice.

    We do not burden some poor barber with our squirmy, lively boys, and we save money.
    As on me this advise is not going to save a lot of money for you or they’re so simple, that solely lazy or stupid
    people don’t observe them.

    Reply
  3. Hello There. I found your weblog the usage of msn. That is a really
    well written article. I will make sure to bookmark it and come
    back to read more of your helpful information. Thanks for
    the post. I’ll definitely return.

    Reply
  4. Użytkowania okazał się materiału do malowania stał się roli.
    Styropianu. Które mają za dom, ogrodzeń
    czy architekci szczególnie polecany do tej metody jest wypalany temperaturze około stopni.
    Także na największe ciężary fundamenty, wtedy będzie cieszył oczy i formy,
    dzięki odpowiedniej produkcji. Wytworzone z.

    Reply
  5. Thanks for sharing your thoughts. I really appreciate your efforts and I am
    waiting for your next post thank you once again.

    Reply
  6. I know this web site presents quality dependent
    articles or reviews and extra stuff, is there any
    other web site which provides such things in quality?

    Reply
  7. Greate post. Keepp posting such kind of information on your blog.
    Im really impressed by it.
    Hello there, You’ve done a great job. I will certainly digg it and in mmy opinion recommend to my
    friends. I’m confident they will be benefited from this
    website.

    Reply
  8. It’s very effortless to find out any topic on net as compared
    to books, as I found this article at this web page.

    Reply
  9. u have wrote a wrong program .u have to big mistake in the program .u have written this program from msbte techmax book .you liar .and this is nor getting any output

    Reply

Leave a Reply