In this, we are going to see a program to calculate payable amount of Tenant to Owner using Multiple Inheritance in C++ Programming Language.Â
The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<conio.h>
class owner
{
public:
int flatno;
char oname[50];
void getownerdetails()
{
cout << "Enter Owner details:" << endl;
cout << "Enter Flat No: ";
cin >> flatno;
cout << "Enter Owner Name: ";
cin >> oname;
}
};
class tenant
{
public:
int lengthofcontract;
double rent;
char tname[50];
char ch = 'Y';
void gettenantdetails()
{
cout << "\n***Enter Tenant details***" << endl;
cout << "Enter Tenant's Name: ";
cin >> tname;
cout << "Enter Tenant's length of Contract: ";
cin >> lengthofcontract;
}
void getrent()
{
cout << "Is tenant sharing the flat? [Y/N]: ";
cin >> ch;
(ch == 'Y') ? rent = 18000.00 : rent = 25000.00;
}
};
class displaydata : public owner, public tenant
{
public:
void display()
{
cout << tname << " will pay Rs. " << rent << " monthly to " << oname << " for " << lengthofcontract << " years.";
}
};
void main()
{
clrscr();
displaydata obj1;
obj1.getownerdetails();
obj1.gettenantdetails();
obj1.getrent();
obj1.display();
getch();
}
//...........Coded by Ananya Vidyadharan
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class owner
{
public:
int flatno;
string oname;
void getownerdetails()
{
cout << "Enter Owner details:" << endl;
cout << "Enter Flat No: ";
cin >> flatno;
cout << "Enter Owner Name: ";
cin >> oname;
}
};
class tenant
{
public:
int lengthofcontract;
double rent;
string tname;
char ch = 'Y';
void gettenantdetails()
{
cout << "\n***Enter Tenant details***" << endl;
cout << "Enter Tenant's Name: ";
cin >> tname;
cout << "Enter Tenant's length of Contract: ";
cin >> lengthofcontract;
}
void getrent()
{
cout << "Is tenant sharing the flat? [Y/N]: ";
cin >> ch;
(ch == 'Y') ? rent = 18000.00 : rent = 25000.00;
}
};
class displaydata : public owner, public tenant
{
public:
void display()
{
cout << tname << " will pay Rs. " << rent << " monthly to " << oname << " for " << lengthofcontract << " years.";
}
};
int main()
{
displaydata obj1;
obj1.getownerdetails();
obj1.gettenantdetails();
obj1.getrent();
obj1.display();
return 0;
}
//...........Coded by Ananya Vidyadharan
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP