Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C++ Programming Assignment 2024

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

C++ Programming- LAB Assignment

BCA 2nd Year 3rd Semester

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.

3. Write down a C++ program to display model_number, price,


seat_capacity and vehicle_type (private or public) by define a class
‘vehicle’ , which contain two object i.e. Bus and Car.

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

1. A mathematical research and implementation institute needs to take a


number from user. It is required to multiply the data by 2 if it is a
palindrome number. Otherwise it needs to divide by 2 and display the
output. For security reasons, the data must be encapsulated.

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:

Details of All student

ROLL NAME AGE SUB-1 SUB-2 SUB-3


1 Rohan 19 81 67 78
2 Saikat 20 34 56 81
3 Monaj 19 45 56 46

Total marks of Student-1 is: 226


Average marks of student-1 is: 75.33
Total marks of Student-2 is: 171
Average marks of student-2 is: 57.00
Total marks of Student-3 is: 147
Average marks of student-3 is: 49.00

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

Topper of the BCA 3rd semester

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

1. 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)]

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:

Value before exchange a and b:


100
200
Value after exchange a and b:
200
100

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

Brand model year price


BMW X500 1999 290000
FORD M230 2002 320000
TATA A502 1998 270000

2. 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:

Enter the number to find factorial: 5


Printing from constructor:
Factorial of 5 is 120
Printing from copy constructor:
Factorial of 5 is 120

Constructor overloading

3. 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

Area of the circle is: 153


Perimeter of the circle is: 43
The area of rectangle is: 40
The volume of cube is: 288
Function Overloading

4. 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

Enter float data to search: 9.01


Data not found
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment No-7
Function Overloading

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:

Input: calculate(3, 4, 8);


Output: Sum = 15
Average = 5

Test case-2:

Input: calculate(6, 4, 5.3);


Output: Sum = 15.3
Average = 5.1

2. An organization holds 4 different types of employee (manager, developer,


accountant and group-D staff). The salary brake up are given bellow:

Employee Basic DA HRA TA Medical


Type
Manager 40000.50 16000.2(40% 6000 ( 15% 1000 ---
of Basic) of basic)
Developer 30000 12000 (40% OF 4500 ( 15% 500 -----
Basic) of basic)
Accountant 20000 10000 3000 ----- ------
Group-D 10000.50 ----- ----- ----- 500

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

Basic of Manager is: 40000.50


DA of Manager is: 16000.20
HRA of Manager is: 6000
TA of Manager is: 1000
Total Salary of Manager is: 63000
_____________________________
Basic of Developer is: 30000
DA of Developer is: 12000
HRA of Developer is: 4500
TA of Developer is: 5000
Total Salary of Developer is: 47000
_____________________________
Basic of Accountant is: 20000
DA of Accountant is: 10000
HRA of Accountant is: 3000
Total Salary of Accountant is: 33000
_____________________________
Basic of Group-D: 10000.50
Medical of Group-D: 500
Total salary of Group-D is: 10500

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

Details of all books:

ISBN Page Price


101 600 420
122 720 540
133 550 610

The total price of all books: 1570


The average price of all books: 523
Highest book price and ISBN: PRICE: 610 ISBN: 133
Lowest book price and ISBN: PRICE: 420 ISBN: 101

2. Develop an application program in C++ by implementing the concept of constructor


to check a number is a prime or not. If the number is a prime number then the
number will be multiplied by 2 and if the number is not a prime number, the number
divided by 2.

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:

Enter basic salary of Manager: 25000


Enter basic salary of Developer: 20000
Enter basic salary of Accountant: 15000

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:

Enter price of Computer: 25000


Enter price of Television: 14000
Enter price of Air-Condition: 34000

Output:
Selling price of computer: 14000
Selling price of Television: 9450
Selling price of Air-condition: 27200

Total selling price of all products: 56650


C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment No-9
[Inheritance]

1. 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

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

Total salary : 45000


Engineering incentive: 5400 [60% of Rs. 9000]
Management incentive: 4000 [40% of Rs. 10000]

Grand total salary: 54400

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

4. Write down a C++ program to demonstrate the hybrid inheritance concept.


C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester
Assignment No-10
Operator Overloading

1. 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

2. 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

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

1. 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

2. 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.

Test case-1:
Input:
Enter real part of the complex number: 4
Enter img part of the complex number: 6

Enter real part of the complex number: 3


Enter img part of the complex number: 2

Output:

First complex number: 4 + 6i


Second complex number: 3 + 2i

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

Enter real part of the complex number: 4


Enter img part of the complex number: 3

Output:

First complex number: 9 - 2i


Second complex number: 4 + 3i

Addition: 13 + 1i
Subtraction: 5 - 5i
C++ Programming- LAB Assignment
BCA 2nd Year 3rd Semester

Assigement-12
Exception Handling

1. A research institute need to develop an application to embed a formula a/(b-c). Values of


a, b and c will be randomly given by the user. It is required to consider any exceptional
condition and need to handle if any. Model the above requirement using object oriented
programming concepts.

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.

You might also like