0% found this document useful (0 votes)
8 views4 pages

C++ Lab assignment

The document outlines a series of programming assignments for a C++ lab course, covering various topics such as class definitions, operator overloading, and data structures. Each assignment includes specific tasks like creating classes for student records, bank accounts, and geometric shapes, as well as implementing functions for matrix operations and exception handling. The assignments aim to enhance students' understanding of C++ programming concepts and practical applications.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
8 views4 pages

C++ Lab assignment

The document outlines a series of programming assignments for a C++ lab course, covering various topics such as class definitions, operator overloading, and data structures. Each assignment includes specific tasks like creating classes for student records, bank accounts, and geometric shapes, as well as implementing functions for matrix operations and exception handling. The assignments aim to enhance students' understanding of C++ programming concepts and practical applications.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

INTERNATIONAL INSTITUTE OF PROFESSIONAL STUDIES DEVI AHILYA UNIVERSITY, INDORE

M. Tech. (IT) 5 Years II SEMESTER IT-207B: C++ Programming Lab


Lab Assignment
1. Write a program to display the minimum, maximum, sum, search and average of elements of an array.
2. Define a class student with the following specification
Private members of class student
admno integer
sname 20 character
eng. math, science float
total float
Public member function of class student
ctotal() a function to calculate eng + math + science with float return type.
Takedata() Function to accept values for admno, sname, eng, science Showdata()
Function to display all the data members on the screen
3. Define a class in C++ with following description:
Private Members
A data member Flight number of type integer
A data member Destination of type string
A data member Distance of type float
A data member Fuel of type float
A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call
function CALFUEL() to calculate the quantity of Fuel.
A function SHOWINFO() to allow user to view the content of all the data members.
4. Write a menu driven program to perform following:
a) Input a matrix
b) Display matrix
c) Add two matrix
d) Multiply two matrixes
e) Transpose a matrix
5. Write a C++ program for calculating volume of sphere, cuboid and cylinder using function overloading.
6. Write the definition for a class called complex that has floating point data members for storing real and
imaginary parts. The class has the following member functions:
void set(float, float) to set the specified value in object
void disp() to display complex number object
complex sum(complex) to sum two complex numbers & return complex number
1. Write the definitions for each of the above member functions.
2. Write main function to create three complex number objects. Set the value in two objects and call sum() to
calculate sum and assign it in third object. Display all complex numbers.
7. Write the definition for a class called Rectangle that has floating point data members length and width. The
class has the following member functions:
void setlength(float) to set the length data member
void setwidth(float) to set the width data member
float perimeter() to calculate and return the perimeter of the rectangle
float area() to calculate and return the area of the rectangle
void show() to display the length and width of the rectangle
int sameArea(Rectangle) that has one parameter of type Rectangle. sameArea returns 1 if the two
Rectangles have the same area, and returns 0 if they don't.
1. Write the definitions for each of the above member functions.
2. Write main function to create two rectangle objects. Set the length and width of the first rectangle to 5 and
2.5. Set the length and width of the second rectangle to 5 and 18.9. Display each rectangle and its area and
perimeter.
3. Check whether the two Rectangles have the same area and print a message indicating the result. Set the
length and width of the first rectangle to 15 and 6.3. Display each Rectangle and its area and perimeter
again. Again, check whether the two Rectangles have the same area and print a message indicating the
result.
8. Write a date class with data members dd, mm, yy. Write a constructor and overload ++ operator, << operator
and >> operator.
9. Develop a mark sheet in C++ for university examination with following data:
a) Students’ name
b) Enrolment no
c) roll no
d) Theory marks in 5 subjects
e) Practical marks in five subjects
f) grade
Overload << and >> operator .Grade should be calculated for each subject. Use Constructor overloading. Roll
no should be auto generated.
10. Write a menu driven program for addition, subtraction, display result of two distances (given in meter and
centimetre) .
i. Overload ‘+’ operator with member function
ii. Overload ‘–‘ operator using friend function
iii. Overload << and >> operator
11. Create a class time with hours and minutes as its data members. Write a C++ program which has a member
function to overload binary operator + to add two times. Also overload relational operator > to compare 2
times. It should also overload << (output) and >>(input) operator.
12. Create an array class. In it dynamically allocate memory for integer array of size according to value passed to
constructor, and write following methods
i. copy constructor
ii. destructor
iii. Overload [ ] operator.
iv. Overload << , >>operator.
13. Define a class to represent a Bank Account. Include the following members:
Data Members:
i. Name of the depositor
ii. Account number
iii. Type of account
iv. Balance amount in the account
Member Functions:
1. To Input initial values
2. To deposit an amount
3. To withdraw an amount after checking the balance
4. To display name and balance
Also write constructor for this class that takes four arguments. It should also handle type of account as
savings by default.
14. Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The
saving account provides compound interest and withdrawal facilities but no cheque book facility. The
current account provides cheque book facility but no interest. Current account holders should also maintain
a minimum balance and if the balance falls below the level, a service charge is imposed.
Create a class account that stores customer name, account number and type of account. From this derive
the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary
member functions in order to achieve the following tasks:
a. Include constructor for all the three classes.
b.Accept deposit amount from the customer and update the balance.
c. Display the balance.
d.Compute and deposit interest.
e. Permit withdrawal and update the balance.
f. Check for minimum balance, impose penalty, necessary and update the balance.
15. An educational institution wishes to maintain a database of its employees. The database is divided into
number of classes whose hierarchical relationships are shown in below figure. The figure also shows
minimum information required for each class. Specify all the classes and define functions to create the
database and retrieve individual information as and when required.

16. Create a base class called shape .Use this class to store two double type values that could be used to compute
the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the
base class, a member function get_data() to initialise base class data members and another member function
display_area() to compute and display the area of figures. Make display_area () as a virtual function and
redefine this function in the derived class to suit their requirements.
Using these three classes, design a program that will accept dimensions of a triangle or a rectangle
interactively and display the area.
Area of rectangle = x*y
Area of triangle = ½*x*y
17. Write a program to read a list containing item name, item code and cost interactively and produce a
three column output as shown below:

Note that the name and code are left justified and the cost is right-justified with a precision of two
digits. Training zeros are shown. Also fill the unused spaces with hyphens.
18. Write a program to create a class EMP which have data member Name, Employee ID, contact number,
address, year of joining and department in which he/she is working with data member get and put. Create a
database of minimum 300 employees. Store and retrieve information on the basis of above configuration.
19. Create a class Inventory which performs the following operations on the file STOCK.DAT
a. Adds a new item to the file
b. Modifies the details of an item
c. Displays the contents of the file
20. Write a program to create a class EMP which have data member Name, Employee ID, contact number,
address, year of joining and department in which he/she is working with data member get and put. Create a
database of minimum 300 employees. Store and retrieve information on the basis of above configuration.
21. Write a function template for finding the minimum value contained in an array.
22. Write a class template to represent a generic vector. Include member function to perform the following
tasks:
a. To create the vector
b. To modify the value of a given element
c. To multiply by a scalar value
d. To display the vector in the form (10, 20, 30……)
23. Write a program with following:
a. A program to read two double type numbers from keyboard
b. A function to calculate the division of these two numbers
c. A try block to throw an exception when a wrong type of data is keyed in
d. try block to detect and throw an exception if the condition “divide by zero” occurs
e. Appropriate catch block to handle the exception thrown

You might also like