Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Wednesday, April 21, 2010

This program is used to demonstrate multiple inheritance. (C++)


This program is used to demonstrate multiple inheritance. (C++)
 
Though the program may not be as important the concept of multiple inheritence is. This concept should be very well understood by the students as this will be helpfull in the long run. 
 
#include< iostream.h>
#include< conio.h>
 
 
class item
{
private:
char title[20];
float price;
public:
 
void getdata()
{
cout< < endl< < "Enter name and cost ::";
cin>>title>>cost;
}
 
 
void displaydata()
{
cout< < endl< < "name and cost ::";
>cout< < title< < "\t"< < cost;
}
};
 
 
class sales
{
private:
float salesfig[3];
public:
void getdata()
{
cout< < endl< < "Enter sales figure for three months ::";
> for(inti=0;i< 3;i++)
cin>> salesfig[i];
}
 
 
void displaydata()
{
cout< < endl< < "Sales figure for three months ::";
> for(inti=0;i< 3;i++)
cout< < salesfig[i]< < "\t";
> }
};
 
 
class hwitem : private item,private sales
{
private:
char category[10];
char oem[10];
public:
 
void getdata()
{
 
item:: getdata();
cout< < endl< < "Enter category and Oem ::";
cin>>category>>oem;
 
sales::getdata();
}
 
 
void displaydata()
{
 
item:: displaydata();
cout< < endl< < "Category and Oem ::";
cout< < category< < "\t"< < oem;
 
sales::displaydata();
}
};
 
 
class switem:private item, private sales
{
private:
char category[10];
char os[10];
public:
void getdata()
{
item::getdata();
cout< < endl< < "Enter the Category and Os ::";
>cin>>category>>os;
sales::getdata();
}
void displaydata()
{
item::displaydata();
cout< < endl< < "Category and Os ::";
cout< < category< < "\t"< < os;
sales::displaydata();
}
};
 
void main()
{
clrscr();
 
 
hwitem h1,h2;
h1.getdata();
h1.displaydata();
h2.getdata();
h2.displaydata();
 
 
switem s1,s2;
s1.getdata();
s1.displaydata();
s2.getdata();
s2.displaydata();
}
 
 
 
 

Related Posts by Categories



0 comments:

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP