







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Objective To understand and implement the concepts of classes, objects, constructors, destructors, constructor overloading, and constant member functions in C++ classes for object initialization, cleanup, and structured data handling by defining user-defined classes with data members and member functions to model real-world entities Program 1: Create a class named Book with attributes such as title, author, and ISBN. Define appropriate member functions to get book information from the user and display the book details. Algorithm
1. Start the program.
cout << "Enter ISBN: "; getline(cin, ISBN); } // Function to display book details void displayBookInfo() { cout << "\nBook Details:\n"; cout << "Title : " << title << endl; cout << "Author : " << author << endl; cout << "ISBN : " << ISBN << endl; } }; int main() { Book b; b.getBookInfo(); b.displayBookInfo(); return 0; } Output: Program 2: Create a class named CarPark with data members Car Registration Number, Charge Per Hour, and Parking Duration. Implement appropriate member functions to set the data and display the parked hours and total charges. Algorithm
Output:
Program 3: Create a class named BankAccount with data members accountNumber,accountHolderName, and balance.Implement member functions to deposit an amount, withdraw an amount, and display the current balance. Implement constructor overloading by defining: โ A parameterized constructor that initializes the account with account number, account holder name. This Constructor should initialize the account balance as 0. โ A parameterized constructor that initializes the account with account number, account holder name, and initial balance Create objects of the class using different constructors and perform deposit and withdrawal operations. Algorithm:
Program 4: Develop a Program to demonstrate mathematical computation using classes and interaction between multiple objects. Create a class to represent a point in a two- dimensional coordinate system with data members for the x-coordinate and y- coordinate. Implement member functions to accept coordinate values from the user and to calculate the distance between two-point objects. Further, enhance the program by using constructors to initialize point coordinates. Apply constructor overloading by defining a default constructor that initializes a point at the origin and a parameterized constructor that initializes a point with given coordinates. Create appropriate objects and display the calculated distance between them. Algorithm: Program: Output:
cout<<"Product Id:"; cin>>ID; cout<<"Name of the product:"; cin>>name; cout<<"Price of the product:"; cin>>price; cout<<"Number of products:"; cin>>number; } void calculatecost(){ totalcost = price*number; } void display(){ cout<<"Details of the product:"<