Inheritance 2
Inheritance 2
Define a subclass Wages to compute the monthly wages for the worker. The
details/specifications of both the classes are given below:
Class name: Worker
Data Members/instance variables:
Name: to store the name of the worker
Basic: to store the basic pay in decimals
Member functions:
Worker (…): Parameterised constructor to assign values to the instance
variables
void display (): display the worker’s details
Class name: Wages
Data Members/instance variables:
hrs: stores the hours worked
rate: stores rate per hour
wage: stores the overall wage of the worker
Member functions:
Wages (…): Parameterised constructor to assign values to the instance
variables of both the classes
double overtime (): Calculates and returns the overtime amount as
(hours*rate)
void display (): Calculates the wage using the formula wage = overtime
amount + Basic pay and displays it along with the other details
Specify the class Worker giving details of the constructor () and void display
( ). Using the concept of inheritance, specify the class Wages giving details
of constructor ( ), double-overtime () and void display (). The main ()
function need not be written.
Answer:
Using the concept of inheritance, specify the class Bill giving details of the
constructor(), void cal() and void show().Assume class Detail has been
defined.
THE MAIN ( ) FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.
Answer:
Specify the class Perimeter giving details of the constructor (…), double
Calculate and void show (). Using the concept of inheritance, specify the
class Area giving details of the constructor (…), void doarea () and void show
().Assume class Perimeter has been defined. The main function and
algorithm need not be written.
Answer:
A superclass Stock has been defined to store the details of the stock of a
retail store. Define a subclass Purchase to store the details of the items
purchased with the new rate and updates the stock. Some of the members
of the classes are given below:
Class name: Stock
Data members/instance variables:
item: to store the name of the item
qt: to store the quantity of an item in stock
rate: to store the unit price of an item
amt: to store the net value of the item in stock
Member functions:
Stock (…): parameterized constructor to assign values to the data members
void display(): to display the stock details
Specify the class Stock, giving details of the constructor() and void display().
Using the concept of inheritance, specify the class Purchase, giving details of
the constructor(), void update() and void display().Assume class Stock has
been defined.
The main function and algorithm need not be written.
Answer: