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
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
October 11th, 2010 at 8:36 pm
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
December 17th, 2010 at 11:22 am
please give here vere easy program
&
send me in my email
January 28th, 2011 at 3:56 pm
the above program is very simple of the single program. i am join
this project very enjoy.
February 21st, 2011 at 7:01 pm
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
July 18th, 2011 at 10:07 pm
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
August 20th, 2011 at 1:32 pm
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();
}
August 20th, 2011 at 2:04 pm
\\ 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();
}