C++ Programming Assignment 2024
C++ Programming Assignment 2024
C++ Programming Assignment 2024
Assigement-1
1. Write down a C++ program to find out the factorial of a given number, n
with the help of object and class concept.
2. Write down a C++ program to find out the maximum and minimum value
from an array with the help of object and class concept.
Hints: You must define 4 individual member functions to take input from
user end, search maximum value, search minimum value and display the
output.
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
Enter 10 integer elements:
7, 5, 4, 8, 9, 11,5, 0, 2, 1
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
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assigement-2
1. C++ Program to sort the elements of an array using the concept of class and
object.
Hints: Use bubble sort concept, where the total number of pass= number of element
in the array-1 and total No of comparison in each pass= No. of elements in each pass-
1.
2. Write down a C++ program to store and display book information (title, ISBN, price
etc.) with Using array of object concept.
3. Write down a C++ program to store and display the detail information (ID, Name
and Salary) of three different employees. The input values will be passes when the
objects call a member function.
4. 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:
Enter details of the item:
Item name: Sugar
Item code: 101
Price: 40.00
Quantities available in KG: 20
Output:
Details of the item:
Item name: Sugar
Item code: 101
Price: 40.00
Quantities available: 20KG
5. 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
Enter 10 integer elements:
7, 5, 4, 8, 9, 11,-5, 0, 2, 1
Output
Maximum: 11
Minimum: -5
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assigement-3
Encapsulation
Test case-1:
Input:
Enter the data: 161
Output:
It is Palindrome number, so final result is 322
Test case-2:
Input:
Enter the data: 244
Output:
It is Palindrome number, so final result is 122
2. 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:
3. A college requires storing information like roll, age and marks of 5 subjects
about each student of BCA 3rd semester. It is required to find out the topper
of the BCA 3rd semester. Assume there are five students in BCA 3rd
semester. Model above problem using object oriented flavor.
Test case:
Input
Roll Name age m1 m2 m3
Student-1 1 Rohit 19 81 67 78
Student-2 2 Binoy 20 34 56 81
Student-3 3 Mohit 19 45 56 46
Output
Highest Marks=226
Roll Number of Highest Scorer=1
Age of Highest Scorer=19
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assigement-4
Encapsulation
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
2. 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
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
3. 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
Calculation method :100*1.2+200*2+100*3=820
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assigement-5
Friend Function
1. 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
2. Write down a C++ program to swap two numbers without using third variable with the
help of friend function.
Test Case:
3. An organization want to calculate the total salary of two different type of employee one
is manager another is sales person. Manager get 60% DA and 30% HRA of basic salary
on the other hand sales person get 40% 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 Manager: Rs. 25000/-
Basic of sales person: Rs. 20000/-
Output:
Total Salary of Manager: Rs 41800/-
Total salary of sales person: Rs 28160/-
Total salary of both employee: Rs. 69960/-
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment-6
Parameterize and copy Constructor
1. 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.
Test Case:
Details of car
Test case:
Constructor overloading
Test case:
Circle area=7
Rectangle breadth and length=5, 8
Cube breadth, height and length=4, 8, 9
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
1. 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:
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
Friend Function
3. There are three different member function abc(), pqr() and xyz() belongs into
three different class where every member function contain one private float
data member. Here each class contain a common friend function max () which
is required to compare the greater number.
Test case-1
Input:
abc obj1(10.25);
pqr obj2(11.10);
xyz obj3(12.25);
Output: Data member of xyz is greater
Test case-2
Input:
abc obj1(20.25);
pqr obj2(11.10);
xyz obj3(12.25);
Output: Data member of abc is greater
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment-8 (Brush Up)
[Array of object, constructor and friend function]
1. 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
Output
Test Case-1:
Input:
Enter a number: 11
Output:
The number is a prime and it is multiplied by 2: 22
Test Case-2:
Input:
Enter a number: 60
Output:
The number is not a prime and it is divided by 2: 30
3. 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 Accountant: 22440
Total salary of All Employee: 102080
4. Develop a C++ program for an electronic shop want to calculate the total price of
three (3) different product (computer, television and Air-condition). 30% flat discount
will be provide on base price of computer also 20% special discount provide on the
Deducted price after flat discount of computer. Similarly 25 % flat discount will be
providing on base price of television and 10% special discount provide on the
deducted price of television. And for air-condition only 20% flat discount provide.
Calculate the total price of the three products with the help of friend function.
Test Case:
Input:
Output:
Selling price of computer: 14000
Selling price of Television: 9450
Selling price of Air-condition: 27200
Test case-1:
Input:
Student’s Name: Rohan
Roll: 1
Marks of 5 subjects: 80 95 66 75 85
Sports name: Cricket
Score 60
Output
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
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
Total Marks: 396
2. 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.
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
3. A engineering institute maintain 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
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
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
3. 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.
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
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment No-11
Operator Overloading
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
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
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assigement-12
Exception Handling
Test case-1:
Input:
Enter values of a: 1
Enter values of a: 2
Enter values of a: 3
Output:
Result = -1
Test case-2:
Input:
Enter values of a: 1
Enter values of a: 2
Enter values of a: 2
Output:
Exception occurs! Division by zero
2. In a specific scenario, an application can have exception in three situations, for a specific
variable, if the value is zero, the application need to throw integer exception, if the value
is 1 then it will generate float exception and finally, if the value if -1, then it will generate
character exception . But while developing this application, it is to remember that there
will be only one exception checking module.
Test case-1:
Input:
Enter value: 0
Output:
Integer exception caught.
Test case-2:
Input:
Enter value: -1
Output: Character exception caught.