C++ Lab R19

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

Swarnandhra College of Engineering & Technology - CBCS (Autonomous)

L T P C
SEMESTER-II
0 0 3 1.5
OBJECT ORIENTED PROGRAMMING THROUGH C++ LAB

COURSE OUTCOMES:
At the end of the Course, Student will be able to:
1. Able to differentiate structure oriented programming and object oriented programming.
2. Able to understand and apply various object oriented features.
3. Able to know concepts in operator overloading, function overloading & polymorphism.
4. Able to write, compile and debug programs in C++ language.
5. Design programs involving constructors, destructors.
6. Able to reuse of code using inheritance.
7. To implement the concept of files, templates and exceptions.
8. To write diversified solutions using C++ language.

EXERCISE-1(BASICS)

A. Write a CPP Program to demonstrate the structure of a C++ program.


B. Write a CPP Program to display the names of header files, definitions and list of functions
supported.
C. Write a program to show the base of a numeric value of a variable using Hex, Oct and Dec
manipulator functions.
D. Write a CPP Program to use of the standard manipulators normally used in the stream classes.
E. Write a CPP Program to demonstrate the usage of bit fields.
F. Write a CPP Program to define constant pointer and pointer to constant and perform possible
operations.
G. Write a CPP Program access a variable in different scopes by using scope resolution operator
and the use of comma operator.

EXERCISE-2(CLASSES & OBJECTS)

A. Write a CPP Program to swap two numbers using call by value, call by address, call by reference
and return by reference.
B. Write a CPP Program to calculate square and cube of a number using inline functions and
macros. (Demonstrate the use of inline functions compared to macros).
C. Write a CPP Program to find the area of a rectangle, a triangle and surface area of a sphere using
function overloading.

B.TECH/CSE/2019 (CBCS) 13
Swarnandhra College of Engineering & Technology - CBCS (Autonomous)

D. Write a CPP Program to declare all members of a class as public, Access the members using
objects. (Use public, protected, private).
E. Write a CPP Program to access the member functions inside and outside a class.
F. Write a CPP Program to access private data using non-member functions. (Use friend function).
G. Write a CPP Program to pass objects to functions by pass by value method.
H. Write a CPP Program to declare main () function as member function and overload it.

EXERCISE-3(CONSTRUCTORS AND OPERATOR OVER LOADING)

A. Write a CPP Program to show that “for each object constructors is called separately” and read
the values through keyboard (Use Constructor).
B. Write a CPP Program to create constructor with arguments and pass the arguments to
constructor.
C. Write a CPP Program to create object and release them using destructor.
D. Write a CPP Program to perform addition, subtraction, multiplication of two objects using
operator keyword.
E. Write a CPP Program to overload unary and binary operator overloading with friend function.

EXERCISE-4(INHERITANCE AND POLYMORPHISM)

A. Write a CPP Program to derive a class publicly from base class. Declare base class members
under public, private and protected.
B. Write a CPP Program to derive single and multiple inheritances.
C. Write a CPP Program to declare virtual base class. Derive a class using two virtual classes.
D. Write a CPP Program to implementation of Virtual Function.
E. Write a CPP Program to Implementation of Pure Virtual Function.

EXERCISE- 5(FILES, TEMPLATES AND EXCEPTION HANDLING)

A. Write a CPP Program to write and read text in a file. Use ofstream and ifstream classes.
B. Write a CPP Program to open a file for writing and reading purpose. Use open () function.
C. Write a CPP Program write text in a file. Read the text from the file from EOF. Display the
contents in reverse order.
D. Write a CPP Program to demonstrate that the data is read from file using ASCII format.
E. Write a CPP Program to find the factorial of a number. Throw multiple exceptions and define
multiple catch statements to handle exceptions.
F. Write a C++ Program to illustrate template class

Practice Programms

B.TECH/CSE/2019 (CBCS) 14
Swarnandhra College of Engineering & Technology - CBCS (Autonomous)

