OOPM LAB MANUAL DATA SCIENCE
OOPM LAB MANUAL DATA SCIENCE
OOPM LAB MANUAL DATA SCIENCE
of
Object Oriented Programming
and Methodology (CD305)
Submitted by
Name:
Enrolment No:
Semester:
Branch:
Session:
Contents
⮚ Vision and Mission of the Institute
⮚ Program Outcomes
⮚ Course Outcomes
⮚ List of Experiments
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.
Cultivating leaders in Data Science who drive innovation and informed decision-making
through the power of data analytics and scientific discovery.
Mission
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.
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.
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.
CO1: Understand the core principles of Object-Oriented Programming (OOP) and distinguish
it from Procedural Programming.
CO5: Understand Streams classes, Stream Errors, Disk File I/O with streams, file pointers,
error handling in file I/O with member function.
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.
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:
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:
#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;
}
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;
Output:
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];
}
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;
}
};
void display() {
cout<<"("<<getId()<<","<<getName()<<","<<getPost()<<")"<<endl;
}
};
int main() {
Trainee x(1,"Mark Zuckerberg","CEO");
x.display();
}
Output:
#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;
}
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..
}
cout<<"cleaning up...."<<endl;
destroyMatrix(m1,3);
destroyMatrix(m2,3);
destroyMatrix(addition,3);
destroyMatrix(subtraction,3);
}
Output:
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:
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()
bool Stack::isEmpty()
{
return (top < 0);
}
return 0;
}
Output: