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

Sample QP

The document outlines various C++ programming tasks involving object-oriented concepts such as classes, constructors, inheritance, operator overloading, and polymorphism. It includes the creation of classes for managing customer orders, product inventories, phonebooks, and employee management systems, as well as implementing functionalities like calculating bills, discounts, and employee salaries. Additionally, it describes the use of templates for mathematical computations and the design of systems for specific applications like online ticket booking and warehouse management.

Uploaded by

Visaka
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)
6 views8 pages

Sample QP

The document outlines various C++ programming tasks involving object-oriented concepts such as classes, constructors, inheritance, operator overloading, and polymorphism. It includes the creation of classes for managing customer orders, product inventories, phonebooks, and employee management systems, as well as implementing functionalities like calculating bills, discounts, and employee salaries. Additionally, it describes the use of templates for mathematical computations and the design of systems for specific applications like online ticket booking and warehouse management.

Uploaded by

Visaka
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

Constructor

Write a C++ program for creating two classes namely Customer and Product. The price
from the product class and the quantity from the order class are multiplied to generate the
bill. Declare price and quantity as private data members, create a bill() function globally,
access the same by passing the objects as arguments in the function. Give the inputs as
price and quantity and price of the 5 items and its total will be the bill. The ABC furniture
show room provides discount as shown in the table 1.

Calculate the discount percentage for the items using a separate function and call the
same using the object. Create a constructor to initialize the objects.

Refer the following table:

[Link] No. of items Ordered Price Discount %

1 4 chairs 8000 10%

2 3 sofas 21000 15%

3 8 tables 16000 20%

4 3 corner tables 6000 10%

5 2 swings 9000 15%

Consider there are two class rooms and each containing X number of boys and Y number
of girls in it. Write a C++ program to display the total sum of boys and girls in both the
classes keeping in view the following guidelines:

a) The name of the class should be ClassRoom with data members NoOfBoys,
NoOfGirls in it.
b) Parameterized constructor should be used for initializing the objects.
c) A method namely add(ClassRoom, ClassRoom) with objects as arguments
should be used for performing the addition.
d) Total three objects of ClassRoom type should be created in the main method.
e) The first two objects should be used as arguments to add method and the third
object is to store the result returned from add method and then display the total
number of boys and girls in the resulting object.
Krishna wants to use a Product Inventory program using object-oriented programming
concepts in his shop. So, the program should allow Krishna to manage a list of products,
including adding products, displaying product details, and calculating the total value of the
inventory. Write a C++ program that implements the following features to help Krishna:

a) Create a Product class with the following attributes:

• productId: to store the unique ID of the product

• productName: to store the name of the product

• price: to store the price of the product

• quantity: to store the quantity of the product in stock

b) Implement a member variable totalProducts to keep track of the total number of


products in the inventory.

c) Implement a constructor for the Product class that takes the productId, productName,
price, and quantity as parameters. The constructor should initialize the attributes and
increment the totalProducts count.

d) Implement member functions for the Product class as follows:

• displayProductDetails(): displays the details of the product, including the product


ID, name, price, and quantity.

• getTotalValue(): returns the total value of the product inventory (price * quantity).

e) Use an inline function to implement the getTotalValue() member function.

f) Allow the user to input the number of products to add to the inventory and their details
(product ID, name, price, and quantity) using appropriate user prompts. After adding the
products, display the details of all the products in the inventory, including the total
products and total value of the inventory.

Static Function

Assume you are developing an online warehouse management system, when a new
customer is sending a query to the system, based on the availability, the system will
allocate the space or it will return “not available”.
Create a class for the customer with data members; customer name, requirement of space
(length and Breadth in meters) and number of days required. The member function
set_data will get the input from the user and initialize the member variables and
generate_quotation function will display the quotation for the requirement. The rent of one
square meter space for one day is Rs. 50/-.

Create the static data member company name, available space (in meters) and define the
static function named avail_space() to check the availability of calculated required space
in the warehouse by checking the status of ‘available space’. Write the C++ program to
implement the above scenario and generate the quotation for the requirement.

Friend function

Suppose you are asked to design a phonebook that has N entries. Each entry is modelled
as a class having attributes such as entry_id, name and a 10 digit phone number. Here
entry_id uniquely identifies each phonebook entry and it is auto-generated with static
initialization. Note that the details such as entry_id, name and phone number are private
data members of the class.
Write a C++ program that includes a class for the phonebook as described above and a
friend function to display the matching phone number and entry_id for a given name.

Write a C++ program to implement the automobile dealership system. This system consists
of two classes Sales Manager and General Manager. The Sales Manager maintains his
customers’ namelist, number of customers and performance status. This class has set and
get methods for data members’ values assignment and display. Assume that the Sales
Manager can deal ‘N’ number of customers. Whenever the Sales Manager sells a car to
new customer then this customer name is added in the name list and the number of
customer is also increased.

The General Manager class has a method to evaluate the performance of Sales Manager
based on the number of customers he has and set Sales Manager’s performance status as
Good if the number of customers is more than 100 otherwise set ‘Improvement Needed’.
This system also supports the lucky winner function to find the customer with eight letters
in his name to announce the winner’s name. Winner function should be declared as a
friend function. Apply friend function and friend class concepts to implement this system.

Operator overloading

Consider a class Distance containing x and y coordinates of two points 𝑃1and 𝑃2in space.

Write a C++ program and necessary functions to perform the following task:

(a) To read the x and y-coordinates for the two points


𝑃1 (𝑥1 , 𝑦1 )and 𝑃2 (𝑥2 , 𝑦2 ).

