0% found this document useful (0 votes)
10 views

Unit 2 - Week 3 - Tutorial Lab Programs

The document discusses class constructors and destructors. It provides examples of using different types of constructors like default, parameterized, copy and constructor overloading. It also gives an example of using destructors to release dynamically allocated memory.

Uploaded by

arorarijak06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Unit 2 - Week 3 - Tutorial Lab Programs

The document discusses class constructors and destructors. It provides examples of using different types of constructors like default, parameterized, copy and constructor overloading. It also gives an example of using destructors to release dynamically allocated memory.

Uploaded by

arorarijak06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UNIT -2 – Lab Questions

1. Create a class named 'Box' with data members such as length, breadth and height. Get the
values of length, breadth and height from the user and also calculate the volume of the
box which is to be generated in the proper format using constructors.

2. Create a C++ program to construct the circle by getting two points such as x and y using
parameterised constructor by getting the values in parameters. Also, how to access these
points to display the values in the console mode.

3. Create a C++ program to construct the student database using copy constructor. Get the
input such as name, roll number and fees payment details. All necessary and additional
details can also be get in the input format internally.

4. Consider a scenario where you are designing a software system for a library management
application. The system has two main entities: Book and LibraryMember. Each Book has
attributes such as ISBN, title, and author, while each LibraryMember has attributes like
member ID, name, and contact details. Assume that both entities need to be initialized
with different sets of information. Additionally, there is a requirement to manage
dynamic memory for storing book titles. Design the class structures for Book and
LibraryMember considering constructor overloading and destructor. Implement the
necessary constructors to initialize the objects, ensuring dynamic memory management
for book titles.

5. Write a C++ program to design a class 'Complex' with data members for real and
imaginary part. Provide default and parameterized constructors. Write a program
to perform arithmetic operations of two complex numbers using operator
overloading(Addition, subtraction, multiplication and division) using member functions.

6. Elavenil is the working in Survey of India, The National Survey and Mapping
Organization of the country under the Department of Science & Technology. Now
Elavenil has been assigned the task of Collecting the Area and Density Information of all
the states of India from the local authorities of the respective states and to consolidate in a
common portal of Government of INDIA. Since the task assigned to her is highly
complicated in nature she is seeking your help. Can you help her? Use the Concept of
Constructor Overloading to complete the task.

7. Provide an example where a destructor is used to release dynamically allocated memory.

8. Sequence diagram exercise: Poker use case, Start New Game Round The scenario begins
when the player chooses to start a new round in the UI. The UI asks whether any new
players want to join the round; if so, the new players are added using the UI. All players'
hands are emptied into the deck, which is then shuffled. The player left of the dealer
supplies an ante bet of the proper amount. Next each player is dealt a hand of two cards
from the deck in a round-robin fashion; one card to each player, then the second card. If
the player left of the dealer doesn't have enough money to ante, he/she is removed from
the game, and the next player supplies the ante. If that player also cannot afford the ante,
this cycle continues until such a player is found or all players are removed.

You might also like