Calculate Payable Amount of Tenant to Owner || Single Inheritance || C++

In this program, we are going to Calculate Payable amount of Tenant to Owner using Single 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;
    string OName;
    void GetOwnerDetails()
    { //to get the owner and flat details
        cout << "Enter Owner details: \n";
        cout << "Enter Flat No: ";
        cin >> flatNo;
        cout << "Enter Owner Name: ";
        cin >> OName;
    }
};

class Tenant : public Owner
{
    public:
    int lengthOfContract;
    string TName;
    void GetTenantDetails()
    { //Tenant will inherit the properties of Owner
        cout << "Enter Tenant details:- \n";
        cout << "Enter Tenant's Name: ";
        cin >> TName;
        cout << "Enter Tenant's length of Contract: ";
        cin >> lengthOfContract;
    }

    double GetRent()
    {
        char ch = 'Y';
        cout << "Is tenant sharing the flat? [Y/N]: ";
        cin >> ch;
        return (ch == 'Y') ? 18000.00 : 25000.00;
    }
};

void main()
{
    clrscr();
    Tenant obj;
    obj.GetOwnerDetails();
    obj.GetTenantDetails();
    cout << obj.TName << " will pay Rs. " << obj.GetRent() << " to " << obj.OName << " for " << obj.lengthOfContract << " years.";
    getch();
}

//...........Coded by Shreya Idate

 

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()
    { //to get the owner and flat details
        cout << "Enter Owner details: \n";
        cout << "Enter Flat No: ";
        cin >> flatNo;
        cout << "Enter Owner Name: ";
        cin >> OName;
    }
};

class Tenant : public Owner
{
    public:
    int lengthOfContract;
    string TName;
    void GetTenantDetails()
    { //Tenant will inherit the properties of Owner
        cout << "Enter Tenant details:- \n";
        cout << "Enter Tenant's Name: ";
        cin >> TName;
        cout << "Enter Tenant's length of Contract: ";
        cin >> lengthOfContract;
    }

    double GetRent()
    {
        char ch = 'Y';
        cout << "Is tenant sharing the flat? [Y/N]: ";
        cin >> ch;
        return (ch == 'Y') ? 18000.00 : 25000.00;
    }
};
int main()
{
    Tenant obj;
    obj.GetOwnerDetails();
    obj.GetTenantDetails();
    cout << obj.TName << " will pay Rs. " << obj.GetRent() << " to " << obj.OName << " for " << obj.lengthOfContract << " years.";
    return 0;
}

//...........Coded by Shreya Idate
    

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post