0% found this document useful (0 votes)
13 views3 pages

Lab 4

The document outlines a series of programming tasks for a C++ course at the University of Engineering and Technology, Lahore. It includes the creation of various classes such as Person, Car, Product, clockType, and Rectangle, with specific requirements for constructors, destructors, memory management, and deep copying. Each task emphasizes the importance of separate declaration and definition of member functions, along with demonstrating the use of these classes in a main function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Lab 4

The document outlines a series of programming tasks for a C++ course at the University of Engineering and Technology, Lahore. It includes the creation of various classes such as Person, Car, Product, clockType, and Rectangle, with specific requirements for constructors, destructors, memory management, and deep copying. Each task emphasizes the importance of separate declaration and definition of member functions, along with demonstrating the use of these classes in a main function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computer Science, New Campus

UNIVERSITY OF ENGINEERING
AND TECHNOLOGY, LAHORE

Lab 4 Target CLO2, CLO 3


Separate declaration and definition of member functions
Example: 1

Circle.h Header

Circle.cpp – implementation
Department of Computer Science, New Campus
UNIVERSITY OF ENGINEERING
AND TECHNOLOGY, LAHORE

TestCircle.cpp – main

Note: Implement files with separate declarations and implementations.


Question: 1
Write a C++ program to create a Person class that represents individuals with a name and an
age. The class should include constructors to initialize objects with both name and age, as
well as with just the name. Ensure proper memory management by implementing a destructor,
a copy constructor for deep copying, and an assignment operator. Additionally, overloads the
constructors to accept different parameter types. Finally, in the main() function, demonstrate
the usage of these constructors by creating Person objects with various parameters and
displaying their information.
Question: 2
Develop a C++ program for a car rental system. Define a Car class with attributes such as
make, model, and rental price per day. Implement constructors to initialize objects with
different parameter combinations, ensuring proper memory management. Provide a copy
constructor for deep copying and overload constructors to accept different parameter types.
In the main() function, demonstrate the usage of these constructors by creating Car objects
with various parameters and displaying their details.
Question: 3
Target: this pointer use
Write a C++ program to manage a product inventory. Create a Product class with attributes
including name, category, and price. Implement constructors to initialize objects with different
parameter combinations, ensuring proper memory management. Additionally, provide a copy
constructor for deep copying and overload constructors to accept different parameter types.
In the main() function, show the usage of these constructors by creating Product objects with
various parameters and displaying their information.
Note: local variable’s name should be same as member’s name
Department of Computer Science, New Campus
UNIVERSITY OF ENGINEERING
AND TECHNOLOGY, LAHORE

Question: 4
Design and implement a class clockType that manages time. The class clockType should
store hours, minutes, and seconds and display them in the following format (12:30:5). For
any object of clockType, your program should be able to perform the following operations on
that object.
1. Set the time
2. Get the time
3. Display the time
4. Increment the hour by 1
5. Increment the minute by 1
6. Increment the second by 1
7. Create another object of clockType and copy it with the object you created earlier. And see
the values in both objects.
Question: 5
Define a Rectangle class with attributes for length and width. Implement dynamic memory
allocation for storing the dimensions of the rectangle, where both length and width are
dynamically allocated. Add a copy constructor to this class that accepts another Rectangle
object as an argument. Within the copy constructor, perform deep copies of the length and
width attributes to ensure the creation of an independent copy of the original rectangle's
dimensions. Demonstrates the use of cascaded functions

You might also like