Sunteți pe pagina 1din 5

A. D.

Patel Institute of Technology


Information Technology Department
2140705: Object Oriented Programming with C++
A. Y. 2018-19 Semester: II

Practical / Experiment List

(Practical Hours: 2 hours x 2 day per week, per batch)


Instructions:

1. Student should maintain soft copy of all the programs performed during lab sessions.
2. Laboratory File must contain the experiment list.

PRACTICAL NO: 1

OBJECTIVE: To learn about basic header files, data types, variables in C++.

1) Write a program to display “Hello World” message on output screen.


2) Write a program to do summation of two numbers.

PRACTICAL NO: 2

OBJECTIVE: To learn about control structure in C++.

1) Write a program to check whether the no is positive, negative or Zero.


2) Write a program to convert temperature from Fahrenheit to Celsius and vise a versa.
3) Write a program to convert distance from feet to meter and vise a versa.
4) Write a program to find maximum number among three numbers.
5) Write a program to check whether given year is leap year or not.
6) Write a program to implement simple calculator using switch-case.

PRACTICAL NO: 3

OBJECTIVE: To learn about loop structure in C++.

1) Write a program to find sum of n numbers.


2) Write a program to find the sum of even and odd numbers between 1 and 100.
22 33 𝑛𝑛
3) Write a program to solve given series 1 + − …+
2! 3! 𝑛!

PRACTICAL NO: 4

OBJECTIVE: To learn about 1D and 2D array in C++.

1) Write a program to read and display data for an array.


2) Write a program to find sum of all the elements of given array.
3) Write a program to sort the given data in ascending order using bubble sort.
4) Write a program to find maximum element from given array.
5) Write a Program to add two matrices.
PRACTICAL NO: 5

OBJECTIVE: To learn about character array and functions in C++.

1) Write a program to find length of given string using user defined function.
2) Write a program to reverse given string using user defined function.
3) Write a program to check whether the given string is palindrome or not.
4) Write a program to copy one string into another string using user defined function.
5) Write a program to concatenate two strings using user defined function.

PRACTICAL NO: 6

OBJECTIVE: To learn about structures in C++.

1) Write a program to create a structure called “Student” having idno, name and cpi as
structure data members. Develop a user defined function getdata( ) to read structure
data members and putdata( ) to display them.
2) Write a program to create a structure called “Student” having idno, name and cpi as
structure data members. Develop a user defined function searchdata( ) to search record
of given student and deletedata( ) to delete record of given student.
3) Write a program to create a structure called “Student” having idno, name and cpi as
structure data members. Develop a user defined function sortdata( ) to sort student’s
data in ascending order of cpi.

PRACTICAL NO: 7

OBJECTIVE: To learn about new and delete operators in C++.

1) Write a program to dynamically create memory (using new operator) for two variables
and free the memory (using delete operator) after displaying content of it.
2) Write a program to dynamically create memory (using new operator) for an integer
array and free the memory (using delete operator) after displaying content of it.
3) Write a program to dynamically create memory (using new operator) for an integer
array. Find sum of all the elements of array using pointer.
4) Write a program to dynamically create memory (using new operator) for two integer
array. Find addition of two array and store result into third array using pointer.

PRACTICAL NO: 8

OBJECTIVE: To learn about inline function in C++.

1) Write a program to find volume of cube using inline function.


2) Write a program to swap two numbers using call by value to a function defined as
inline.
3) Write a program to swap two numbers using call by reference to a function defined as
inline.
PRACTICAL NO: 9

OBJECTIVE: To learn about function overloading in C++.

1) Write a program to find volume of cube, cylinder and rectangular box using function
overloading.
2) Write a program to overload add function. Add function can add two integer numbers,
three integer numbers and two float numbers.

PRACTICAL NO: 10

OBJECTIVE: To learn about class with data, object and function

1) Write a program which demonstrate the use of class and object. Create a class student
with student name and age as data members. Create member functions to read and display
the data members.
2) Create a class item having members name, item_code and price. Make two functions 1)
voidgetdata() which reads the data for item. 2) void display() which display the data.
Take data for 10 items.

Extra Programs:

3) Create a class Employee having members Emp_Id, Emp_Name and Basic Salary. Make
three functions 1) void readdata() which reads the data for n employee. 2) void
displaydata() which display the data of n employee. 3) Void Calculate_Salary() which
calculates gross salary of employee.
Gross Salary = Basic Salary + DA (80% of Basic Salary)+ HRA (10% of Basic Salary)

PRACTICAL NO: 11

OBJECTIVE: To learn about Inline function and Friend function with Class.

1) Write a program to create a class time with two data members; int minutes and int hours.
Create member functions: getdata() to assign value to the data member and display() to
display data member values. Declare both the member functions as inline.
2) Write a program to create two classes alpha and beta with one data member int data and
one public member function getdata() to assign value to data member. Create a friend
function to both the classes which will find the maximum data variable from both the
classes.
3) Write a program to create a class distance with two data members; int feet and float
inches. Create appropriate member functions to assign and display data member values.
Define a non-member function add(distance,distance) which will perform addition of the
data members of two different objects of the class distance.
4) Write a program to create a class time with two data members; int minutes and int hours.
Create appropriate member functions to assign and display data member values.
Define following non-member function:
time add(time,time);
which will perform addition of the data members of two different objects of the class
time and return the addition in the form of object.

