0% found this document useful (0 votes)
6 views4 pages

Constructors, Lab 5

The document outlines the requirements for creating C++ programs using Object-Oriented Programming principles. It includes tasks for developing a Bank Account Management System with deposit and withdrawal functionalities, and a Book class demonstrating the use of constructors and destructors. Each task specifies class designs, methods, and program flow to implement the required features.

Uploaded by

heist994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Constructors, Lab 5

The document outlines the requirements for creating C++ programs using Object-Oriented Programming principles. It includes tasks for developing a Bank Account Management System with deposit and withdrawal functionalities, and a Book class demonstrating the use of constructors and destructors. Each task specifies class designs, methods, and program flow to implement the required features.

Uploaded by

heist994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Write a C++ program that defines a class Rectangle.

The class should have two data members,


length and width. The class should have a default constructor that initializes the length and
width to 0. Write a function display() to show the values of length and width.
2. Write a C++ program that defines a class Circle. The class should have a data member
radius. The class should have a parameterized constructor that takes radius as an argument
and initializes the radius of the circle. Also, implement a function area() to calculate and print
the area of the circle (area = π * radius^2).

TASKS
TASK 1
You are tasked with creating a Bank Account Management System in C++ using Object-Oriented
Programming (OOP) principles. The system should allow the creation of a bank account, deposit and
withdraw funds, and display the account details. The system should handle basic operations such as
deposits, withdrawals, and balance checks.

Requirements:

1. Class Design:

o Create a class named BankAccount to represent a bank account.

o The class should have the following private attributes:

▪ int accountNumber: Represents the unique account number.

string accountHolderName: Represents the name of the account holder.

▪ double balance: Represents the current balance in the account.

o Implement the following public methods:

▪ Constructor: A constructor to initialize the account with the account number,


account holder's name, and initial balance.

▪ Deposit Method: A method deposit(double amount) that adds the specified


amount to the account balance. If the amount is negative, it should display an
error message.

▪ Withdraw Method: A method withdraw(double amount) that subtracts the


specified amount from the account balance. The method should ensure that the
balance does not become negative (i.e., the user cannot withdraw more than
the available balance).

▪ Display Method: A method displayAccountDetails() that outputs the account


details including account number, account holder's name, and the current
balance.

2. Program Flow:

o In the main() function, implement the following actions:

▪ Create a BankAccount object and initialize it with an account number, account


holder's name, and initial balance.

▪ Provide options for the user to:

▪ Deposit money into the account.

▪ Withdraw money from the account.

▪ View account details (account number, account holder's name, and balance).

▪ Ensure that after each transaction (deposit/withdraw), the account balance is


updated and the current details are displayed.

Task 2:
You are required to implement a C++ program that demonstrates the use of constructors in an object-
oriented manner. The program should create a class that represents a simple Book with attributes such
as title, author, and price. The class should use a constructor to initialize these attributes and a
destructor to clean up or display a message when the object is destroyed.

Requirements:

1. Class Design:

o Create a class named Book with the following private attributes:


string title: Represents the title of the book.

▪ string author: Represents the author of the book.

▪ double price: Represents the price of the book.

o Implement the following public methods:

▪ Constructor: A parameterized constructor to initialize the values of title, author,


and price when an object is created.

▪ Display Method: A method displayDetails() to output the details of the book


(title, author, and price).

2. Program Flow:

o In the main() function, demonstrate the creation of a Book object using the constructor.

o Display the book details using the displayDetails() method.

o The destructor should automatically be called when the object goes out of scope (i.e.,
when the program finishes execution or when the object goes out of scope).

Task 3:
You are required to implement a C++ program that demonstrates the use of constructors and
destructors in an object-oriented manner. The program should create a class that represents a simple
Book with attributes such as title, author, and price. The class should use a constructor to initialize these
attributes and a destructor to clean up or display a message when the object is destroyed.

Requirements:

1. Class Design:

o Create a class named Book with the following private attributes:

▪ string title: Represents the title of the book.

▪ string author: Represents the author of the book.

▪ double price: Represents the price of the book.

o Implement the following public methods:

▪ Constructor: A parameterized constructor to initialize the values of title, author,


and price when an object is created.

▪ Destructor: A destructor that will display a message when the object is


destroyed. The destructor should be automatically invoked when the object
goes out of scope.

Display Method: A method displayDetails() to output the details of the book


(title, author, and price).

2. Program Flow:

o In the main() function, demonstrate the creation of a Book object using the constructor.

o Display the book details using the displayDetails() method.

o The destructor should automatically be called when the object goes out of scope (i.e.,
when the program finishes execution or when the object goes out of scope).

You might also like