0% found this document useful (0 votes)
14 views2 pages

Lab 5 and 6 OOP

Uploaded by

nabeekbuisness
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)
14 views2 pages

Lab 5 and 6 OOP

Uploaded by

nabeekbuisness
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/ 2

Lab Overview:

This lab covers key concepts in C++ programming, including static attributes and functions, as well as
deep copy vs. shallow copy. Participants will explore practical scenarios, such as tracking instances,
managing data, and implementing class-level functionality, to gain a comprehensive understanding of
these concepts.

Lab Objective:
The objective of this lab is to familiarize participants with key concepts in C++ programming, including
deep copy, shallow copy, static variables, and static functions.

Lab Environment:
 C++ compiler (e.g., g++, Visual C++, or Xcode)
 A text editor or Integrated Development Environment (IDE)

1. Static Attribute:

Illustrate the use of a static attribute (`totalLabs`) to keep track of the total number of instances created
for a class (`Lab`).

2. Static Function:

Demonstrate the usage of a static function (`getTotalLabs`) that operates on a class level, providing
functionality without the need for an instance of the class.

3. Shallow Copy:

Copies only the memory addresses of data, which can result in unintended modifications if not handled
carefully.

4. Deep Copy:

Ensures each object has its unique copy of data, preventing unintended side effects and maintaining
data integrity.
1. Deep Copy vs. Shallow Copy:
Implement a C++ class representing a shopping cart. Create a copy constructor that performs a deep
copy to ensure that each shopping cart instance maintains its independent list of items.

2. Static Variables:
Write a C++ program for a banking application. Define a class representing a bank account and use a
static variable to keep track of the total number of accounts opened. Implement a method to display this
total count.

Develop a C++ class to represent employees in a company. Utilize a static variable to generate a unique
employee ID for each new employee object created. Implement a method to retrieve and display the
employee ID.

3. Static Functions:
Create a C++ utility class for mathematical operations. Implement a static function to calculate the
factorial of a given number. Test the function with different input values.

Design a C++ class to manage database connections. Use a static function to establish a connection to
the database, ensuring that only one connection is maintained throughout the program's execution.

Develop a C++ game class to handle different levels. Implement a static function to determine the
difficulty level of a specific game level based on predefined criteria such as the number of enemies,
obstacles, or time constraints.

You might also like