(b) To find distance 𝑑between two points (𝑃1, 𝑃2)by using (+) operator overloading
method.

𝑑 = √(𝑥2 − 𝑥1)2 + (𝑦2 − 𝑦1 )2

Where:

• 𝑑= distance

• (𝑥1, 𝑦1)= coordinates of the first point 𝑃1

• (𝑥2, 𝑦2)= coordinates of the second point 𝑃2

Inheritance

Write a C++ program to check whether a cricket player is a reliable all-rounder or not.
Create a class "player" with data members such as player number, runs scored in last 5
matches, balls faced in last 5 matches and run_rate. Under "player" class, implement a
method to find sum of run rates (runs scored/ balls faced i.e for each match) and store it in
run_rate.

Create another class "bowler" with data members such as, number of wickets taken in last
5 matches, runs given in last 5 matches and bowling_economy. Under "bowling" class
implement a method to find sum of bowling economies (runs given/number of wickets
taken i.e each match) and store it in bowling_economy.

Derive a class "performance" from player and bowler classes. Under "performance" class
implement a method to invoke methods defined in base classes and to find whether player
is reliable or not according to following conditions:

If run_rate >= 5 and the bowling_economy is <= 30, he is the reliable player.

Create object of derived type in main() and invoke method defined in performance class.

-------------------------------------------------------------------------------------------------------------

Assume XYZ conducts a technical competition to the college students. The students
belong to either Electronics background or Computer Science background. Define a base
class student which stores information such as student id, name and marks of three levels
of competition.

From the base class, derive two classes, one for students belonging to Electronics stream
and other class for the students belonging to Computer Science stream. Include necessary
member functions in order to achieve the following tasks:

i. Get values from the user and display the same.


ii. Calculate the total marks of three levels of competition.
iii. Display the average mark scored by each student from electronics and computer
science stream.

Write a C++ program using appropriate inheritance to implement the same.


(Note: Write at least one valid test case and give appropriate comments in the program)

Design a Hospital Management System** to manage different types of employees in a


hospital.

The hospital has various categories of staff, including doctors, nurses, and administrative
staff. Each category of staff has specific attributes and functionalities. The doctors have
specialties, the nurses have different shifts, and the administrative staff has specific roles
such as receptionist, accountant, and human resources manager.
Develop a C++ program** that implements the following classes: **Employee, Doctor,
Nurse, and AdministrativeStaff.

- Employee class should serve as the base class for all staff members and contain member
variables **name** and employeeId.

- Define a display method in the derived classes to display the employee details.

- The Doctor class should be derived from the Employee class and have an additional
member variable specialty.

- The Nurse class should also be derived from the Employee class and have an additional
member variable shift.

- The AdministrativeStaff class should be derived from the Employee class and have an
additional member variable role.

In your main() function, create instances of a doctor, a nurse, and an administrative staff
member. Use the chain of constructor to initialize the data members of derived class and
base class.

Identify the type of inheritance and sketch the various classes and methods used in the
above scenario.

Dynamic Polymorphism

Create a base class named Person with the following members:

1. Name

2. ID

3. virtual void getData() – to read the details of the person

4. virtual void putData() – to print the details of the person

5. virtual void calcTax() – prints “All earning individuals must pay tax regularly”
Tax Exemption for Govt. Employees is 500000/- and for Private Employees is 300000/-.
Income tax % for Govt. Employees is 10% and for private employees is 20%.

-----------------------------------------------------------------------------------------------------------

Consider an online ticket booking system of a movie hall. Assume that you are going to
book ticket for only one person. Ticket price is calculated based on the type of seat:
NORMAL (220 Rs.) and EXECUTIVE (340 Rs.). Along with ticket type, you may also order for
refreshments which are available as combo packages with price of 100 Rs, 200 Rs, etc.

Given seat type and refreshments package price, you need to calculate the net price to be
paid.

There is a special kind of ticket VIP_ticket, booked by VIP customers who will get some
discount on seat price as well as refreshment price. The discount depends on the VIP
quota level as described below:

for quota level 1 to 3, 3% discount on seat price and 2% on refreshment price

for quota level 4 and above, 5% discount on seat price and 4% on refreshment price

Write a C++ program which includes base class ticket and derived class VIP_ticket as
described above and calculates the ticket price depending on the customer using dynamic
polymorphism.

You have a base class called Employee with data members name, basic salary and inherit
two derived classes Manager and Developer. Each derived class has its own
implementation of a calculateSalary() method.

Create a class hierarchy in C++ to handle salary calculation differently for each derived
class (Manager and Developer) in the Employee class hierarchy, and make the
calculateSalary() method as virtual function in base class and override the
calculateSalary() method in each derived class.
The user has to give the input value for name and basic salary. The formula for calculating
salary is as follows:

Salary = Basic + HRA + Transport Allowance + DA.

TA, DA and HRA details as follow:

- For Manager:

DA is 12% of basic pay,

TA is 15% of basic pay and

HRA is 18% of basic salary.

- For Developer:

DA is 10% of basic pay,

HRA is 14% of basic pay and

no TA allowed.

Templates

Create the C++ Function Template named Series which has three parameters sum, x, and
n. The first two parameters will have the type represented by the function template type
parameter T. The third parameter will always be int. The return type is void. All parameters
are passed by value except for sum which is passed by reference.

A Template Function created from Series will compute:

sum = 1 + 𝑥 + 2𝑥 + 3𝑥 + ⋯ + 𝑛𝑥

for both int and float values of x.

You might also like