BCACC302 - 2 - Object Oriented Programming With C - 4rth Edition-E Balagurusamy
BCACC302 - 2 - Object Oriented Programming With C - 4rth Edition-E Balagurusamy
2
3
4
5
6
7
8
9
10
11
12
13
14
C++ problem based on object, class
1. A shop required to store information about each item. Information will be Item name, item code, price and
available quantities. User (Sales person) will store information about each item and can display information
about each item. Model the above problem with object oriented technology.
Test case:
Input
Output
2. For different mathematical operation and decision making process, it is very vital to find out maximum and
minimum elements from a data set of say 10 integers. At the same time security of the data set is also
essential. Keeping above all in mind, develop an application which facilitate search of maximum and
minimum element from a 10-element integer data set using object oriented design concept.
Test case:
Input
Output
Maximum: 11
Minimum: -5
3. If an electronic shop contains 10 different product and each product have unique price in this shop.
Write down a C++ program to find out the maximum and minimum product price using the
concept of object and class.
Test Case:
Input:
Enter the price of all products:
2300, 5400, 14000, 6500, 7500, 1200, 23000, 4500, 6600, 9800
Output:
Maximum piece: 23000
Minimum price: 1200
6|P a ge
4. For various data operation it is very difficult task to find out the exact location of a data element from a
data set of say 10 integers. At the same time security of the data set is also essential. Keeping above all in
mind, develop an application which facilitate to search the location an element from a 10-element integer
data set using object oriented design concept.
Test case:
Input
Output
Search Item: 11
Location: 6
5. If any array contain huge amount of data (but all the element are in sorted order), it is very difficult task to
find out the location of any data item within less amount of time. Hence write down a C++ program to find
out the location of any data item with minimum number of comparison by implementing the concept of
object and class. At the same time security of the data set is also essential.
Test Case:
Input-1: Element in array: 10,19,27,30,35,67,80
Minimum no. of comparison required: 1
Maximum no of comparison required: 3
Input-2: Search Item: 19
Output: Location: 2
6. Let as assume an organization contain n number of employee and the HR wants to short the salary
of their employee and also want to display the salary as per ascending order from manager level to
worker level. Write down a C++ program to resolve the problem with the help of class and object.
Hints: If the organization contains 10 employees, the total number of pass will be 9 and the
required number of comparison = Element in each pass-1.
7. Write down a C++ program to store and display the information of all books (title, price etc.) of a book
shop by implementation the concept of object and class where the total number of books will be given by
book shopper as an input.
Test Case:
Input:
The total number of books to store the information: 3
Enter details of book 1
Title: Programming in C
Price: 500
Enter details of book 2
Title: Programming in java
Price: 200
Enter details of book 3
Title: Computer Network
Price: 450
7|P a ge
Output:
Details of all books
Book 1
Title: Programming in C
Price: 500
Book 2
Title: Programming in java
Price: 200
Book 3
Title: Computer Network
Price: 450
8. Write down a C++ program to store and display the details (such as employee id, name and salary)
information of required employee of an organization using the concept of method, class and objects. At the
same time security of the data set is also essential. The user must define the total number of employee
which will be store and display the data as a tabular format.
Test Case:
Input:
The total number Employee: 2
Details of Employee 1
Employee ID: 201
Name: Rohit Kumar Das
Salary: 45000
Details of Employee 2
Employee ID: 202
Name: Amitava Dutta
Salary: 55000
Output:
201 Rohit Kumar Das 45000
202 Amitava Dutta 55000
9. A college library requires storing information of all books like as ISBN, page and price. It is required to
find out the total and average price of all book also find out the maximum and minimum price of the book
along with its ISBN number. Assume there are three books in the library. To solve above problem using
object oriented flavor.
Test case:
Input
ISBN Page Price
Book-1 101 600 420
Book-2 122 720 540
Book-3 133 550 610
8|P a ge
Output
10. A college requires storing information like roll, name, age and marks of 3 different subjects about each
student of BCA 3rd semester. It is required to find out the total and average marks of each student along
with details of all students. Assume there are three students in BCA 3rd semester. Model above problem
using object oriented flavor.
Test case:
Input
Roll Name age m1 m2 m3
Student-1 1 Rohan 19 81 67 78
Student-2 2 Saikat 20 34 56 81
Student-3 3 Manoj 19 45 56 46
Output:
11. An institute requires storing information like roll, age and marks of 3 different subjects (Mathematics,
Physics and Chemistry) of class-X student. It is required to find out the topper of the class-X. Assume there
are three students in class-X. Model above problem using object oriented flavor.
9|P a ge
Test case:
Input
Roll Name age Mathematics Physics Chemistry
Student-1 1 Manab 19 81 67 78
Student-2 2 Rohit 20 34 56 81
Student-3 3 Sayan 19 45 56 46
Output
Topper of class-X
Highest Marks=226
Roll Number of Highest Scorer=1
Age of Highest Scorer=19
C++ problem based on switch case with the help of object and class concept
12. An electronics shop, ABC provide a Diwali discount for different product on the basis of MRP
range, they provide two types of discounts (flat and special) for some products, the list is given
bellow.
Sl. No Product name MRP Range (Rs.) Flat Discount Special Discount
1 TV >=20000 15% 10%
<20000 & >=15000 10% 5%
<15000 5% Nil
2 AC >=40000 20% 15%
<40000 & >=35000 15% 10%
<35000 & >=30000 10% 5%
<30000 5% Nil
3 Computer >=35000 10% 7%
<35000 & >=25000 7% 5%
<25000 5% Nil
4 Other electronics NA 5% Nil
goods
Now write down a C++ Program to calculate the selling price of any product as per user choice
based on the concept of object and class. For security reasons, the data must be encapsulated
Test case:
Input:
2
Price of AC:
30000
Output: Selling price of AC is: 24000
10 | P a g e
13. Develop an application program in C++ by implement the concept of object and class for an organization,
Telcome who want to calculate the DA, TA, HRA Gross Salary and Net salary, for three different types of
employee (Manager, Developer and accountant) based on basic salary. The basic salary and choice of
employee selection will be given from the user end. For security reasons, the data must be encapsulated.
NOTE: To calculate the net salary 12% tax will be deducted from gross salary for all type of employee
except both type of accountant.
Test case:
1. Manager
2. Developer
3. Accountant
4. Exit
1. Manager
2. Developer
3. Accountant
4. Exit
Enter your choice: 3
Enter salary of Accountant: 15000
DA of junior Accountant: 3000
TA of junior Accountant: 1500
HRA of junior Accountant: 1500
Net Salary of Junior Account: 21000
14. A Cricket organization need to store information like name, number of innings, number of not out innings,
total run scored and total wicket taken of each cricketer. After storing data, organization will analyze the
data and want to come on the following conclusion: If a cricketer plays more or equal to 50 innings and is
batting average is more than 35 then recognize him as a “BATSMAN”. If a cricketer plays more or equal to
50 innings and if taken more than 49 wickets then recognize him as a “BOWLER”. If one satisfies both
conditions then he will be “ALL ROUNDER”. Organization needs to display each information about each
cricketer. Model above problem using object-oriented flavor.
[Batting average=total run/( No_Of_Inn - Not_Out_Inn)]
11 | P a g e
Test case-1:
Input:
Name: Rahul
No_Of_Inn: 120
Not_Out_Inn: 20
Total_run: 8500
Total_Wkt: 11
Output:
He is a BATSMAN
Test case-2:
Input:
Name: kapil
No_Of_Inn: 150
Not_Out_Inn: 30
Total_run: 7900
Total_Wkt: 450
Output:
He is an ALL ROUNDER
15. An office need to store information like age, BASIC, DA, TA and year of experiences and designation of
each of its employee. DA will be 60% of basic and TA will be 10% of basic. If an employee has more than
5 years of experience then organization will give Rs. 1200/- extra. Model the system in OOP technology so
that it can display each record of all employees with total income. Also display amount of cost incurred by
the office to pay salary to each employee. Assume there are 3 employees.
Test case:
Input:
Enter following information of the employee:-
Age: 38
Basic: 12000
Year_Exp: 8
Age: 41
Basic: 14000
Year_Exp: 4
Age: 38
Basic: 8000
Year_Exp: 9
12 | P a g e
Output:
Employee-1
Age: 38
Basic: 12000
Year_Exp: 8
Total salary: 21600
Employee-2
Age: 41
Basic: 14000
Year_Exp: 4
Total salary: 23800
Employee-3
Age: 38
Basic: 8000
Year_Exp: 9
Total salary: 14800
Total salary paid to all employees: 60200
16. Electric office calculates the electric bill of a person by giving the details of the customer such as customer
number, customer name along with units’ consumption in a month. The bill will be calculated on the basis
of following condition: Up to 100 units Rs. 1.2 per unit, 300 units Rs 2 per unit, more than 300 units Rs 3
per unit.
Test Case:
Customer id: 101
Customer name: Sayan
Unit: 400
Cost: 820
17. There is an application ‘fun’ with one private float data member. Developer use constructor to initialize
that member. Like that, there is another application ‘magic’ with one private data member.
Now, it is a requirement to compare between data member of ‘fun’ and member of ‘magic’. Write an
application to meet that requirement
Test case
Input:
fun f(10.25);
magic m(11.10);
Output:
Data member of magic is greate
18. Write down a C++ program to swap two numbers without using third variable with the help of friend
function.
13 | P a g e
Test Case:
19. An Institute wants to calculate the total salary of HOD and Assistant HOD. HOD get 60% DA and 30%
HRA of basic salary on the other hand Assistant HOD get 50% DA and 20% HRA of basic salary. For both
type of employee 12% P. Tax will be deducted from their total salary. To solve this problem we must
implement the concept of friend function.
Test Case:
Input:
Basic of HOD: Rs. 25000/-
Basic of Assistant HOD: Rs. 20000/-
Output:
Total Salary of HOD: Rs 41800/-
Total salary of Assistant HOD: Rs 28160/-
Total salary of both employee: Rs. 69960/-
20. An organization want to calculate the total salary of three (3) individual (manager, developer and
accountant) as well as want to calculate the total salary of all three types of employee. Manager get 60%
DA and 50% HRA of basic salary, developer get gets 50% DA and 40% HRA of basic salary and
accountant gets 40% DA and 30% HRA of basic salary. For all type of employee 12% P. Tax will be
deducted from their total salary. To solve this problem we must implement the concept of friend function
by defining three individual classes for three different types of employee.
Test Case:
Input:
Output:
Total salary of Manager: 46200
Total salary of Developer: 33440
Total salary of Manager: 22440
Total salary of All Employee: 102080
21. Create a class with the name car which contains four data members (brand, model, year and price).
Construct the value during object creation. Pass the values of three different types of car (details are given
below). Implement the concept of parameterized constructor to solve the problem. Also use a member
function display (). Every time the function, display () is call to print the details of each type of car.
14 | P a g e
Test Case:
Details of car
22. Develop an application in C++ to calculate the factorial of a given number n where the value of n is given
from user end by implementing the concept of copy constructor.
Test case:
23. Develop an application program to calculate the area and perimeter of a circle. Also calculate the rectangle
area and volume of a cube. To solve this problem we use a constructor namely Rect ( ) and in different
time we overload the value of the constructor with different types of parameter. Here we also define four
individual member functions to display these four different values.
Test case:
Circle area=7
Rectangle breadth and length=5, 8
Cube breadth, height and length=4, 8, 9
24. Develop an application where requirement is to search an item from two different types of data set of 10
elements each. One data set is of type integer and another is of type float. These data needs protection for
unauthorized users. Function name of the search function need to be same.
Test case:
Input:
Enter integer data set: 2, 5, 4, 3, 7, -9, 10, 12, 45, 17
Enter float data set: 12.4, 2.1, 5.4, 4.6, 1.4, 4.2, 5.4, 6.9, 9.8, 9.7
Output:
Enter integer data to search: -9
Data found at position: 6
15 | P a g e
25. An application need to calculate sum and average of i) 3 integer ii) 3 float, iii) 2 integer-1float and iv) 1
integer-1float-1integer. Achieve the solution using same functions with same name
Test case-1:
Test case-2:
26. An organization holds 4 different types of employee (manager, developer, and accountant and group-D
staff). The salary brake up are given bellow:
Write down a C++ program to calculate the total salary of each employee along with brake up salary. To solve
this problem you must implement the concept of function overloading.
Test case:
16 | P a g e
C++ problem based on operator overloading
27. In an application, there are three variables of type integers. Concepts of data security should have
implemented. Objects need to represent those variables. For use, there should have frequent increase and
decrease of object value using ++ and -- operator. Those operators need to use with object directly type.
Implement the above requirement by object oriented programming.
Test case:
Input:
Test t(1,2,3);
t.display();
t++;
t.display();
t--;
t.display();
Output:
A= 1, B = 2, C = 3
A= 2, B = 3, C = 4
A= 1, B = 2, C = 3
28. In an application, there are one variable of type integer. Concepts of data security should have
implemented. Objects need to represent that variable. For use, there should have frequent checking of
biggest or lowest or equal objects by directly applying >, <, == operators on object. Implement the above
requirement by object oriented programming.
Test case-1:
Input:
Test t(6);
Test s(5)
Output:
Object t is greater
Test case-2:
Input:
Test t(5);
Test s(7)
Output:
Object s is greater
Test case-3:
Input:
Test t(6);
Test s(6)
Output:
Both objects are equal
29. A small software farm has 5 employees. The firm needs to keep record about name, ID, BASIC, DA, TA,
HRA and total salary. DA will be 90% of BASIC, TA will be 10% of BASIC and HRA will be 15% of
BASIC. Farm also needs to compute total expenditure due to payment of salary. Calculation will be done
using simple ‘+’ operator. Implement the above requirement by object oriented programming.
17 | P a g e
Test case:
Input:
Enter for first employee:
ID: 1
Basic: 10000
Enter for second employee:
ID: 2
Basic: 9000
Enter for third employee:
ID: 3
Basic: 10000
Enter for fourth employee:
ID: 4
Basic: 10000
Enter for fifth employee:
ID: 5
Basic: 8000
Output:
Total expenditure due to payment of salary: 110050
30. A research institute needs to build an application where a 3 x 3 matrix will be stored by maintaining all
protocol of data hiding. For its operational purpose, separate object is required for representing each matrix
and multiplication of those matrixes is also a requirement. Multiplication need to achieve by * operator
applied on objects. Implement the above requirement by object oriented programming.
Test case:
First matrix:
1 2 3
4 5 6
7 8 9
Second matrix:
9 8 7
6 5 4
3 2 1
Multiplication result:
30 24 18
84 69 54
138 114 90
31. For a mathematical operation purpose, it is essential to store and represent a complex number of the form
A+Bi. Since these are highly sensitive data, so data hiding is required. An object is required to present a
complex number. For it’s operational purpose, it required to do addition and subtraction of the complex
number by directly applying + or – operator. Implement the above requirement by object oriented
programming.
18 | P a g e
Test case-1:
Input:
Enter real part of the complex number: 4
Enter img part of the complex number: 6
Output:
Addition: 7 + 8i
Subtraction: 1 + 4i
Test case-2:
Input:
Enter real part of the complex number: 9
Enter img part of the complex number: -2
Output:
Addition: 13 + 1i
Subtraction: 5 - 5i
32. A college already has an application to maintain students’ information such as name of students, roll, marks
of 5 subjects and semester. The application has some functionality such as storing student’s information,
displaying students’ information. Now, college needs to add a new attribute such as sports as a part of
student result. Apart from all above information, the college need to store information such as sports name
and a score(out of 100) associated with sports. 40% of the score need to ad with total marks if the score is
more than or equal to 50 to publish the result. Develop above (both) applications using object oriented
programming concepts.
Test case-1:
Input:
Student’s Name: Rohan
Roll: 1
Marks of 5 subjects: 80 95 66 75 85
Sports name: Cricket
Score 60
19 | P a g e
Output
*****FINAL RESULT*****
Roll: 1
Name: Rohan
Marks of subject 1: 80
Marks of subject 2: 95
Marks of subject 3: 66
Marks of subject 4: 75
Marks of subject 5: 85
Sports: Cricket
Score: 60
Total Marks: 425
Test case-2:
Input:
Student’s Name: Rahul
Roll: 2
Marks of 5 subjects: 70 85 76 75 90
Sports name: Football
Score 45
Output
*****FINAL RESULT*****
Roll: 2
Name: Rahul
Marks of subject 1: 70
Marks of subject 2: 85
Marks of subject 3: 76
Marks of subject 4: 75
Marks of subject 5: 90
Sports: Football
Score: 45
33. An organization recruits either engineer or MBA pass outs. For engineer, the organization store information
such as engineering stream, project code, and total salary plus an incentive of Rs: 9000. For MBA
graduates, the organization keeps information such as CAT score, MBA institute, and specialization
incentive is Rs: 10000. Now the organization plans to recruit candidates who have done engineering as well
as MBA. For those candidates, organization needs to keep all above details as well as a ratio of job
responsibility % such as engineering: 65%, management 35% Incentive will be based on % of job
responsibility. Develop all three applications using object oriented programming concepts also display
details of a BTech & MBA canddidate.
20 | P a g e
Test case:
Input:
Engineering stream: IT
P_Code: P001
Total Salary: 45000
CAT Score: 925
MBA Institute: IIM Calcutta
Specialization: Marketing
Engineering responsibility: 60
Management responsibility: 40
Output:
Engineering stream: IT
P_Code: P001
CAT Score: 925
MBA Institute: IIM Calcutta
Specialization: Marketing
34. An engineering institute maintains an application named Employee to keep record about all its employees,
such as name of employee, Emp id and salary. Another application, Engineer that store all above
information as well as engineering branch of that employee. All above application must have functionalities
to input information and display information. Now, organization need to have another application, IT-
Engineer, where apart from all above information of Engineer application, a new attribute need to store,
that is programming proficiency(one language). Develop all three applications using object oriented
programming concepts.
Test case:
Input:
Name of the employee: Kunal
Employee ID: 3
Salary: 55000
Engineering branch: Computer Science
Programming Language: Python
Output:
Name of the employee: Kunal
Employee ID: 3
Salary: 55000
Engineering branch: Computer Science
Programming Language: Python
21 | P a g e