C LabAssignment2020
C LabAssignment2020
1. Write a C++ program to implement pure virtual function with following details:
Data members:
Float temp;
Function members
void setTempData(float)
Data members:
Float ctemp;
Function members
Override function changetemp() to convert Fahrenheit temperature into degree Celsius by using formula
C=5/9*(F-32) and display converted temperature
Data members:
Float ftemp;
Function members
Override function changetemp() to convert degree Celsius into Fahrenheit temperature by using
formula F=9/5*c+32 and display converted temperature
2.Create a base class called shape. Use this class to store two double type values that could be
used to compute the area of figures. Derive two specific classes called triangle and rectangle
from base shape. Add to the base class , a member function get_data() to initialize base class data
members and another member function display_area() to compute and display the area of figures.
Make display_area() as a virtual function and redefine this function in the derived class to suit
their requirements. Using these three classes, design a program that will accept dimensions of a
triangle or a rectangle interactively and display the area.
Remember the two values given as input will be treated as lengths of two sides in the case of
rectangles and as base and height in the case of triangle and used as follows:
Area of rectangle = x * y
Area of triangle = ½ *x*y
3.Create a base class called CAL_AREA(Abstract). Use this class to store float type values that
could be used to compute the volume of figures. Derive two specific classes called cone,
hemisphere and cylinder from the base CAL_AREA. Add to the base class, a member function
getdata ( ) to initialize base class data members and another member function display volume( )
to compute and display the volume of figures. Make display volume ( ) as a pure virtual function
and redefine this function in the derived classes to suit their requirements. Using these three
classes, design a program that will accept dimensions of a cone, cylinder and hemisphere
interactively and display the volumes. Remember values given as input will be and used as
follows:
Volume of cone = (1/3)πr2h
Volume of hemisphere = (2/3)πr3
Volume of cylinder = πr2h