Oops Iv 11072023
Oops Iv 11072023
Oops Iv 11072023
LABORATORY MANUAL
B.Tech. Semester- IV
DEPARTMENT OF CSE/CSIT/IT/IOT
DRONACHARYA COLLEGE OF ENGINEERING
KHENTAWAS, FARRUKH NAGAR, GURUGRAM (HARYANA)
Object Oriented Programming Lab Using C++ (LC-CSE-214G)
Table of Contents
1. Vision and Mission of the Institute
2. Vision and Mission of the Department
3. Programme Educational Objectives (PEOs)
4. Programme Outcomes (POs)
5. Programme Specific Outcomes (PSOs)
6. University Syllabus
7. Course Outcomes (COs)
8. CO- PO and CO-PSO mapping
9. Course Overview
10. List of Experiments
11. DOs and DON’Ts
12. General Safety Precautions
13. Guidelines for students for report preparation
14. Lab assessment criteria
15. Details of Conducted Experiments
16. Lab Experiments
VISION OF INSTITUTE
To impart Quality Education, to give an enviable growth to seekers of learning, to groom them as World Class
Engineers and managers competent to match the expending expectations of the Corporate World has been ever
enlarging vision extending to new horizons of Dronacharya College of Engineering
MISSION OF INSTITUTE
1. To prepare students for full and ethical participation in a diverse society and encourage lifelong learning
by following the principle of ‘Shiksha evam Sahayata’ i.e. Education & Help.
2. To impart high-quality education, knowledge and technology through rigorous academic programs,
cutting-edge research, & Industry collaborations, with a focus on producing engineers& managers who are
socially responsible, globally aware, & equipped to address complex challenges.
3. Educate students in the best practices of the field as well as integrate the latest research into the academics.
4. Provide quality learning experiences through effective classroom practices, innovative teaching practices
and opportunities for meaningful interactions between students and faculty.
5. To devise and implement programmes of education in technology that are relevant to the changing needs
of society, in terms of breadth of diversity and depth of specialization.
VISION OF DEPARTMENT
“To become a Centre of Excellence in teaching and research in Information Technology for
producing skilled professionals having a zeal to serve society”
M1: To create an environment where students can be equipped with strong fundamental concepts,
programming and problem-solving skills.
M2: To provide an exposure to emerging technologies by providing hands on experience for
generating competent professionals.
M3: To promote Research and Development in the frontier areas of Information Technology and
encourage students for pursuing higher education
M4: To inculcate in students ethics, professional values, team work and leadership skills.
University Syllabus
1. [Classes and Objects] Write a program that uses a class where the member functions are defined inside a class.
2. [Classes and Objects] Write a program that uses a class where the member functions are defined outside a class.
3. [Classes and Objects] Write a program to demonstrate the use of static data members.
4. [Classes and Objects] Write a program to demonstrate the use of const data members.
5. [Constructors and Destructors] Write a program to demonstrate the use of zero argument and parameterized
constructors.
6. [Constructors and Destructors] Write a program to demonstrate the use of dynamic constructor.
7. [Constructors and Destructors] Write a program to demonstrate the use of explicit constructor.
9. [Operator Overloading] Write a program to demonstrate the overloading of increment and decrement operators.
12. [ Templates and Generic Programming] Write a program to demonstrate the use of function template.
Upon successful completion of the course, the students will be able to:
C214.1: Understand the features of C++ supporting object oriented
programming
C214.2: Understand the relative merits of C++ as an object oriented
programming language
C214.3: Understand how to produce object-oriented software using
C++.
C214.4 Understand how to apply the major object-oriented concepts to implement
object
. C214.5: Understand advanced features of C++ specifically stream I/O, templates and
operator overloading
CO-PO Mapping
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
C214.1 1 1 3 2 3 1 3 1
C214.2 1 3 3 2 3 1 3 1
C214.3 1 3 3 2 3 1 3 1
C214.4 1 3 3 2 3 1 3 1
C214.5 1 1 3 2 3 1 3 1
CO-PSO Mapping
PSO1 PSO2 PSO3
C214.1 2 2
C214.2 2 2
C214.3 2 2
C214.4 2 2
C214.5 2 2
Course Overview
The Object-Oriented Programming using C++ course is designed to provide students with a solid foundation in
object-oriented programming principles and the C++ programming language. Throughout the course, students
will learn how to design, implement, and manipulate objects to solve complex problems. The course will cover
key concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
1. Lab Setup: The lab should provide a computer environment equipped with the necessary software tools and
compilers for C++ programming. This includes an integrated development environment (IDE) or a text editor, a C++
2. Programming Exercises: The lab sessions typically involve a series of programming exercises that cover various
aspects of C++ programming. These exercises may focus on topics like basic syntax, control structures, functions, arrays,
classes, inheritance, polymorphism, data structures, algorithms, file handling, and more.
3. Hands-on Coding: In the lab, students are encouraged to actively write code to solve programming problems and
complete the given exercises. They can experiment with different programming techniques, implement algorithms, and
4. Debugging and Error Handling: Debugging is an essential part of programming, and the lab provides an
environment for students to practice debugging techniques. Students learn to identify and fix errors in their programs, use
debugging tools to trace program execution, and handle exceptions that may occur during program execution.
5. Lab Assignments/Projects: Lab courses often include assignments or projects that require students to work on more
extensive programming tasks. These assignments may involve developing software applications, implementing algorithms,
solving coding problems, or working on group projects to encourage teamwork and collaboration.
6. Code Review and Feedback: Lab instructors or teaching assistants provide guidance, review students' code, and
offer feedback on their programming solutions. This helps students improve their coding style, understand best practices,
1 Write a program that uses a class where the member functions are defined inside a class. C214.1,
C214.3
2 Write a program that uses a class where the member functions are defined outside a class. C214.3
5 Write a program to demonstrate the use of zero argument and parameterized constructors. C214.2
9 C2144
Write a program to demonstrate the overloading of increment and decrement operators
10 Write a program to demonstrate the multilevel inheritance. C214.5
DON’Ts
1. Do not share your username and password.
2. Do not remove or disconnect cables or hardware parts.
3. Do not personalize the computer setting.
4. Do not run programs that continue to execute after you log off.
5. Do not download or install any programs, games or music on computer in Lab.
6. Personal Internet use chat room for Instant Messaging (IM) and Sites is strictly prohibited.
7. No Internet gaming activities allowed.
8. Tea, Coffee, Water & Eatables are not allowed in the Computer Lab.
Emergency : Reception
Note:
1. Students must bring their lab record along with them whenever they come for the lab.
LAB EXPERIMENTS
LAB EXPERIMENT 1
OBJECTIVE: Write a program that uses a class where the member functions are defined inside a
class.
BRIEF DESCRIPTION:
Member functions are defined inside a class and provide the behavior or actions that objects of that class
can perform. They are also referred to as methods. Member functions can access and manipulate the data
members (variables) of the class and can interact with other objects of the same or different classes.
PRE-EXPERIMENT QUESTIONS:
Explanation:
#include<iostream.h>
class car
{
Private:
Int car_number;
Char car_model[10];
Public:
void getdata()
{
cout<<"Enter car number: "; cin>>car_number;
{
Car c1;
c1.gatdata()
c1.showdata();
return 0;
}
Output:
LAB EXPERIMENT 2
OBJECTIVE:
Write a program that uses a class where the member functions are defined outside a
class.
BRIEF DESCRIPTION:
Defining member functions outside the class in C++ is a way to separate the declaration and
implementation of the functions. This approach provides modularity and improves code
organization, especially when dealing with large classes.
To define a member function outside the class ,you need to follow these steps:-
1. Declare the member function inside the class declaration, including the function's return type,
name, and parameters.
2. Outside the class declaration, use the scope resolution operator :: followed by the class name
and the member function's name to indicate that you are defining the function belonging to
that class.
3. Provide the function definition, including the return type, name, and parameters, just as you
would for any other function.
4. Implement the function's logic within the definition. You can access the class's private
members and perform any necessary operations.
.
Explanation:
#include<iostream.h>
class car
{
Private:
Int car_number;
Char car_model[10];
Public:void getdata();
void showdata();
};
Output:
LAB EXPERIMENT 3
OBJECTIVE:
BRIEF DESCRIPTION: C++, a static data member is a class member that is shared among all
instances (objects) of the class. It is associated with the class itself rather than with individual
objects. Here's an overview of static data members in C++.
PRE-EXPERIMENT QUESTIONS:
Explanation:
#include <iostream>
using namespace std;
class A {
public:
A()
{
cout << "A's Constructor Called " <<
endl;
}
};
class B {
static A a;
public:
B()
{
cout << "B's Constructor Called " <<
endl;
}
};
// Driver code
int main()
{
B b;
return 0;
}
2.What is static ?
LAB EXPERIMENT 4
OBJECTIVE: Write a program to demonstrate the use of const data members..
BRIEF DESCRIPTION:
In C++, a const data member is a class member whose value cannot be modified once it is
initialized. Here's an overview of const data members in C++:
Declaration and Initialization: A const data member is declared in the class declaration and must
be initialized at the point of declaration or in the constructor's initializer list. It is typically
declared as private to ensure that its value remains constant.
#include<iostream>
using namespace std;
class Demo {
int val;
public:
Demo(int x = 0) {
val = x;
}
int getValue() const {
return val;
}
};
int main() {
const Demo d(28);
Demo d1(8);
cout << "The value using object d : " << d.getValue();
cout << "\nThe value using object d1 : " << d1.getValue();
return 0;
}
LAB EXPERIMENT 5
OBJECTIVE:
Write a program to demonstrate the use of zero argument and parameterized constructors.
BRIEF DESCRIPTION:
In C++, a parameterized constructor is a special member function of a class that is used to initialize objects of
that class with specific values. It accepts parameters as arguments, allowing the caller to provide values during
object creation. Here's an overview of parameterized constructors:
Declaration and Definition: A parameterized constructor is declared within the class declaration like any other
member function. It has parameters corresponding to the values needed to initialize the object. The constructor
definition provides the implementation for the constructor.
1.What is an constructor?
2.What are the various types of constructor in c++ 3.How can
we determine the width and height of triangle using
constructor?
EXPLANATION:
class math
{
private:
int a,b,c;
public:
math(int x,int y)
{
a=x;
b=y;
}
void add()
{
c=a+b;
cout<<"Total : "<<c;
}
};
int main()
{
math o(10,25);
o.add();
return 0;
}
Output: Total : 35
LAB EXPERIMENT 6
OBJECTIVE:
BRIEF DESCRIPTION:
C++ provides different types of constructors, such as default constructors, parameterized constructors, copy
constructors, and move constructors. These constructors are called implicitly based on the object creation
syntax or specific scenarios.
Dynamic memory allocation in C++ involves the use of operators like new and delete to allocate and deallocate
memory at runtime. However, this is not directly related to constructor.
PRE EXPERIMENT QUESTIONS:
1. What is the correct syntax of new and delete operator
2. What id dynamic memory allocation?
Explanation:
#include<iostream>
using namespace std;
class example
{
const char* ptr;
public:
// default constructor
example()
{
// allocating memory at run time by using the new keyword
ptr = new char[15];
ptr = "Hi from example constructor ";
}
void display()
{
cout << ptr;
}
};
int main()
{
example obj1;
obj1.display();
}
POST EXPERIMENT QUESTIONS:
1. What is pointer?
2. What are steps of define pointer to pointer?
LAB EXPERIMENT 7
OBJECTIVE:
BRIEF DESCRIPTION:
In C++, the explicit keyword is used to qualify a constructor declaration. It affects the way the
constructor is used for implicit type conversions. Here's an overview of explicit constructors:
Implicit Type Conversions: By default, constructors that can be called with a single argument can
also be used for implicit type conversions. For example, if a class has a constructor that takes an
int parameter, it can be used to implicitly convert an int value to an object of the class
Explanation:
#include<iostream.h>
class A
{
int data;
public:
A(int a):data(a)
{
cout<<"A::Construcor...\n";
};
int main()
{
//Call display with A object i.e. a1
display(5000);
return (0);
}
Output A::Construcor...
B::Construcor...
function display..
LAB EXPERIMENT 8
OBJECTIVE:
BRIEF DESCRIPTION:
In C++, the initializer list is a special syntax used in constructors to initialize the data members of a class. It
provides a concise and efficient way to initialize member variables when an object is created. Here's an
overview of the initializer list:
Syntax: The initializer list is placed after the constructor's parameter list and is enclosed within parentheses.
Each member variable is initialized using a comma-separated list of member initializations.
1. What is datamembers?
2. What is initializer list?
EXPLANATION:
#include<iostream>
using namespace std;
class Point {
private:
int x;
int y;
public:
Point(int i = 0, int j = 0):x(i), y(j) {}
/* The above use of Initializer list is optional as the
constructor can also be written as:
Point(int i = 0, int j = 0) {
x = i;
y = j;
}
*/
int getX() const {return x;}
BRIEF DESCRIPTION:
Operator overloading in C++ allows you to define the behavior of operators when applied to
user-defined types. It enables you to extend the functionality of operators beyond their built-in
capabilities. Here's an overview of operator overloading:
PRE-EXPERIMENT QUESTIONS:
Q1. What is operator overloading?
Q2. What is the binary and unary operator ?
Explanation:
#include<iostream.h>
Class Check
Private: int i;
Public: Check():i(0){ }
{++i;}
void Display()
{ cout<<”i=”<<i<<endl;}
};
int main()
Check obj;
Obj.Display()
++obj;
Obj.Display()
Return 0;
Output
i=0
i=1
LAB EXPERIMENT 10
OBJECTIVE:
BRIEF DESCRIPTION:
In C++, multilevel inheritance is a type of inheritance where a derived class is derived from another
derived class. It involves creating a class hierarchy with multiple levels of derived classes. Here's an
overview of multilevel inheritance:
Syntax: In multilevel inheritance, each derived class serves as the base class for the next level of derived
class.
class A
{
……..
}
class B: public A
{
………..
}
Class C: public B
{
………..
}
PRE-EXPERIMENT QUESTIONS:
Q1. What is Inheritance ?
Q2. Which inheritance is most important explain.
Explanation:
#include <iostream>
using namespace std;
class Vehicle{
public:
void vehicle(){
cout<<"I am a vehicle\n";
}
};
void fourWheeler(){
cout<<"I have four wheels\n";
}
};
Input
Car obj;
obj.car();
obj.fourWheeler();
obj.vehical()
Output
I am a car
I have four wheels
I am a vehicle
POST-EXPERIMENT QUESTIONS:
Q1. Different types of inheritance.
Q2. What is hybrid inheritance?.
LAB EXPERIMENT 11
OBJECTIVE:
Write a program to demonstrate the exception handling.
BRIEF DESCRIPTION: Exception handling in C++ provides a mechanism to handle runtime errors
and exceptional conditions that may occur during program execution. It allows you to catch and handle
exceptions, preventing program termination and providing a way to recover from errors. Here's an
overview of exception handling
PRE-EXPERIMENT QUESTIONS:
1. What is exception ?
2. How to handle exception in c++?
3. What is try block?
Explanation:
#include <iostream>
using namespace std;
int main () {
int x = 50;
int y = 0;
double z = 0;
try {
z = division(x, y);
cout << z << endl;
} catch (const char* msg) {
cerr << msg << endl;
}
return 0;
}
LAB EXPERIMENT 12
PRE-EXPERIMENT QUESTIONS:
Explanation:
#include <iostream>
using namespace std;
int main () {
int i=5, j=6, k;
long l=10, m=5, n;
k=GetMax<int>(i,j);
n=GetMax<long>(l,m);
cout << k << endl;
cout << n << endl;
return 0;
}
Mr.Ashwani Kumar
([email protected]
nfo)
Crosschecked By
HOD CSE