Lab 2 c
Lab 2 c
UNIVERSITY OF ENGINEERING
AND TECHNOLOGY, LAHORE
Question: 1
Write C++ code that defines a Book class comprising private member variables for title,
author, and publication year. Display the information of 5 books.
Question: 2
Write C++ code, in which a Triangle class is declared, featuring private attributes for base and
height. Public member function calculateArea. And display the area of triangle.
Question: 3
Design a class that holds the following personal data: name, address, age, and phone
number. Write appropriate info function. Creates three instances of it. One instance should
hold your information, and the other two should hold your friends’ or family members’
information.
Question: 4
Design a class for a widget manufacturing plant. If 10 widgets may be produced each hour,
the class object will calculate how many days it will take to produce any number of widgets.
(The plant operates two shifts of eight hours each per day.) Write a program that asks the
user for the number of widgets that have been ordered and then displays the number of
days it will take to produce them. Hint: widgetsPerDay = widgetsPerHour * hoursPerShift *
shiftsPerDay.
Question: 5
Design a class called Date. The class should store a date in three integers: month, day, and
year. There should be member functions to print the date in the following forms:
• 12/25/10
• December 25, 2010
• 25 December 2010
Demonstrate the class by writing a complete program and implementing it.
Department of Computer Science, New Campus
UNIVERSITY OF ENGINEERING
AND TECHNOLOGY, LAHORE
Input Validation: Do not accept values for the day greater than 31 or less than 1. Do not
accept values for the month greater than 12 or less than 1.