OOPM LAB MANUAL DATA SCIENCE

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

A Practical File

of
Object Oriented Programming
and Methodology (CD305)

Department of Computer Science & Engineering (Data Science)

Submitted by

Name:

Enrolment No:
Semester:

Branch:
Session:

Department of Computer Science & Engineering

Baderia Global Institute of Engineering and Management, Jabalpur (M.P.)


Global Square, Patan Bypass, Raigwan, Jabalpur, M.P., 482002
OOPM Lab Manual

Contents
⮚ Vision and Mission of the Institute

⮚ Vision and Mission of the Department

⮚ Program Educational Objective

⮚ Program Outcomes

⮚ Program Specific Outcomes

⮚ Course Outcomes

⮚ LABORATORY REGULATIONS AND SAFETY RULES

⮚ List of Experiments

Object Oriented Programming and Methodology (CD 305)


Vision and Mission of the Institute
Vision

Transforming lives by providing professional education with excellence.

Mission

1. Quality Education: Providing Education with quality and shaping up Technocrats and
budding managers with a focus on adapting to changing technologies.
2. Focused Research & Innovation: Focusing on Research and Development and
fostering Innovation among the academic community of the Institution.
3. People Focused: Accountable and committed to institutional operations for effective
functioning by Faculty members, Staff and Students.
4. Holistic Learning: Focus on conceptual learning with practical experience and
experiential learning with strong Industrial connections and collaborations.
5. Service to Society: Providing Technical and Managerial services to society for
betterment of their quality of life with best of the skills, compassion and empathy.

Object Oriented Programming and Methodology (CD 305)


Vision and Mission of the Department
Vision

Cultivating leaders in Data Science who drive innovation and informed decision-making
through the power of data analytics and scientific discovery.

Mission

The department strives to:

1) Foster a student-centric learning environment that equips graduates with cutting-edge


knowledge and skills in data science, analytics, and related technologies.
2) Develop professionals who can apply data-driven approaches to solve complex
problems across diverse industries, with a commitment to ethical standards and
societal well-being.
3) Continuously enhance faculty expertise through ongoing training, ensuring the
delivery of high-quality education and mentorship.
4) Promote collaboration between academia and industry through research and
consultancy projects, providing students with practical experiences and opportunities
for conceptual learning.

Object Oriented Programming and Methodology (CD 305)


Program Education Objectives
1. To impart in depth concepts of the subject in terms of both theoretical and practical aspects
to achieve excellent University results.

2. To produce technically sound engineering graduates who would fulfil the latest
requirements of computer science and IT industry at modest cost with the calibre of solving
intricacies of deeper programming concepts.

3. To inculcate the lessons of communication skills, teamwork spirit and professional attitude
to the budding engineering graduates.

4. In order to get versatile growth of the students, participation of students in extracurricular


activities is also made compulsory; and also to develop ethical attitudes in the graduates so
that they can also become good citizens of the nation.

5. To develop leadership and entrepreneurship qualities in budding graduates so that they will
cherish and nourish the society and the nation with modern trends of digitization and blossom
it with their unparalleled technical expertise.

Object Oriented Programming and Methodology (CD 305)


Program Outcomes
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization for the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
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 public health and safety, and cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of 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 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 engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for 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 the 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
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long 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.

Object Oriented Programming and Methodology (CD 305)


Program Specific Outcomes

Graduates will be able to-

PSO 1: Proficiency in Computer Systems: Capability to understand, analyzeand develop


computer programs in the areas related algorithms, system software, multimedia, web design,
cloud computing and networking enable designing of computer systems that are efficient and
support the degree of complexity.

PSO2: Proficiency in Software Development: Ability to understand the structure and


methodologies of software systems with keen knowledge about software design process and
practical expertise in the programming languages and the open system platform.

PSO 3: Proficiency in Mathematics and science concepts: Capable of applying


mathematics and science concepts to solve computation tasks and model real world problems
using suitable algorithms and data structures.

PSO 4: Successful career as a Computer Science Engineer: Ability to employ themselves


as computer professionals, to be an entrepreneur having innovative ideas and sound
knowledge in various domains leads to enthusiasm in higher studies and research.

Object Oriented Programming and Methodology (CD 305)


Course Outcome

CO1: Understand the core principles of Object-Oriented Programming (OOP) and distinguish
it from Procedural Programming.

CO2: Demonstrate effective implementation of Object-Oriented Programming (OOP)


principles by designing classes with well-defined attributes and services, using appropriate
access modifiers and static members.

CO3: Analyze and apply different types of relationships in Object-Oriented Programming


(OOP), including 'is a' (inheritance), Association, and Aggregation.

CO4: demonstrate polymorphism in Object-Oriented Programming (OOP) by implementing


method overriding and method overloading, runtime and compile-time polymorphism,
respectively.

CO5: Understand Streams classes, Stream Errors, Disk File I/O with streams, file pointers,
error handling in file I/O with member function.

Object Oriented Programming and Methodology (CD 305)


Laboratory Regulations and Safety Rules

The following Regulations and Safety Rules must be observed in all concerned
laboratory locations.
1. It is the duty of all concerned parties who use any electrical laboratory to take all
reasonable steps to safeguard the HEALTH and SAFETY of themselves and all other users
and visitors.
2. Make sure that all equipment is properly working before using them for laboratory
exercises. Any defective equipment must be reported immediately to the Lab. Instructors or
Lab. Technical Staff.
3. Students are allowed to use only the equipment provided in the experiment manual or
equipment used for senior project laboratory.
4. Power supply terminals connected to any circuit are only energized with the presence of
the Instructor or Lab. Staff.
5. Students should keep a safe distance from the circuit breakers, electric circuits or any
moving parts during the experiment.
6. Avoid any part of your body to be connected to the energized circuit and ground.
7. Switch off the equipment and disconnect the power supplies from the circuit before leaving
the laboratory.
8. Observe cleanliness and proper laboratory housekeeping of the equipment and other
related accessories.
9. Wear proper clothes and safety gloves or goggles required in working areas that involve
fabrications of printed circuit boards, chemicals process control system, antenna
communication equipment and laser facility laboratories.
10. Double check your circuit connections specifically in handling electrical power machines,
AC motors and generators before switching “ON” the power supply.
11. Make sure that the last connection to be made in your circuit is the power supply and the
first thing to be disconnected is also the power supply.
12. Equipment should not be removed, transferred to any location without permission from
the laboratory staff.
13. Software installation in any computer laboratory is not allowed without the permission
from the Laboratory Staff.
14. Computer games are strictly prohibited in the computer laboratory.
15. Students are not allowed to use any equipment without proper orientation and actual
hands on equipment operation.

Object Oriented Programming and Methodology (CD 305)


List of Experiments

S. Experiment Date Sign


No.
1 Implement a programming logic to find out the largest number using
function.
2 Implement a programming logic to find the area of circle, rectangle and
triangle using function overloading.
3 Implement a programming logic to add the complex numbers using
operator overloading.
4 Implement a programming logic to create a class ‘Student’ that takes
marks of 3 subjects (out of 3) and checks the eligibility of students. The
student is eligible if percentage is greater than or equal to 45%.
5 Implement a programming logic which defines a class with constructor
and destructor which will count number of object created and destroyed.
6 Implement a programming logic to demonstrate multiple inheritances
taking ‘Student’ and ‘Employee’ as the base class and ‘Trainee’ class
inheriting from both the classes.
7 Implement a programming logic to add two private data members using
friend function.
8 Implement a programming logic using dynamic memory allocation to
perform matrix addition and subtraction.
9 Implement a programming logic to create an Abstract class Animal
having a pure virtual function makeSound (). Make two derived classes
Cat and Dog that implements the makeSound () function in their own
ways.
10 Implement a programming logic to create a Stack class that has all the
necessary methods of stack operation.

Object Oriented Programming and Methodology (CD 305)


Experiment 1
Aim:Implement a programming logic to find out the largest number using function.

Program

#include <iostream>
using namespace std;
intgetMax(intarr[],int size) {
int maxi=arr[0];
for(inti=1;i<size;i++) {
if(maxi<arr[i]) {
maxi =arr[i];
}
}
return maxi;
}

int main() {
constint size = 10;
intnum[size];
for(inti=0;i<size;i++)
cin>>num[i];
int maxi = getMax(num,size);
cout<< maxi <<endl;
}
Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 2
Aim: Implement a programming logic to find the area of circle, rectangle and triangle using
function overloading.

Program