1. Write C++ Program to Create Floyd's Triangle


2. Write a C++ program Add Two Matrices using Multi-dimensional Arrays
3. Write a C++ program Multiply Matrix by passing it to a Function
To perform this task three functions are made:
To take matrix elements from user
To multiply two matrix
To display the resultant matrix after multiplication
4. Write a C++ program to create a class for student to get and print details of N students.
(C++ program to demonstrate example of array of objects.)
5. Write a C++ program to convert time from HH:MM:SS format to seconds using class
6. Write a C++ program to convert time from seconds to HH:MM:SS format using class
7.Write a C++ program to define a class employee having members Emp-id, Emp-name,
basic salary and functions accept() and display(). Calculate DA=25% of basic salary,
HRA=800, I-tax=15% of basic salary. Display the pay slip using appropriate output
format.
1) To accept the data
2) To display the data

8. Write a C++ Program to check prime Number or not using class


9. To create a class staff having fields: Staff-id , name, salary and functions accept() and
display(). Calculate DA=25% of basic salary, HRA=800, I-tax=15% of basic salary.
Display the pay slip using appropriate output format.
1) To accept the data
2) To display the data
3) To sort the data by name
10. To define a class to represent a bank account. Include the following members:
Data members:
1) Name of the depositor
2) Account number
3) Type of account
4) Balance amount in the account.
Member functions:
1) To assign initial values
2) To deposit an amount

B.TECH/CSE/2019 (CBCS) 15
Swarnandhra College of Engineering & Technology - CBCS (Autonomous)

3) To withdraw an amount after checking the balance


4) To display name and balance.
11. To create a class for an electricity board that charges the following rates to users
a) For first 100 units : 40p per unit
b) For next 200 units : 50p per unit
c) Beyond 300 units : 60p per unit
All users are charged a minimum of Rs.500. If the total cost is more than Rs.250.00 then an additional
charges of 15% are added.
Write a C++ program using class to read the names of users & number of units consumed & print out
the charges with names.
12. Write C++ program to demonstrate Overloading new and delete operator
13. Write C++ program to compare two Strings using Operator Overloading
14. Write C++ Program to concatenate two strings using Operator Overloading
15. Write a C++ Program to Find the Number of Vowels, Consonants,Digits and White Spaces in a
String
16. Write a C++ Program to remove all Characters in a String except Alphabets.
17. Write a C++ Program to Find the Frequency of Characters in a String
18) Write C++ Program for remove all duplicates from the input string. Print all the duplicates in the
input string.
19. Write C++ Program for remove characters from the first string which is present in the second
string
20. Write C++ Program to check if strings are rotations of each other or not
21. Write C++ Program to read a string .Add the same string in the reverse order to the end of the
same string.
22. Write a C++ program to read a string. Change the first letter of every capital word.
23. Write C++ program to declare string objects .Perform assignment and concatenation with the
string objects.
24. Write C++ program to perform string operations using string library functions.
25. Write C++ Program for return maximum occurring character in the input string
26. Write C++ program using string manipulating functions.
27. Write a C++ Program to Implement Stack in STL using the following
1. Insert Element into the Stack
2. Delete Element from the Stack
3. Size of the Stack
4. Top Element of the Stack

B.TECH/CSE/2019 (CBCS) 16
Swarnandhra College of Engineering & Technology - CBCS (Autonomous)

5. Exit
28. Write a C++ Program to Implement String in STL using following
1. Insert Substring in a String
2. Erase Substring from a String
3. Append Substring to a String
4. Replace the String with a Substring
5. Size of the String
6. Find substring in a String
7. Display the String
8. Exit
29. Write a C++ Program to Implement Array in STL using following
1. Insert Element into the Array
2. Size of the array
3. Front Element of Array
4. Element of Array
5. Display elements of the Array
6. Exit
30. Write C++ program to implement Bubble Sort using templates in C++

B.TECH/CSE/2019 (CBCS) 17

You might also like