B & B Institute of Technology Computer Department: Prepared By: L. A. Bhavnani
B & B Institute of Technology Computer Department: Prepared By: L. A. Bhavnani
B & B Institute of Technology Computer Department: Prepared By: L. A. Bhavnani
Computer Department
Practical-1:
Basic C++ programming using operators, reference variables, scope resolution, memory
management operator and manipulators.
1. Write a program using to read two numbers using Cin and print sum of numbers using
Cout statement.
2. Write a program to show the effects of manipulator setw() ,setfill() and endl.
3. Write a program to demonstrate use of setprecison() manipulator.
4. Write a program to demonstrate use of reference variable.
5. Write program to demonstrate use of scope resolution operator (::) .
6. Write program to demonstrate use of type cast operator.
7. Write a program for dynamic initialization of variables using memory management
operators.
8. Write a program to read and print array. Use new and delete operator to allocate and
deallocate memory of array at runtime.
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Practical 2:
2.1 Functions:
1. Write a program to swap given two numbers.
a. Using call by value
b. Using call by Address(pointer)
c. Using call by reference(reference variable)
2. WAP to print following using default arguments
a. repchar() // prints 45 times asterisks (*)
b. repchar ('=) // prints 45 times (=)
c. repchar('+',30) // prints 30 times (+)
3. Write a function to find simple interest for given interest rate. Use default
arguments for default interest rate of 15 %.
4. Write a function power() to raise a number m to power n. The function takes a
double value for m and int value for n, and returns the value (results) correctly. Use
default argument 2 for n and m to make a function to calculate squares when
argument is not passed. Write a program for the same.
5. Write a function called zerosmaller() uses two arguments. Use return by reference
to the function concept and set a smaller value to 0.
6. Write a program that prints various types of data using function overloading.
7. Write a program to find area of square, rectangle and cube using function
overloading.
8. Write a program to find volume of cylinder, cube and cuboid using function
overloading.
9. Write a program using inline function to add given two numbers.
10.Write a program to demonstrate use of constant arguments.
11.Write a recursive function to find factorial of a given number.
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
2.2 Structure
1. Write a program to reads student roll number, student name, student result .
Print student information on screen.
2. Define a structure student which contain no, name, result. Read at least 5 data of
students and print no, name, marks and result. Write a program to arrange above
data in descending order according to result. (Use function for sorting)
3. Define a structure student which contain no, name, marks of three subjects and
average _marks. Write a function
a) To read at least 5 data of students no, name, marks of three subjects & Calculate
average_marks of each student
b) To print only those students having average marks greater than 50.
4. Write a program which defines a structure that can describe a hotel. It should have
members that include the name, address, grade, average room charge and number
of rooms. The program should perform following operation using function
a) To print out hotels of a given grade in order of charges.
b) To print out hotels with room charges less than the given value
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Practical-3
Classes & Objects
1. Create a class player with the following data members
name, age, runs, hi, lo, tsts, avg
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the average of the player
2. Create a class item with the following data members
item code, cost, qty, total_price
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the total price of the item
3. Create a class book with the following data members
bookname, authorname, rate, qty
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the total price of the book
4. Create a time with the following data members
int h, m , s
Write member functions for each of the following
a. To get the data in number of seconds
b. To set the data in number of seconds
c. To display the data
d. To convert seconds into h, m, s
5. Create a student with the following data members
rollno, name, marks[6], per, class
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate percentage
d. To calculate class based on percentage
6. Write a program to count number of objects using static member and static
member function.
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Practical-4
Constructor and Destructor
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Practical-5
Inheritance
1. Assume that Circle is defined using radius and Cylinder is defined using radius and
height. Write a Circle class as base class and inherit the Cylinder class from it.
Develop classes such that user can compute the area of Circle objects and volume
of Cylinder objects. Area of Circle is pie *radius*radius, while volume of Cylinder
is pie*(radius * radius)*height.
2. Consider a class network as shown in figure given below. The class Employee
derives information from both Account and Admin classes which in turn derive
information from the class Person. Define all the four classes and write a program
to create, update and display the information contained in Employee objects.
3. Define class employee which has fname and lname as data member. Define
following:
1. Constructor for employee class with default arguments
2. Print function
Derive a class called hourly_worker (with wage and hours as data members).
Define following:
Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department
Prepared By : L. A. Bhavnani