#include <iostream>
#define PI 3.1416
using namespace std;
float area(float radius) {
float area = PI*radius*radius;
return area;
}
//overloaded function 1
float area(int length, int breadth) {
return length*breadth;
}
//overloaded function 2
float area(float base, float height) {
return 0.5*base*height;
}

int main() {
//dimensions of a circle
float radius;
cout<<”Enter the radius of circle: “;
cin>>radius;
//dimensions of a rectangle
int length, breadth;
cout<<”Enter the length and breadth of the rectangle: “;
cin>>length>>breadth;
//dimensions of a triangle
float base, height;
cout<<”Enter the base and height of the triangle: “;
cin>>base>>height;
cout<< "Area of circle: " << area(radius) <<endl;
cout<< "Area of rectangle: " << area(length, breadth) <<endl;
cout<< "Area of triangle: " << area(base, height) <<endl;
}

Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 3
Aim: Implement a programming logic to add the complex numbers using operator
overloading.
Program

#include <iostream>
using namespace std;
class complex {
public:
double real;
doubleimag;
complex(double, double);
complex();
complex add(complex);
complex operator+(complex);
};
complex::complex() {}
complex::complex(double r, double i) {
real = r;
imag = i;
}
complex complex::add(complex c) {
complex x;
x.real = real+c.real;
x.imag = imag+c.imag;
return x;
}
// + operator overloaded to add complex number
complex complex::operator+(complex c) {
complex x;
x.real = real+c.real;
x.imag = imag+c.imag;
return x;
}
int main() {
double real, imag;
cout<< "Enter the first complex number\'s real part: ";
cin>> real;
cout<< "Enter the first complex number\'s imaginary part: ";
cin>>imag;
cout<< "First complex number is: " << real << "+i" <<imag<<endl;
complex c1(real,imag);
cout<< "Enter the second complex number\'s real part: ";
cin>> real;
cout<< "Enter the second complex number\'s imaginary part: ";
cin>>imag;
cout<< "Second complex number is: " << real << "+i" <<imag<<endl;
complex c2(real,imag)
complex a1,a2,a3;
//Simple add function
a1 = c1.add(c2);
//Two ways of calling overloaded operator
a2 = c1.operator+(c2);
a3 = c1 + c2;
cout<< “The addition of two complex numbers: “<<endl;
cout<< a1.real << "+i" << a1.imag <<endl;
cout<< a2.real << "+i" << a2.imag <<endl;
cout<< a3.real << "+i" << a3.imag <<endl;
}

Object Oriented Programming and Methodology (CD 305)


Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 4
Aim: Implement a programming logic to create a class ‘Student’ that takes marks of 3
subjects (out of 3) and checks the eligibility of students. The student is eligible if percentage
is greater than or equal to 45%.

Student
-S_ID:int
-name:string
-marks1,marks2,mark3:float
+Student()
+Student(int, string)
+setMarks(float,float,float):void
+checkEligibility():bool
+ printMarksheet():void

Program

#include <iostream>
using namespace std;
class Student {
int id;
string name;
float marks1, marks2, marks3;
public:
Student(){}
Student(int id, string name) {
this->id=id;
this->name=name;
}
voidsetMarks(float m1,float m2,float m3) {
marks1 = m1;
marks2 = m2;
marks3 = m3;
}
boolcheckEligibility() {
floatans = (marks1+marks2+marks3)/3;
if(ans<45) {
return false;
}
return true;
}
};
int main() {
intsid;

Object Oriented Programming and Methodology (CD 305)


string name;
float m1, m2, m3;
cout<<"Enter Roll Number: "<<endl;
cin>>sid;
cout<<"Enter Name: "<<endl;
cin>>name;
cout<<"Enter marks of Physics, Chemistry and Maths: "<<endl;
cin>>m1>>m2>>m3;
Student s1(sid, name);
s1.setMarks(m1,m2,m3);
if(s1.checkEligibility()) {
cout<<"Eligible for engineering"<<endl;
} else {
cout<<"Not Eligible for engineering"<<endl;
}
voidprintMarksheet() {
cout<<"\n\n";
cout<<"----------------------------------"<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Roll Number: "<<id<<endl;
cout<<"Physics Percentage: "<<marks1<<endl;
cout<<"Chemistry Percentage: "<<marks2<<endl;
cout<<"Maths Percentage: "<<marks3<<endl;
cout<<"----------------------------------"<<endl;
}
}

Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 5
Aim: Implement a programming logic which defines a class with constructor and destructor
which will count number of object created and destroyed.

Theory: When we declare a member of a class as static it means no matter how many objects
of the class are created, there is only one copy of the static member.

● A static member is shared by all objects of the class, all static data is initialized to
zero when the first object is created, if no other initialization is present.
● A static member function can only access static data member, other static member
functions and any other functions from outside the class.
● By declaring a function member as static, we make it independent of any particular
object of the class. A static member function can be called even if no objects of the
class exist and the static functions are accessed using only the class name and the
scope resolution operator :: .
● We can’t put it in the class definition but it can be initialized outside the class as done
in the following example by re-declaring the static variable, using the scope resolution
operator :: to identify which class it belongs to.
Program
#include <iostream>
using namespace std;

class Demo {
public:
staticintobjCount;
Demo() {
objCount++;
cout<<"Object no: "<<objCount<< " created"<<endl;
}
~Demo() {
cout<<"Object no: "<<objCount<< " Destroyed"<<endl;
objCount--;
}
};
int Demo::objCount;

int main() {
Demo d[3];
}

Object Oriented Programming and Methodology (CD 305)


Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 6
Aim: Implement a programming logic to demonstrate multiple inheritances taking ‘Student’
and ‘Employee’ as the base class and ‘Trainee’ class inheriting from both the classes.

Student Employee

Trainee

Program

#include <iostream>
using namespace std;
class Student {
int id;
string name;
public:
Student() {}
Student(int id, string name) {
this->id = id;
this->name = name;
}
intgetId() {
return id;
}
stringgetName() {
return name;
}
virtual void display() {
cout<<"("<<id<<","<<name<<")"<<endl;
}
};
class Employee {
string post;
public:
Employee() {}
Employee(string post) {
this->post = post;
}
stringgetPost() {
return post;
}
};

Object Oriented Programming and Methodology (CD 305)


classTrainee:publicStudent,public Employee {
public:
Trainee(){}
Trainee(int id, string name,string post):Student(id,name),Employee(post) {
}

void display() {
cout<<"("<<getId()<<","<<getName()<<","<<getPost()<<")"<<endl;
}
};
int main() {
Trainee x(1,"Mark Zuckerberg","CEO");
x.display();
}

Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 7
Aim: Implement a programming logic to add two private data members using friend function.
Program

#include <iostream>
using namespace std;
class calculator {
int num1, num2;
public:
friendint add(int,int);
friendint subtract(int,int);
friendint multiply(int,int);
friend float divide(int,int);
};
int add(int x, int y) {
calculatorcal;
cal.num1=x;cal.num2=y;
return cal.num1+cal.num2;
}
int subtract(int x, int y) {
calculatorcal;
cal.num1=x;cal.num2=y;
return cal.num1-cal.num2;
}
int multiply(int x, int y) {
calculatorcal;
cal.num1=x;cal.num2=y;
return cal.num1*cal.num2;
}
float divide(int x, int y) {
calculatorcal;
cal.num1=x;cal.num2=y;
return (float)cal.num1/cal.num2;
}
int main() {
int a=3,b=4;
float c;
c = add(a,b);
cout<< "Addition:"<<c<<endl;
c = subtract(a,b);
cout<< "Subtraction:"<<c<<endl;
c = multiply(a,b);
cout<< "Multiplication:"<<c<<endl;
c = divide(a,b);
cout<< "Division:"<<c<<endl;
}

Object Oriented Programming and Methodology (CD 305)


Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 8
Aim:Implement a programming logic using dynamic memory allocation to perform matrix
addition and subtraction.

Program

