C++ Lab assignment
C++ Lab assignment
16. 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 the base shape .Add to the
base class, a member function get_data() to initialise 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.
Area of rectangle = x*y
Area of triangle = ½*x*y
17. Write a program to read a list containing item name, item code and cost interactively and produce a
three column output as shown below:
Note that the name and code are left justified and the cost is right-justified with a precision of two
digits. Training zeros are shown. Also fill the unused spaces with hyphens.
18. Write a program to create a class EMP which have data member Name, Employee ID, contact number,
address, year of joining and department in which he/she is working with data member get and put. Create a
database of minimum 300 employees. Store and retrieve information on the basis of above configuration.
19. Create a class Inventory which performs the following operations on the file STOCK.DAT
a. Adds a new item to the file
b. Modifies the details of an item
c. Displays the contents of the file
20. Write a program to create a class EMP which have data member Name, Employee ID, contact number,
address, year of joining and department in which he/she is working with data member get and put. Create a
database of minimum 300 employees. Store and retrieve information on the basis of above configuration.
21. Write a function template for finding the minimum value contained in an array.
22. Write a class template to represent a generic vector. Include member function to perform the following
tasks:
a. To create the vector
b. To modify the value of a given element
c. To multiply by a scalar value
d. To display the vector in the form (10, 20, 30……)
23. Write a program with following:
a. A program to read two double type numbers from keyboard
b. A function to calculate the division of these two numbers
c. A try block to throw an exception when a wrong type of data is keyed in
d. try block to detect and throw an exception if the condition “divide by zero” occurs
e. Appropriate catch block to handle the exception thrown