OOP Manual Update
OOP Manual Update
PRACTICAL MANUAL
NAME :
ROLL NO. :
REGISTER NO. :
BRANCH : B.E CSE
YEAR : II
SEMESTER : III SEM
KIT- KALAIGNARKARUNANIDHI INSTITUTE OF TECHNOLOGY
(An Autonomous Institute, Approved by AICTE & Affiliated to Anna University, Chennai)
Kannampalayam Post, Coimbatore -641 402
BONAFIDE CERTIFICATE
Name: ………………………………………………………………………………………………
Date:
7. Shutdown the Computer properly and arrange chairs in order before leaving the lab.
8. The program should be written on the left side pages of the record work book.
9. The record workbook should be completed in all aspects and submitted in the very next class itself.
10. Experiment number with date should be written at the top left corner of the record work book page.
11. Strictly follow the uniform dress code for Laboratory classes.
13. Avoid eatables inside and maintain the cleanliness of the lab.
OBSERV PERFOR VIVA- TOTA
SL. PAGE SIGNATUR
ATION MANCE VOCE L (75
NO DATE NAME OF THE EXPERIMENT NUMB E OF
(25 (40 (10 MARK
. ER FACULTY
MARKS) MARKS) MARKS) S)
Average:
Programme Outcomes (POs)
Students graduating from Computer Science and Engineering should be able to:
1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of Computer Science and Business Systems problems.
2. Problem Analysis: Identify, formulate, research literature, and analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics, natural sciences, and Computer Science and Business
Systems.
3. Design/Development of Solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and safety,
and the cultural, societal, and environmental considerations in the field of Computer Science and Business Systems.
4. Conduct Investigations of Complex Problems: Using research-based knowledge and Computer Science and
Business Systems oriented research methodologies including design of experiments, analysis and interpretation of
data, and synthesis of the information to provide valid conclusions.
5. Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and modern engineering and
IT tools including prediction and modeling to complex Computer Science and Business Systems Engineering
activities with an understanding of the limitations.
6. The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.
7. Environment and Sustainability: Understand the impact of the professional Computer Science and Business
Systems Engineering solutions in societal and environmental contexts, and demonstrate the knowledge, and need for
the sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and Team Work: Function effectively as an individual, and as a member or leader in diverse teams
and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering community
and with society at large, such as, being able to comprehend and write effective reports and design documentation,
make effective presentations, and give and receive clear instructions.
11. Project Management and Finance: Demonstrate knowledge and understanding of the Computer Science and
Business Systems engineering and management principles and apply these to one’s own work, as a member and
leader in a team and, to manage projects in multidisciplinary environments.
12. Lifelong Learning: Recognize the need for, and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES (PSOs)
After the successful completion of the U.G. programme in Computer Science and Engineering, Graduates will
be able to:
PSO1: Categorize the basic engineering knowledge to solve the problems in Computer Science and Engineering
according to the environmental needs.
PSO2: Apply the modern tools to design and develop the software system ethically to the industrial needs.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)
PEO1: Graduate will be successful in their profession by taking part actively in the field of software and
technology.
PEO2: Graduate will be proficient in analyzing and facing the challenge in computer science and engineering.
PEO3: Graduate will engage in lifelong learning activities by adapting to the advanced software technologies
for continuous professional development.
COURSE OUTCOMES
At the end of this course, the student will be able to:
Course Outcomes Knowledge
Level
CO1 Summarize the basics of Object-Oriented Programming concepts. K2
CO2 Make use objects, classes and functions in applications K3
CO3 Apply the concepts of constructors and destructors for object K3
creation and deletion
CO4 Analyse the use of inheritance, polymorphism through virtual, K4
overriding function and abstract class in programs.
CO5 Examine the concept of I/O operations and file streams using C++ K4
programming.
LIST OF EXPERIMENTS:
a) Write a C++ program to generate all the prime numbers between 1 and n, where
2. n is a value supplied by the user.
b) Write a C++ program to find both the largest and smallest number in a list of
integers.
Create a C++ program with a class named “Student” to store student’s details
3.
a) Implement an array of objects of the class to store details of multiple students.
b) Write functions to input data for each student and display details of all students.
Develop a C++ program with class named "Shape" with member variables
representing geometric shapes and member functions to calculate area and
perimeter.
4.
a) Use pointers to members to access and modify member variables dynamically.
b) Implement member functions to perform various operations on shapes, such as
scaling or rotating.
Define a class named "Complex" to represent complex numbers with real and
imaginary parts.
Write a C++ program to create a base class named "Shape" with a virtual function
7.
named calculateArea().
a) Derive classes like "Rectangle" and "Circle" from the Shape class.
b) Implement the calculateArea() function in each derived class to calculate the
area of the respective shape.
c) Demonstrate polymorphic behaviour by creating an array of Shape pointers and
assigning derived class objects to them.
d) Define a pure virtual function in the base class "Shape" called draw(), which has
no implementation.
Create a class named "Point" to represent 2D points with attributes x and y in C++
to
A) Implement member functions to set and display the coordinates of a point.
8.
B) Utilize this pointer to access the member variables within member functions.
C) Demonstrate the usage of the this pointer to differentiate between local variables
and member variables.
Write another program to read one line at a time from this file, perform the
9.
corresponding operation on the two complex numbers read, and write the result to
another file (one per line).
10. Write a C++ program to implement exception handling for file operations.
AIM:
To calculate the sum of the digits of a given positive integer using a C++ program.
PROCEDURE:
1. Start the program.
2. Declare integer variables number and sum, initialize sum = 0.
3. Prompt the user to input a positive integer.
4. Read the input number.
5. If number ≤ 0, display error and terminate.
6. While number > 0:
7. Get last digit using number % 10.
8. Add digit to sum.
9. Remove last digit using number /= 10.
10. Display the result.
11. End the program.
CODE:
SAMPLE OUTPUT:
INFERENCE:
VIVA VOCE:
AIM:
To write a C++ program to print the first n natural numbers using a loop.
PROCEDURE:
SAMPLE OUTPUT:
INFERENCE:
VIVA VOCE:
RESULT:
AIM:
To write a C++ program to print all prime numbers from 1 to n.
PROCEDURE:
VIVA VOCE:
RESULT:
AIM:
To write a C++ program to find the smallest and largest numbers in a list.
PROCEDURE:
INFERENCE:
VIVA VOCE:
2. How does the program determine the smallest and largest numbers after sorting?
RESULT
AIM:
To write a C++ program using a class named Student to store and display the details of multiple students using an
array of objects.
PROCEDURE:
INFERENCE:
VIVA VOCE:
RESULT:
TOTAL 75
Ex. No. 3.B
DISPLAY DETAILS OF ALL STUDENTS
Date
AIM:
To extend the previous student program by adding functions to input and display data for all students.
PROCEDURE:
VIVA QUESTIONS:
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No: 4.A POINTERS TO MEMBERS TO ACCESS AND MODIFY MEMBER
VARIABLES DYNAMICALLY
Date:
AIM:
To use pointers to members in a class Shape to access and modify geometric properties dynamically and
calculate area and perimeter.
PROCEDURE:
1. Define a class Shape with members: radius, length, width.
2. Define member functions for:
a. Area and perimeter of a circle and a rectangle.
3. Declare pointers to member variables and member functions.
4. Read shape parameters using pointers.
5. Invoke member functions using pointers to calculate results.
6. Display area and perimeter.
7. End the program.
CODE:
INFERENCE:
VIVA QUESTIONS:
1. What is the purpose of using member function pointers in this program?
2. What is the role of the pointers to member variables (like ptrRadius, ptrLength, and
ptrWidth)?
3. What would happen if the member function pointers were not used in this program?
RESULT:
AIM:
To write a C++ program with a Shape class that supports operations like scaling and rotating.
PROCEDURE:
1. Define a Shape class with members: radius, length, width.
2. Implement:
o calculateAreaCircle(), calculatePerimeterCircle()
o calculateAreaRectangle(), calculatePerimeterRectangle()
o scale(factor) to multiply dimensions
o rotate() to swap length and width
o displayDetails() to show shape properties
3. In main():
o Read shape dimensions.
o Call displayDetails().
o Scale the shape and show results.
o Rotate the rectangle and show updated results.
4. End the program.
CODE:
INFERENCE:
VIVA QUESTIONS:
2. How does the rotate() function affect the rectangle in this program?
3. Why is a constructor used in the Shape class, and what does it do?
RESULT:
TOTAL 75
Ex. No: 5.A OPERATOR OVERLOADING TO STRING
MANIPULATION
Date :
AIM:
To implement a class MyString in C++ that supports basic string manipulation using operator overloading for
+, ==, +=, and <<.
PROCEDURE:
VIVA QUESTIONS:
1. What is the purpose of operator overloading in this program, and how is it used?
2. How does the += operator work in this program, and why does it return a reference to *this?
3. Why is the const keyword used in the member functions of the MyString class (like in operator+
and display)?
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No 5.B
LAMBDA EXPRESSIONS TO SORT STRINGS
Date :
AIM:
To write a C++ program that sorts a list of strings in descending order using lambda expressions as custom
comparison functions.
PROCEDURE:
VIVA QUESTIONS:
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. 5.C
DEMONSTRATE THE USAGE OF OVERLOADED
No OPERATORS AND LAMBDA EXPRESSIONS
Date :
AIM:
To demonstrate the usage of overloaded operators and lambda expressions for string manipulation
within a C++ program.
PROCEDURE:
VIVA QUESTIONS:
RESULT:
1. AIM 10
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No. 6.A OVERLOAD BINARY OPERATORS FOR COMPLEX
Date NUMBER OPERATIONS
AIM:
To implement a C++ class Complex and overload binary operators +, -, *, and / to perform arithmetic
operations on complex numbers.
PROCEDURE:
VIVA VOCE:
RESULT:
AIM:
To overload unary operators (-, ++) in a Complex class to perform negation and increment operations.
PROCEDURE:
1. Define a Complex class with members real and imag.
2. Overload:
o Unary - to negate both real and imaginary parts.
o Pre-increment ++c to increment both parts and return updated object.
o Post-increment c++ to increment but return original value.
3. In main():
o Read input for one complex number.
o Create a Complex object.
o Apply unary operations and display results.
4. End the program.
CODE:
INFERENCE:
VIVA VOCE:
RESULT:
1. AIM 10
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. 6.C
No. OVERLOADING FUNCTIONS AS MEMBER FUNCTIONS
OR FRIEND FUNCTIONS
Date
AIM:
To demonstrate overloading of operators as both member and friend functions for a Complex class.
PROCEDURE:
1. Define a Complex class with private members real and imag.
2. Overload:
o Unary operators (-, ++, ++(int)) as member functions.
o Binary operators (+, -, *, /) as friend functions.
3. Implement a display() method for formatted output.
4. In main():
o Read two complex numbers.
o Create Complex objects.
o Perform and display results of all operations.
5. End the program.
CODE:
INFERENCE:
VIVA VOCE:
1.What is operator overloading in this program?
2. What is the difference between pre-increment (++c1) and post-increment (c1++) in this
program?
3. Why are friend functions used for the binary operators (+, -, *, /) in this program?
RESULT:
AIM:
To implement a base class Shape with a virtual function calculateArea(), and derive classes like
Rectangle and Circle that override this function.
PROCEDURE:
VIVA VOCE:
RESULT:
AIM:
To demonstrate runtime polymorphism using virtual functions by overriding calculateArea() in derived classes.
PROCEDURE:
]
INFERENCE:
VIVA VOCE:
1. What is the purpose of the pure virtual function calculateArea() in the Shape class?
RESULT:
AIM:
To demonstrate polymorphic behavior by using an array of base class (Shape) pointers to hold and invoke
methods on derived class objects.
PROCEDURE:
VIVA QUESTIONS:
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No: 7.D
PURE VIRTUAL FUNCTION
Date:
AIM:
To demonstrate the use of a pure virtual function draw() in an abstract class Shape and provide specific
implementations in derived classes.
PROCEDURE:
1. Create an abstract class Shape with a pure virtual function draw().
2. Derive classes Rectangle and Circle:
o Implement draw() to output shape-specific details.
3. In main():
o Create objects of derived classes.
o Call draw() on each to show polymorphic behavior.
4. End the program.
CODE:
INFERENCE:
VIVA QUESTIONS:
1. What is the purpose of using the virtual keyword in the Shape class?
3. Why is memory allocated using new and deallocated using delete in this program?
RESULT:
Ex. No.
8.A
2D POINTS
Date:
AIM:
To create a class Point in C++ that represents 2D points and includes member functions to set and display the
coordinates.
PROCEDURE:
VIVA QUESTIONS:
3. What happens when you create an object of the Point class, like Point p1;?
RESULT:
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No: 8.B ‘THIS’ POINTER TO ACCESS THE MEMBER
VARIABLES WITHIN MEMBER FUNCTIONS
Date :
AIM:
To demonstrate the use of the this pointer to access member variables inside member functions in a class
Point.
PROCEDURE:
VIVA QUESTIONS:
3. What happens if you don't use a constructor to initialize the Point object in this program?
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No 8.C
“THIS” POINTER TO DIFFERENTIATE BETWEEN
Date : LOCAL VARIABLES AND MEMBER VARIABLES
AIM:
To use the this pointer in a C++ program to differentiate between local variables and member variables having
the same names.
PROCEDURE:
Define a Point class with private members x and y.
In setCoordinates(int x, int y):
Use this->x = x; and this->y = y; to distinguish member variables from parameters.
Add a display() function to show x and y.
In main():
Create a Point object.
Call setCoordinates() with values.
Call display() to print the point.
End the program.
CODE:
INFERENCE:
VIVA QUESTIONS:
2. What is the purpose of using the modulo operator (%) in this program?
3. How does the program remove the last digit from the number?
4. What happens if the user enters a non-positive integer, and how does the program handle it?
RESULT:
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No 9
Date : COMPLEX NUMBER OPERATIONS FROM FILE
AIM:
To write a C++ program that randomly generates complex numbers and arithmetic operators, writes
them to a file, and then reads the file to perform the operations and write the results to another file.
PROCEDURE:
VIVA QUESTIONS:
1. What is the role of operator overloading in this program?
RESULT:
1. AIM 10
2. PROCEDURE / ALGORITHM 10
3. OBSERVATION 25
4. OUTPUT / RESULT 20
5. VIVA 10
TOTAL 75
Ex. No :10
EXCEPTION HANDLING FOR FILE OPERATIONS
Date:
AIM:
To write a C++ program that demonstrates exception handling during file operations such as opening,
reading, and writing to files.
PROCEDURE:
VIVA QUESTIONS: