Aim To write a c++ program to show multiple inheritance & polymorphism in same program.
Procedure In this c++ program there are two base classes and one derived class which is showing MULTIPLE INHERITANCE(Here a class can inherit from more than one classes). There are two Member Functions declared within the base class and are overriden by derived class. These member function are VIRTUAL FUNCTIONS. This program is for calculating Area for the Length and Breadth given in Integer Type and in Real type(Real numbers). Here,In main function For class rec there is one object created which is used to call the member functions of class rec and can also be used to call the member function of its base classes.
Program:
#include using namespace std; class value1 //base class 1 { public: virtual int area1() //virtual member function1 { cout<<"For integer values"; } }; class value2 //base class 2 { public: virtual float area2() //virtual member function2 { cout<<"For real values"; } };
class rec:public value1,public value2 //derived class { public: int area1(int len,int bth) //member function { return(len*bth); } float area2(float len,float bth) //member function { return(len*bth); }
}; int main() //main function { rec r; //object created int a,b; cout<<"enter integer values"; cin>>a>>b; cout<<"area is:"<>c>>d; cout<<"area is:"<<r.area2(c,d); //function calling return 0; }
Errors There are no errors found in this program. Result Output Enter integer values 5 8 area is:40 Enter real values 12.68 57.15 area is:724.664
Aim : To creat a program using multiple inheritance and polymorphism. Procedure : To creat multiple inheritance, we have to create two base class i.e. area and perimeter and one derived class i.e. rectangle. For polymorphism, we have to do function overriding. In my program i used run time polymorphism or also know as dyna,ic polymorphism. Program : #include using namespace std; class area { public: int getarea(int l,int b)
{ return l*b; } }; class perimeter { public: int getperimeter(int l, int b) { return 2*(l+b); } }; class rectangle : public area, public perimeter { int length; int breadth; public: rectangle() { length = 10; breadth = 15; } int area() { return area::getarea(length, breadth); } int perimeter() { return rectangle::getperimeter(length, breadth); } }; int main() { rectangle rt; cout <<"area : "<<rt.area() <<endl; cout <<"perimeter : "<<rt.perimeter()<<endl; return 0; } Output : Area = 150 Perimeter = 50 Error : 0 Results : I have successfully done my project.
AIM:- To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
PROCEDURE:- There are two base classes “odd” and ”even” one derived class(child class)”num”. which is known as MULTIPLE INHERITANCE as it allows child class to inherit from more than one base class. There are virtual functions used in both base classes which are then overrided in the derived class. This program is based on finding whether the number is odd or even.
Program: #include using namespace std; class odd { public: virtual int numtype1() { cout<<"for odd number"; }
}; class even { public: virtual int numtype2() { cout<<"for even number"; } }; class num:public odd,public even { public: int numtype1(int n1) { if(n1%2!=0) { cout<<"\nnumber is odd";
} }; int main() { num b; int x; cout<<"enter a number"; cin>>x; b.numtype1(x); b.numtype2(x); return 0; } Errors There are no errors found in this program. Error=0. Result o/p enter a number 5 Number is odd Not even
Aim:- to create a c++ program using multiple inheritance and dynamic polymorphism in same program. Procedure:- Multiple inheritance has two base classes and one derived class.It is a feature of c++ where a class can inherit from more than one class.. When two member functions are declared within a base class and are overridden with the help of a derived class that member function is called as virtual function. Program:- #include using namespace std; Class student { public: int rno,m1,m2; public: virtual int get details (); { cout<<"enter the roll no:"; cin>>rno; cout<<"enter the two marks:"; cin>>m1>>m2; } }; Class sports { protected: int sm; public: void get details () { cout<<"\n enter the sports marks:"; cin>>sm; } }; Class statement: public student,public sports { public: int tot,avg; void get details () { tot=(m1+m2+sm); avg=tot/3; cout<<"\n\n troll no :"<<rno<<"\n\taverage :"<<avg; } }; int main { statement obj; obj.get details(); ohh.get sm(); obj.display(); return 0; } Output:- Enter roll no -21 Enter two marks -9,8 Enter sports marks -10 Roll no-21 Total -27 Average -27/3
AIM:- To write a c++ program to show multiple inheritance & dynamic polymorphism in same program. Procedure:- This c++ program includes two base classes or parent classes and one derived class or child class. As we know when one class is derived from two base classes it is known as MULTIPLE INHERITANCE. So this program includes MULTIPLE INHERITANCE. There are two virtual functions declared in base classes and in derived class the virtual functions are overridden. This program is coverting temperature Fahrenheit to Celsius and Celsius to Fahrenheit . Program:- #include using namespace std; class fahrenheit { public: virtual float temp1() { cout<<"for fahrenheit to celsius"; }
}; class celsius { public: virtual float temp2() { cout<<"for celsius to fahrenheit"; } }; class temperature:public fahrenheit,public celsius { public: float temp1(float t1) { cout<<"In celsius:"<<5*(t1-32)/9;
}; int main() { temperature t; float a; cout<<"\nenter temprature in fahrenheit"; cin>>a; t.temp1(a); float b; cout<<"\nenter temprature in celsius"; cin>>b; t.temp2(b); return 0; } Errors:- There are no errors in this program. Result: o/p enter temperature in Fahrenheit 200 in Celsius:93.3333 enter temperature in celsius 40 in fahrenheit:104 AIM:- To write a c++ program to show multiple inheritance & dynamic polymorphism in same program. Procedure:- This c++ program includes two base classes or parent classes and one derived class or child class. As we know when one class is derived from two base classes it is known as MULTIPLE INHERITANCE. So this program includes MULTIPLE INHERITANCE. There are two virtual functions declared in base classes and in derived class the virtual functions are overridden. This program is coverting temperature Fahrenheit to Celsius and Celsius to Fahrenheit . Program:- #include using namespace std; class fahrenheit { public: virtual float temp1() { cout<<"for fahrenheit to celsius"; }
}; class celsius { public: virtual float temp2() { cout<<"for celsius to fahrenheit"; } }; class temperature:public fahrenheit,public celsius { public: float temp1(float t1) { cout<<"In celsius:"<<5*(t1-32)/9;
}; int main() { temperature t; float a; cout<<"\nenter temprature in fahrenheit"; cin>>a; t.temp1(a); float b; cout<<"\nenter temprature in celsius"; cin>>b; t.temp2(b); return 0; } Errors:- There are no errors in this program. Result: o/p enter temperature in Fahrenheit 200 in Celsius:93.3333 enter temperature in celsius 40 in fahrenheit:104
AIM – Write a program to create multiple inheritance with compile time polymorphism . PROCEDURE - In my program I used two base class (as in multiple inheritance we have to use more than one base class). First is monthly and the another is yearly. After that I made a subclass class , named income which inherits properties of base class (monthly and yearly). In both base class I used function overloading which is also a compile time polymorphism. In first I used function salary and in another I used function money. In main function I give value of each parameters.
#include using namespace std; class monthly { public: void salary(int x) { cout<<"monthly income of ID - A is:"<< x << endl; } void salary(float y) { cout<<"monthly income of ID - B is:"<< y << endl; } void salary(double z) { cout<<"monthly income of ID - C is:"<< z << endl; } void salary(int x, float y, double z) {cout<<"Four months income of ID - A,B and C is:"<< x << "," << y << "," << z << endl; } }; class yearly { public: void money(int x) { cout<<"yearly income of ID - A is:"<< x << endl; } void money(float y) { cout<<"yearly income of ID - B is:"<< y << endl; } void money(double z) { cout<<"yearly income of ID - C is:"<< z << endl; } void money(int x, float y, double z) {cout<<"Five years income of ID - A,B and C is:"<< x << "," << y << "," << z << endl; } }; class income : public monthly , public yearly { }; int main() { income obj1,obj2; obj1.salary(1000); obj1.salary(2000); obj1.salary(3000); obj1.salary(4000 , 8000 , 12000); obj2.money(12000); obj2.money(24000); obj2.money(36000); obj2.money(60000 , 120000 , 180000); return 0; }
Aim : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program
Procedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class. This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include using namespace std; class Base1 { public: int r; int p; void input() { cout<<"Enter Rupee/Rupees to convert into paisa"<>r; } void convert() { p=r*100; } }; class Base2 { public: virtual void display() { cout<<"this is base class"; } }; class derived: public Base1, public Base2 { public: void display() { cout<display(); return 0; }
Output : Enter Rupee/Rupees to convert into paisa 4 4is equal to 400paisa.
AIM: To create multiple inheritance and dynamic polymorphism Procedure: To create multiple inheritance we have to do two base class one is vehicle1and other is vehicle2 and one derive class that is scooter and in polymorphism we have to do function overriding. In my program I used run time polymorphism or also know as dynamic polymorphism . Program: #include using namespace std; class parenta { Public: Int x=45{ cout<<"Age of father A" << x << endl; cin>>x; } }; class parentb { public: int y=30; public: void mother() { cout<<"age of mother"<< y<< endl; cin>>y } }; class child:public parenta,public parentb { public:void father(void) { cout<<"age of father"<>x; } void mother(void) { cout<<"age of mother"<>y; } }; int main() { child obj,obj2; obj.father(); obj2.mother(); return 0; } Output: Age of father 45 Age of mother 35 Error: 0 Result: I have successfully done my program
AIM: to createa program using multiple inheritance and polymorphism. PROCEDURE: to create multiple inheritance we have to do two base class one is class A and other is class B one drive class that is classC and in polymorphism overriding. in my program i used run time polymorphism or also know polymorphism PROGRAM: #include using namespace std; class A { public: int x; void getx() { cout<<"enter value of x:";cin>>x; } }; class B { public: int y; void gety() { cout<<"enter value of y:";cin>>y; } }; class C: public A,public B { public: void sum() { cout<<"sum="<<x+y; } }; int main() { C obj1; obj1.getx(); obj1.gety(); obj1.sum(); return 0; } n as dynamic polymorphism. output: int x; int y; error: 0 result: i have successfully done my program.
Aim : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program
Procedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class. This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include using namespace std; class Base1 { public: int r; int p; void input() { cout<<"Enter Rupee/Rupees to convert into paisa"<>r; } void convert() { p=r*100; } }; class Base2 { public: virtual void display() { cout<<"this is base class"; } }; class derived: public Base1, public Base2 { public: void display() { cout<display(); return 0; }
Output : Enter Rupee/Rupees to convert into paisa 4 4 is equal to 400paisa.
Aim : : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
Procedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class. This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer. Program :
#include using namespace std; class Base1 { public: int r; int p; void input() { cout<<"Enter Rupee/Rupees to convert into paisa"<>r; } void convert() { p=r*100; } }; class Base2 { public: virtual void display() { cout<<"this is base class"; } }; class derived: public Base1, public Base2 { public: void display() { cout<display(); return 0; }
Output : Enter Rupee/Rupees to convert into paisa 4 4is equal to 400paisa.
Error : No errror found.
Result : This program execute successfully. https://drive.google.com/open?id=1ana6B2yIOm2CumPOGhvtBj3yYB9R8jOD
Aim : : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
Procedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class. This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer. Program :
#include using namespace std; class Base1 { public: int r; int p; void input() { cout<<"Enter Rupee/Rupees to convert into paisa"<>r; } void convert() { p=r*100; } }; class Base2 { public: virtual void display() { cout<<"this is base class"; } }; class derived: public Base1, public Base2 { public: void display() { cout<display(); return 0; }
Output : Enter Rupee/Rupees to convert into paisa 4 4is equal to 400paisa.
AIM: Write a C++ program to show multiple inheritance and dynamic polymorphism in same program PROCEDURE: This program consist of multiple inheritance and dynamic polymorphism where two integers described in two different base classes and is overrided in derived class and are added there. PROGRAM: #include using namespace std; class multiple { public: int x; public: void getvalue() { } }; class multiple2 { public: int y; public: void getdata() { } }; class derived:public multiple,public multiple2 { public: void getdata() { cout<<"enter value"; cin>>x; } void getvalue() { cout<<"get data "; cin>>y; }
void getproduct() { cout<<"product "<<x+y<<endl;
} }; int main() { derived d; d.getdata(); d.getvalue(); d.getproduct(); return 0; } OUTPUT: Get value 3 Get data 7 Get product 10 ERROR 0 Done program successfully.
INTRODUCTION Hadoop and Apache Spark both are big-data frameworks, but direct comparison of Hadoop and Spark is difficult because they do many of the same things, but are also non-overlapping in some areas. Hadoop is essentially a distributed data infrastructure, It distributes massive data collections across multiple nodes within a cluster of commodity servers, which means you don't need to buy and maintain expensive custom hardware. It also indexes and keeps track of that data, enabling big-data processing and analytics far more effectively than was possible previously. Spark, on the other hand, is a data-processing tool that operates on those distributed data collections; it doesn't do distributed storage Hadoop have many components of modules that work together to create the Hadoop framework. The primary Hadoop framework modules are: · Hadoop Common · ...
Dear students, Here im uploading study materials chapter wise. Follow your material one by one and report me if you have any queries. Chapter 1: Introduction about System Programming Chapter 2: 1 pass and 2 Pass Assembler Assembler Chapter 3: Macro & Linker Chapter 4 Compiler
Dear students, Here I'm uploading study material for unit 3 and 4 Follow the material in sequence order. Post your queries if you have any. Transport Layer Part 1 Transport Layer Part 2 Network Layer Routing Protocol
Aim
ReplyDeleteTo write a c++ program to show multiple inheritance & polymorphism in same program.
Procedure
In this c++ program there are two base classes and one derived class which is showing MULTIPLE INHERITANCE(Here a class can inherit from more than one classes).
There are two Member Functions declared within the base class and are overriden by derived class. These member function are VIRTUAL FUNCTIONS.
This program is for calculating Area for the Length and Breadth given in Integer Type and in Real type(Real numbers).
Here,In main function
For class rec there is one object created which is used to call the member functions of class rec and can also be used to call the member function of its base classes.
Program:
#include
using namespace std;
class value1 //base class 1
{
public:
virtual int area1() //virtual member function1
{
cout<<"For integer values";
}
};
class value2 //base class 2
{
public:
virtual float area2() //virtual member function2
{
cout<<"For real values";
}
};
class rec:public value1,public value2 //derived class
{
public:
int area1(int len,int bth) //member function
{
return(len*bth);
}
float area2(float len,float bth) //member function
{
return(len*bth);
}
};
int main() //main function
{
rec r; //object created
int a,b;
cout<<"enter integer values";
cin>>a>>b;
cout<<"area is:"<>c>>d;
cout<<"area is:"<<r.area2(c,d); //function calling
return 0;
}
Errors
There are no errors found in this program.
Result
Output
Enter integer values
5
8
area is:40
Enter real values
12.68
57.15
area is:724.664
This comment has been removed by the author.
ReplyDeleteWho is this ??? You posed as unknown
Deleteshe is priyanka kumari mandal
DeleteThis comment has been removed by the author.
ReplyDeleteAim : To creat a program using multiple inheritance and polymorphism.
ReplyDeleteProcedure :
To creat multiple inheritance, we have to create two base class i.e. area and perimeter and one derived class i.e. rectangle. For polymorphism, we have to do function overriding. In my program i used run time polymorphism or also know as dyna,ic polymorphism.
Program :
#include
using namespace std;
class area
{
public:
int getarea(int l,int b)
{
return l*b;
}
};
class perimeter
{
public:
int getperimeter(int l, int b)
{
return 2*(l+b);
}
};
class rectangle : public area, public perimeter
{
int length;
int breadth;
public:
rectangle()
{
length = 10;
breadth = 15;
}
int area()
{
return area::getarea(length, breadth);
}
int perimeter()
{
return rectangle::getperimeter(length, breadth);
}
};
int main()
{
rectangle rt;
cout <<"area : "<<rt.area() <<endl;
cout <<"perimeter : "<<rt.perimeter()<<endl;
return 0;
}
Output :
Area = 150
Perimeter = 50
Error : 0
Results : I have successfully done my project.
AIM:-
ReplyDeleteTo write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
PROCEDURE:-
There are two base classes “odd” and ”even” one derived class(child class)”num”. which is known as MULTIPLE INHERITANCE as it allows child class to inherit from more than one base class.
There are virtual functions used in both base classes which are then overrided in the derived class.
This program is based on finding whether the number is odd or even.
Program:
#include
using namespace std;
class odd
{
public:
virtual int numtype1()
{
cout<<"for odd number";
}
};
class even
{
public:
virtual int numtype2()
{
cout<<"for even number";
}
};
class num:public odd,public even
{
public:
int numtype1(int n1)
{
if(n1%2!=0)
{
cout<<"\nnumber is odd";
}
else
{
cout<<"\nnot odd";
}
}
int numtype2(int n2)
{
if(n2%2==0)
{
cout<<"\nnumber is even";
}
else
{
cout<<"\nnot even";
}
}
};
int main()
{
num b;
int x;
cout<<"enter a number";
cin>>x;
b.numtype1(x);
b.numtype2(x);
return 0;
}
Errors
There are no errors found in this program.
Error=0.
Result
o/p
enter a number
5
Number is odd
Not even
Aim:- to create a c++ program using multiple inheritance and dynamic polymorphism in same program.
ReplyDeleteProcedure:-
Multiple inheritance has two base classes and one derived class.It is a feature of c++ where a class can inherit from more than one class..
When two member functions are declared within a base class and are overridden with the help of a derived class that member function is called as virtual function.
Program:-
#include
using namespace std;
Class student
{
public:
int rno,m1,m2;
public:
virtual int get details ();
{
cout<<"enter the roll no:";
cin>>rno;
cout<<"enter the two marks:";
cin>>m1>>m2;
}
};
Class sports
{
protected:
int sm;
public:
void get details ()
{
cout<<"\n enter the sports marks:";
cin>>sm;
}
};
Class statement: public student,public sports
{
public:
int tot,avg;
void get details ()
{
tot=(m1+m2+sm);
avg=tot/3;
cout<<"\n\n troll no :"<<rno<<"\n\taverage :"<<avg;
}
};
int main
{
statement obj;
obj.get details();
ohh.get sm();
obj.display();
return 0;
}
Output:-
Enter roll no -21
Enter two marks -9,8
Enter sports marks -10
Roll no-21
Total -27
Average -27/3
AIM:-
ReplyDeleteTo write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
Procedure:-
This c++ program includes two base classes or parent classes and one derived class or child class.
As we know when one class is derived from two base classes it is known as MULTIPLE INHERITANCE. So this program includes MULTIPLE INHERITANCE.
There are two virtual functions declared in base classes and in derived class the virtual functions are overridden.
This program is coverting temperature Fahrenheit to Celsius and Celsius to Fahrenheit .
Program:-
#include
using namespace std;
class fahrenheit
{
public:
virtual float temp1()
{
cout<<"for fahrenheit to celsius";
}
};
class celsius
{
public:
virtual float temp2()
{
cout<<"for celsius to fahrenheit";
}
};
class temperature:public fahrenheit,public celsius
{
public:
float temp1(float t1)
{
cout<<"In celsius:"<<5*(t1-32)/9;
}
float temp2(float t2)
{
cout<<"In fahrenheit"<<(t2*9)/5+32;
}
};
int main()
{
temperature t;
float a;
cout<<"\nenter temprature in fahrenheit";
cin>>a;
t.temp1(a);
float b;
cout<<"\nenter temprature in celsius";
cin>>b;
t.temp2(b);
return 0;
}
Errors:-
There are no errors in this program.
Result:
o/p
enter temperature in Fahrenheit
200
in Celsius:93.3333
enter temperature in celsius
40
in fahrenheit:104
AIM:-
To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
Procedure:-
This c++ program includes two base classes or parent classes and one derived class or child class.
As we know when one class is derived from two base classes it is known as MULTIPLE INHERITANCE. So this program includes MULTIPLE INHERITANCE.
There are two virtual functions declared in base classes and in derived class the virtual functions are overridden.
This program is coverting temperature Fahrenheit to Celsius and Celsius to Fahrenheit .
Program:-
#include
using namespace std;
class fahrenheit
{
public:
virtual float temp1()
{
cout<<"for fahrenheit to celsius";
}
};
class celsius
{
public:
virtual float temp2()
{
cout<<"for celsius to fahrenheit";
}
};
class temperature:public fahrenheit,public celsius
{
public:
float temp1(float t1)
{
cout<<"In celsius:"<<5*(t1-32)/9;
}
float temp2(float t2)
{
cout<<"In fahrenheit"<<(t2*9)/5+32;
}
};
int main()
{
temperature t;
float a;
cout<<"\nenter temprature in fahrenheit";
cin>>a;
t.temp1(a);
float b;
cout<<"\nenter temprature in celsius";
cin>>b;
t.temp2(b);
return 0;
}
Errors:-
There are no errors in this program.
Result:
o/p
enter temperature in Fahrenheit
200
in Celsius:93.3333
enter temperature in celsius
40
in fahrenheit:104
AIM – Write a program to create multiple inheritance with compile time polymorphism .
ReplyDeletePROCEDURE - In my program I used two base class (as in multiple inheritance we have to use more than one base class). First is monthly and the another is yearly.
After that I made a subclass class , named income which inherits properties of base class (monthly and yearly).
In both base class I used function overloading which is also a compile time polymorphism.
In first I used function salary and in another I used function money.
In main function I give value of each parameters.
#include
using namespace std;
class monthly
{ public:
void salary(int x)
{ cout<<"monthly income of ID - A is:"<< x << endl;
}
void salary(float y)
{ cout<<"monthly income of ID - B is:"<< y << endl;
}
void salary(double z)
{ cout<<"monthly income of ID - C is:"<< z << endl;
}
void salary(int x, float y, double z)
{cout<<"Four months income of ID - A,B and C is:"<< x << "," << y << "," << z << endl;
}
};
class yearly
{ public:
void money(int x)
{ cout<<"yearly income of ID - A is:"<< x << endl;
}
void money(float y)
{ cout<<"yearly income of ID - B is:"<< y << endl;
}
void money(double z)
{ cout<<"yearly income of ID - C is:"<< z << endl;
}
void money(int x, float y, double z)
{cout<<"Five years income of ID - A,B and C is:"<< x << "," << y << "," << z << endl;
}
};
class income : public monthly , public yearly
{
};
int main()
{ income obj1,obj2;
obj1.salary(1000);
obj1.salary(2000);
obj1.salary(3000);
obj1.salary(4000 , 8000 , 12000);
obj2.money(12000);
obj2.money(24000);
obj2.money(36000);
obj2.money(60000 , 120000 , 180000);
return 0;
}
Sir my profile name is showing unknown after posting the comment. But, while commenting it is showing that "Comment as: sanushree139@gmail.com"
ReplyDeletesame here sir it is showing but posting as unknown
ReplyDeletesir my one is income
kratika joshi
Aim : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program
ReplyDeleteProcedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class.
This program is converting for rupees into paisa.
In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include
using namespace std;
class Base1
{
public:
int r;
int p;
void input()
{
cout<<"Enter Rupee/Rupees to convert into paisa"<>r;
}
void convert()
{
p=r*100;
}
};
class Base2
{
public:
virtual void display()
{
cout<<"this is base class";
}
};
class derived: public Base1, public Base2
{
public:
void display()
{
cout<display();
return 0;
}
Output :
Enter Rupee/Rupees to convert into paisa
4
4is equal to 400paisa.
Error : No errror found.
Result : This program execute successfully.
by Zaira Zahid
Delete
ReplyDeleteAIM: To create multiple inheritance and dynamic polymorphism
Procedure: To create multiple inheritance we have to do two base class one is vehicle1and other is vehicle2 and one derive class that is scooter and in polymorphism we have to do function overriding. In my program I used run time polymorphism or also know as dynamic polymorphism .
Program: #include
using namespace std;
class parenta
{
Public:
Int x=45{
cout<<"Age of father A" << x << endl;
cin>>x;
}
};
class parentb
{
public:
int y=30;
public:
void mother()
{
cout<<"age of mother"<< y<< endl;
cin>>y
}
};
class child:public parenta,public parentb
{
public:void father(void)
{
cout<<"age of father"<>x;
}
void mother(void)
{
cout<<"age of mother"<>y;
}
};
int main()
{
child obj,obj2;
obj.father();
obj2.mother();
return 0;
}
Output:
Age of father 45
Age of mother 35
Error: 0
Result: I have successfully done my program
AIM: to createa program using multiple inheritance and polymorphism.
ReplyDeletePROCEDURE: to create multiple inheritance we have to do two base class one is class A and other is class B one drive class that is classC and in polymorphism overriding. in my program i used run time polymorphism or also know polymorphism
PROGRAM: #include
using namespace std;
class A
{
public:
int x;
void getx()
{
cout<<"enter value of x:";cin>>x;
}
};
class B
{
public:
int y;
void gety()
{
cout<<"enter value of y:";cin>>y;
}
};
class C: public A,public B
{
public:
void sum()
{
cout<<"sum="<<x+y;
}
};
int main()
{
C obj1;
obj1.getx();
obj1.gety();
obj1.sum();
return 0;
} n as dynamic polymorphism.
output:
int x;
int y;
error: 0
result: i have successfully done my program.
Aim : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program
ReplyDeleteProcedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class.
This program is converting for rupees into paisa.
In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include
using namespace std;
class Base1
{
public:
int r;
int p;
void input()
{
cout<<"Enter Rupee/Rupees to convert into paisa"<>r;
}
void convert()
{
p=r*100;
}
};
class Base2
{
public:
virtual void display()
{
cout<<"this is base class";
}
};
class derived: public Base1, public Base2
{
public:
void display()
{
cout<display();
return 0;
}
Output :
Enter Rupee/Rupees to convert into paisa
4
4 is equal to 400paisa.
Error : No errror found.
Result : This program execute successfully.
Aim : : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
ReplyDeleteProcedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class.
This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include
using namespace std;
class Base1
{
public:
int r;
int p;
void input()
{
cout<<"Enter Rupee/Rupees to convert into paisa"<>r;
}
void convert()
{
p=r*100;
}
};
class Base2
{
public:
virtual void display()
{
cout<<"this is base class";
}
};
class derived: public Base1, public Base2
{
public:
void display()
{
cout<display();
return 0;
}
Output :
Enter Rupee/Rupees to convert into paisa
4
4is equal to 400paisa.
Error : No errror found.
Result : This program execute successfully.
https://drive.google.com/open?id=1ana6B2yIOm2CumPOGhvtBj3yYB9R8jOD
Aim : : To write a c++ program to show multiple inheritance & dynamic polymorphism in same program.
DeleteProcedure : In this c++ program there are two base classes and one derived class achieving Multiple Inheritance(where one sub class is inherited from more than one base classes). There are two member functions in one and one virtual function in another declared within the base classes and are overridden by derived class.
This program is converting for rupees into paisa. In main function we create a base pointer of the class where virtual function is created and an object of a derived class. In base pointer we store the address of derived object. then we call the member function through object. To achieve the dynamic polymorphism we have to call the virtual function through pointer.
Program :
#include
using namespace std;
class Base1
{
public:
int r;
int p;
void input()
{
cout<<"Enter Rupee/Rupees to convert into paisa"<>r;
}
void convert()
{
p=r*100;
}
};
class Base2
{
public:
virtual void display()
{
cout<<"this is base class";
}
};
class derived: public Base1, public Base2
{
public:
void display()
{
cout<display();
return 0;
}
Output :
Enter Rupee/Rupees to convert into paisa
4
4is equal to 400paisa.
Error : No errror found.
Result : This program execute successfully.
https://drive.google.com/open?id=1sCMDIIM2Y9dWxq38u4SGtKY7Dfje4Hx3
AIM:
ReplyDeleteWrite a C++ program to show multiple inheritance and dynamic polymorphism in same program
PROCEDURE:
This program consist of multiple inheritance and dynamic polymorphism where two integers described in two different base classes and is overrided in derived class and are added there.
PROGRAM:
#include
using namespace std;
class multiple
{
public:
int x;
public:
void getvalue()
{
}
};
class multiple2
{
public:
int y;
public:
void getdata()
{
}
};
class derived:public multiple,public multiple2
{
public:
void getdata()
{ cout<<"enter value";
cin>>x;
}
void getvalue()
{
cout<<"get data ";
cin>>y;
}
void getproduct()
{
cout<<"product "<<x+y<<endl;
}
};
int main()
{
derived d;
d.getdata();
d.getvalue();
d.getproduct();
return 0;
}
OUTPUT:
Get value 3
Get data 7
Get product 10
ERROR 0
Done program successfully.