Extra Programs:

5) Write a program to create a class complex with two data members; int real and int img.
Create appropriate member functions to assign and display data member values.
Define following non-member function:
complex add(complex, complex);
which will perform addition of the data members of two different objects of the class
complex and return the addition in the form of object.
6) Write a program to swap private data member of two different class using friend function.
7) Write a program to create class matrix with 2-D array as data members. Create
appropriate member functions to read and display matrix. Define a non-member function
transpose(matrix) which will transpose given matrix.

PRACTICAL NO: 12

OBJECTIVE: To learn about constructor and destructor functions.

Extra Programs:

1) Write a program to create a class complex with two data members; float real and float
img. Create default, single argument and two argument constructors to initialized data
members. Define following member function:
complex sum(complex, complex); which will perform addition of the data members of
two different objects of the class complex and return the addition in the form of object.
Define display( ) member function to display data member.
2) Write a program to create a class Fixed_deposit with four data members; long int p, int
years, float rate and float Ret_value. Create default constructor, three argument
constructor with default interest rate 12%, three argument constructors with rate value as
integer and float, to initialized data members. Define display( ) member function to
display return value.

3) Write a program to initialize and display the data of an employee using a default
constructor, with argument constructor and copy constructor.
4) Write a program to create a class room with three data members: height, length and width.
Define appropriate constructors to initialize the data member values. Create appropriate
member functions for displaying the data at the end. Use destructors appropriately.
5) Writer a function called power (n, p) which takes double value for n and int value for p
and returns a result as a double value. Use a default argument of 2 for p. write A main ()
function that gets the value from user and test the function. Use appropriate class with
constructor and destructor.

Extra Program:

6) Write a program to create a class string with two data members; char pointer name and
int length. Create default and one argument constructors to initialized data members
using new operator. Define join () member function to concatenate two strings. Define
display( ) member function to display string.

PRACTICAL NO: 13

OBJECTIVE: To learn about Operator overloading.

1) Write a program to declare a class Counter with one data member (unsigned int count).
Define appropriate constructor and other member functions. Overload unary increment
operator (++) and demonstrate the same using appropriate main () function.
2) Write a program to declare a class Space with three data member (int x, y, z). Define
appropriate constructor and other member functions. Overload unary minus operator (-)
and demonstrate the same using appropriate main () function.
3) Write a program to declare a class distance with two data members inches and feet.
Define appropriate constructor and other member functions. Overload + operator to add
the data member values of two objects of the class.
4) Write a program to declare a class Complex with two data member real and img. Define
default and appropriate constructor. Overload * operator to multiply constant value to
data members using friend function.
5) Write a program to create a class string with two data members; char pointer name and
int length. Create default and one argument constructors to initialized data members
using new operator. Define copy constructor. Overload + and >= operators to concatenate
two strings and compare two strings, respectively. Define display( ) member function to
display string.

6) Define two classes Celsius and Fahrenheit to represent temperature in the Celsius and
Fahrenheit systems. Use type conversion routines to convert from one system to another.
Example:
C = F;
(C × 9/5) + 32 = F
7) Write a program to declare a class distance with two data members inches and feet.
Define appropriate constructor and other member functions. Use type conversion routine
which supports the following statement:
Distance dist1 = 2.35;
(Note: 1 meter = 3.280833 feet)

PRACTICAL NO: 14

OBJECTIVE: To learn about Inheritance.

1) Write a program to declare a class employee having data members id, name and
designation with appropriate member functions. Derive class called salary containing two
data members basic and hra with appropriate member functions. Demonstrate the use of
single inheritance by entering one employee information and display the same. (hra =
20%)
2) Design a class called vehicle having a unique vehicle number as member declared as
protected. Derive a class called car having members as number of seats and maximum
speed limit. Demonstrate the use of single inheritance and the importance of protected
data members.
3) Design a class called student having a unique enrolment number as member declared as
protected, getdata() and putdata() declared as public member functions. Derive a class
called test from student having marks of two subjects as members declared as protected,
getdata() and putdata() declared as public member functions. Derive a class called result
from test having total marks of two subjects and display() as member. Demonstrate the
use of multilevel inheritance and the importance of protected data members.
4) Declare the base class student. Define the function getdata() to get the student details.
Declare the other class test. Define the function getmarks() to read the marks of two
subjects. Declare a class sports. Define the function get_score() to read the score. Create
the class result derived from test and sports. Define the function display () to find out the
total score (two subject marks + score) along with student detail.  Hybrid Inheritance

Course Coordinator

Dr. D. J. Prajapati
Associate Professor,
IT Department,
ADIT.

S-ar putea să vă placă și