Class and Object Practice Question
Class and Object Practice Question
1) You work for a car rental company and need to create a C++ class called "Car" to manage their
fleet. The Car class should have attributes for make, model, year, and mileage. Implement
member functions to:
Create an instance of the Car class with make="Toyota", model="Camry", year=2021, and
mileage=10000. Call the information function and print the result. Then, update the mileage by
500 and call the information function again. Finally, check if the car is a luxury car and print the
result.
Your implementation should demonstrate the use of classes, member functions, and object
instantiation in C++.
2) You are building a banking application and need to create a class called "Account" in C++. The
Account class should have attributes for account number, account holder name, and balance.
Implement member functions to:
Create an instance of the Account class with account number="123456", account holder
name="John Doe", and initial balance=1000. Perform a deposit of 500, followed by a withdrawal
of 200. Finally, retrieve the current balance and print the result.
3) You are designing a game and need to create a class called "Player" in C++. The Player class
should have attributes for player name, level, and score. Implement member functions to:
Create an instance of the Player class with name="Alice", level=1, and score=100. Increase the
score by 50 and level up the player. Print the updated player details.
4) You are developing a restaurant ordering system and need to create a class called "MenuItem" in
C++. The MenuItem class should have attributes for item name, price, and description.
Implement a member function to:
5) You are building a social media platform and need to create a class called "Post" in C++. The
Post class should have attributes for post ID, author name, and content. Implement member
functions to:
Create an instance of the Post class with ID=1, author name="Jane", and content="Hello, world!"
Edit the post content to "Welcome to my profile!" and display the updated post details.
6) You are working on a student management system and need to create a class called "Student" in
C++. The Student class should have attributes for student ID, name, and grades. Implement
member functions to:
Create an instance of the Student class with ID="S001", name="John Smith", and grades=[85,
90, 78]. Add a grade of 95 to the student's record and calculate the average grade. Print the
average grade.
7) You are developing a music player application and need to create a class called "Song" in C++.
The Song class should have attributes for song title, artist name, and duration. Implement a
member function to:
Create an instance of the Song class with title="Bohemian Rhapsody", artist name="Queen", and
duration="5:55". Call the display function to print the song details.
8) You are building an online shopping system and need to create a class called "Product" in C++.
The Product class should have attributes for product ID, name, price, and quantity. Implement
member functions to:
Create an instance of the Product class with ID="P001", name="Smartphone", price=499.99, and
quantity=10. Update the quantity to 5 and display the product details.
Class and Object Practice Question
9) You are developing a calendar application and need to create a class called "Event" in C++. The
Event class should have attributes for event name, date, and location. Implement a member
function to:
Create an instance of the Event class with name="Birthday Party", date="2023-08-15", and
location="Park Plaza". Call the display function to print the event details.
10) You are working on a library management system and need to create a class called
"Book" in C++. The Book class should have attributes for book ID, title, author, and availability
status. Implement member functions to:
Create an instance of the Book class with ID="B001", title="To Kill a Mockingbird",
author="Harper Lee", and availability status="available". Check out the book, return it, and
display the updated book details.