#include <iostream>
using namespace std;
double** createMatrix(int rows, int cols) {
double** mat = new double*[rows]; //Allocate rows.
for (inti = 0; i< rows; ++i)
{
mat[i] = new double[cols](); //Allocate each row and zero initialize.
}
return mat;
}
voiddestroyMatrix(double** &mat, int rows)
{
if (mat)
{
for (inti = 0; i< rows; ++i)
{
delete[] mat[i]; //delete each row..
}

delete[] mat; //delete the rows..


mat = NULL;
}
}
voidshowMatrix(double** &mat, int rows, int cols) {
cout<<endl;
for (inti = 0; i< rows; ++i)
{
for(int j = 0; j < cols; ++j) {
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
}
voidfillMatrix(double** &mat, int rows, int cols) {
for (inti = 0; i< rows; ++i)
{
for(int j = 0; j < cols; ++j) {
cin>>mat[i][j];
}
}
}
double** addMatrices(double** &mat1, double** &mat2, int rows, int cols) {
double **ans = createMatrix(3,3);
for (inti = 0; i< rows; ++i)
{
for(int j = 0; j < cols; ++j) {

Object Oriented Programming and Methodology (CD 305)


ans[i][j] = mat1[i][j]+mat2[i][j];
}
}
returnans;
}

double** subtractMatrices(double** &mat1, double** &mat2, int rows, int cols) {


double **ans = createMatrix(3,3);
for (inti = 0; i< rows; ++i)
{
for(int j = 0; j < cols; ++j) {
ans[i][j] = mat1[i][j]-mat2[i][j];
}
}
returnans;
}
int main() {
double **m1 = createMatrix(3,3);
double **m2 = createMatrix(3,3);
cout<<"Enter the values for matrix1:"<<endl;
fillMatrix(m1,3,3);
cout<<"Enter the values for matrix2:"<<endl;
fillMatrix(m2,3,3);
double **addition = addMatrices(m1,m2,3,3);
double **subtraction = subtractMatrices(m1,m2,3,3);
cout<<"Addition:";
showMatrix(addition,3,3);
cout<<"Subtraction:";
showMatrix(subtraction,3,3);

cout<<"cleaning up...."<<endl;
destroyMatrix(m1,3);
destroyMatrix(m2,3);
destroyMatrix(addition,3);
destroyMatrix(subtraction,3);
}

Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 9
Aim:Implement a programming logic to create an Abstract class Animal having a pure
virtual function makeSound (). Make two derived classes Cat and Dog that implements the
makeSound () function in their own ways.

Theory:
Sometimes implementation of all function cannot be provided in a base class because we
don’t know the implementation. Such a class is called abstract class. For example, let Animal
be a base class. We cannot provide implementation of function draw() in Shape, but we know
every derived class must have implementation of draw(). Similarly an Animal class doesn’t
have implementation of makeSound() (assuming that all animals make sound), but all
animals must know how to make sound. We cannot create objects of abstract classes.A pure
virtual function (or abstract function) in C++ is a virtual function for which we can have
implementation, But we must override that function in the derived class, otherwise the
derived class will also become abstract class
Program

#include <iostream>
using namespace std;
class Animal {
public:
virtual void makeSound() = 0;
void eat() {
cout<< "Munchies";
}
};
classDog:public Animal {
public:
voidmakeSound() {
cout<< "Bow Wow" <<endl;
}
};
class Cat: public Animal {
public:
voidmakeSound() {
cout<< "Meow" <<endl;
}
};
int main() {
Animal *ptr1 = new Dog();
Animal *ptr2 = new Cat();
ptr1->makeSound();
ptr2->makeSound();
}

Output:

Object Oriented Programming and Methodology (CD 305)


Experiment 10
Aim: Implement a programming logic to create a Stack class that has all the necessary
methods of stack operation.

Program

#include <iostream>
using namespace std;
#define MAX 1000

class Stack {
int top;

public:
int a[MAX]; // Maximum size of Stack
Stack() { top = -1; }
bool push(int x);
int pop();
int peek();
boolisEmpty();
};

bool Stack::push(int x)
{
if (top >= (MAX - 1)) {
cout<< "Stack Overflow";
return false;
}
else {
a[++top] = x;
cout<< x << " pushed into stack\n";
return true;
}
}

int Stack::pop()
{
if (top < 0) {
cout<< "Stack Underflow";
return 0;
}
else {
int x = a[top--];
return x;
}
}
int Stack::peek()

Object Oriented Programming and Methodology (CD 305)


{
if (top < 0) {
cout<< "Stack is Empty";
return 0;
}
else {
int x = a[top];
return x;
}
}

bool Stack::isEmpty()
{
return (top < 0);
}

// Driver program to test above functions


int main()
{
class Stack s;
s.push(10);
s.push(20);
s.push(30);
cout<<s.pop() << " Popped from stack\n";
//print all elements in stack :
cout<<"Elements present in stack : ";
while(!s.isEmpty())
{
// print top element in stack
cout<<s.peek()<<" ";
// remove top element in stack
s.pop();
}

return 0;
}

Output:

Object Oriented Programming and Methodology (CD 305)

You might also like