Assignment 04

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ASSIGNMENT IV

(Inheritance)

1. Write a program that defines a shape class with a constructor that gives value to width
and height. Then define two sub-classes triangle and rectangle, that calculate the area
of the shape. In the main, define two objects a triangle and a rectangle and then call
the area () function.

2. Write a program with a mother class animal. Inside it define a name and an age
variables, and set_value () function. Then create two sub class Zebra and Dolphin
which write a message telling the age and name of animal, also giving some extra
information for both sub class (e.g. place of origin).place of origin of zebra is Earth
and place of origin of dolphin is water.

3. Write a program as per following details


Create one base class Teacher
Data members Name, Department, College name, Email id.
Create sub classes for Math Teacher, English Teacher, and Science Teacher Data
member Qualification, Expertise and salary.
Display following details for each teacher
Name:
Department:
College name:
Email id:
Qualification:
Expertise:
Salary:

4. Write a program as per following details


Create one base class MEDICINE with following data members
Category- (i.e. stimulants, inhalants, cannabinoids)
Date_of_manufacture, Company name
Create one sub class TABLET derived from MEDICINE with following data members
Tablet name, Price
Create one sub class PainReliever derived from TABLET with data member
Dosage_units: i.e( 1 or 2 or 3)
Side_effects : i.e (Nausea, Drowsiness, Dizziness.) Use_within_days: i.e(10 or
20 or 30).
Use appropriate member function for setting and Getting above details and display
details in main function.
5. Write a program as per following details
Create one base class HOTEL with following data members
Hotel_name,
Hotel_type i.e(Three star,five star)
City
Hotel_rate i.e(2000,3000,5000)
Create one base class FLIGHT with following data members
Flight_no
Source city
Destination city
Seat no
Create one sub class PASSENGER derived from HOTEL and FLIGHT with following
data members Name, Age, city
Write appropriate member functions in each class and display all information in main

6. Write a program as per following details


Create one base class PERSON with following data members
Name, College name
Create one sub class STUDENT derived from PERSON with following data members
Student_id , Marks of five subject, percentage Member function:
showResult( )-Calculate total,percentage and finding class(Dist,First,second,pass)
Create one sub class EMPLOYEE derived from PERSON with following data members
Emp_id, qualification , basic salary
Member function to calculate Net salary and print Net salary
DA=189% of Basic salary
HRA=10% of Basic salary
TA=500
Income tax=5 % of basic salary, if basic salary >50000
Income tax=0, if Basic salary <=50000

Netsalary=(basicsalary+da+hra+ta) - income tax


Write appropriate setter function in each class and display detail of student and
employee in main.

You might also like