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

Class and Object Practice Question

The document outlines practice questions for creating various C++ classes, including 'Car', 'Account', 'Player', 'MenuItem', 'Post', 'Student', 'Song', 'Product', 'Event', and 'Book'. Each class has specific attributes and member functions to manage data and perform operations relevant to its context. Examples include managing a car rental fleet, banking transactions, game scoring, restaurant menus, social media posts, student records, music details, online shopping, event scheduling, and library management.

Uploaded by

sagor barua
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)
2 views

Class and Object Practice Question

The document outlines practice questions for creating various C++ classes, including 'Car', 'Account', 'Player', 'MenuItem', 'Post', 'Student', 'Song', 'Product', 'Event', and 'Book'. Each class has specific attributes and member functions to manage data and perform operations relevant to its context. Examples include managing a car rental fleet, banking transactions, game scoring, restaurant menus, social media posts, student records, music details, online shopping, event scheduling, and library management.

Uploaded by

sagor barua
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/ 3

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:

1. Get the car's information as a formatted string.


2. Update the car's mileage.
3. Check if the car is a luxury car.

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:

1. Deposit funds into the account.


2. Withdraw funds from the account.
3. Get the current balance of the account.

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:

1. Increase the player's score by a given amount.


2. Level up the player.

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:

1. Display the details of the menu item.


Class and Object Practice Question

Create an instance of the MenuItem class with name="Cheeseburger", price=10.99, and


description="Juicy beef patty with melted cheese." Call the display function to print the menu
item details.

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:

1. Edit the content of the post.


2. Display the post details.

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:

1. Add a grade to the student's record.


2. Calculate the average grade for the student.

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:

1. Display the details of the song.

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:

1. Update the quantity of the product.


2. Display the product details.

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:

1. Display the details of the event.

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:

1. Check out the book.


2. Return the book.
3. Display the book details.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy