SlideShare a Scribd company logo
1 of 55
1 | P a g e
LAB MANUAL
(Object-Oriented Programming.)
Submitted By
Name: ________________M.Faizan_______________________
Roll No#: _________________Bsf23006565_______________________
__________________________________________________________________
Prepared By
_____________________________________________________________________________
2 | P a g e
CONTENTS
1. ------------------------------------Problem Solving ------------------------------------------
2. ---------------------------------Programming Paradigms ------------------------------------
3. ---------------------------------Procedural programming------------------------------------
4. ------------------------------Object-oriented programming ---------------------------------
5. -------------------------------Procedural Oriented Programming------------------------------
VS
-----------------------------Object Oriented Programming----------------------------------
6. --------------------------------------Encapsulation -------------------------------------------
7. --------------------------------------Abstraction ----------------------------------------------
8. -------------------------------------- Inheritance-----------------------------------------------
9. -------------------------------------- Constructors---------------------------------------------
3 | P a g e
Problem Solving
Understanding the problem
Understanding
Analyzing the problem
Analyzing
Formulating a plan
Formulating
Implementing the plan
Implementing
Programming paradigms
4 | P a g e
Procedural programming
5 | P a g e
Object-oriented programming
• Object-oriented programming is a paradigm that
focuses on the data and behavior of the entities or
objects that a program manipulates.
• It organizes the code into classes, which are
templates or blueprints for creating objects.
• Classes define the attributes and methods of the
objects, which are the data and functions that belong
to them.
• Objects can interact with each other through
messages, which are calls to their methods. Object-
oriented programming is based on the idea of
bottom-up design, where the problem is modeled by
identifying the objects and their relationships.
• Object-oriented programming is often associated
with languages like Java, C++, and Python.
6 | P a g e
 In object-oriented programming, the
program is divided into small parts
called objects.
 OOp follows a bottom-up approach.
 OOP has access specifiers like private,
public, protected, etc.
 Adding new data and function is easy.
 Object-oriented programming provides
data hiding so it is more secure.
 Overloading is possible in object oriented
programming.
 In object-oriented programming, the
concept of data hiding and inheritance is
used.
 In object-oriented programming, data is
more important than function.
 Object-oriented programming is based on
the real world.
 Object-oriented programming uses the
concept of data abstraction.
 Code reusability present in object-
oriented programming
 Examples:C++,C#,Python,Java
Procedural Oriented Programming
VS
Object Oriented Programming
 In procedural programming, the program
is divided into small parts
called functions.
 Procedural programming follows a top-
down approach.
 There is no access specifier in procedural
programming.
 Adding new data and functions is not
easy.
 Procedural programming does not have
any proper way of hiding data so it is less
secure.
 In procedural programming, overloading
is not possible.
 In procedural programming, there is no
concept of data hiding and inheritance.
 In procedural programming, the function
is more important than the data.
 Procedural programming is based on
the unreal world.
 Procedural programming uses the
concept of procedure abstraction.
 Code reusability absent in procedural
programming,
 Examples: C, FORTRAN, Pascal, Basic,
etc.
7 | P a g e
Classes And Functions
Activity No.1
Write a C++ function that takes two integers as parameters and returns their sum.
Activity No.2222
Implement a C++ function to calculate the area of a circle given its radius.
8 | P a g e
Activity No.3
Create a C++ function that checks whether a given number is even or odd.
9 | P a g e
Activity No.4
Write a C++ program that uses a function to find the maximum of three numbers.
Activity No.5
Implement a C++ function that reverses a string.
10 | P a g e
Activity No.6
Write a C++ function that takes two integers as parameters and returns their sum.
11 | P a g e
Activity No.7
Implement a C++ function to calculate the area of a circle given its radius.
12 | P a g e
Activity No.8
Create a C++ function that checks whether a given number is even or odd.
13 | P a g e
Activity No.9
Write a C++ program that uses a function to find the maximum of three numbers
14 | P a g e
Activity No.10
Implement a C++ function that reverses a string.
Activity No.11
15 | P a g e
Encapsulation
•
•
•
•
•
•
•
•
•
•
•
•
•
Data and behaviour are tightly coupled inside an object
Both the information structure and implementation details of its operations are hidden from the outer world
Example:
Ali stores his personal information and knows how to translate it to the desired language
We don’t know
How the data is stored
How Ali translates this information
Example:
A Phone stores phone numbers in digital format and knows how to convert it into human-readable characters
We don’t know
How the data is stored
How it is converted to human-readable characters
Encapsulation – Advantages
► Simplicity and clarity
► Low complexity
► Better understanding
16 | P a g e
Abstraction
•
•
•
•
•
•
•
•
•
•
•
Smalltalk was the first pure object-oriented
language, where everything was an object, even
numbers and functions. Smalltalk also introduced
the concepts of dynamic typing, garbage collection,
and graphical user interface.
Abstraction is a way to cope with complexity.
► Principle of abstraction:
“Capture only those details about an object that are relevant to current perspective”
Example:
Ali is a PhD student and teaches BS students
► Attributes
- Name - Employee ID
- Student Roll No - Designation
- Year of Study - Salary
- CGPA - Age
Ali is a PhD student and teaches BS students
► behaviour
- Study - DevelopExam
- GiveExam - TakeExam
- PlaySports - Eat
- DeliverLecture - Walk
Abstraction – Advantages
 Simplifies the model by hiding irrelevant details
 Abstraction provides the freedom to defer implementation decisions by avoiding commitment to details
17 | P a g e
Inheritance
► A child inherits characteristics of its parents
► Besides inherited characteristics, a child may have its own unique characteristics
Inheritance in Classes:
► If a class B inherits from class A then it contains all the characteristics
(information structure and behaviour) of class A
► The parent class is called base class and the child class is called derived class
► Besides inherited characteristics, derived class may have its own unique characteristics
Example:
Person
Teacher
Doctor
Student
18 | P a g e
Inheritance – Advantages
► Reuse
► Less redundancy
► Increased maintainability
19 | P a g e
Inheritance
Activity No.1
Define a base class Shape with private attributes width and height. Create public member
functions in the base class to set and get the values of these attributes. Derive a class Rectangle
from Shape and demonstrate how to access and modify the private attributes through the
public member functions.
Activity No.2
Implement a base class Vehicle with a protected member function startEngine() and a derived
class Car that inherits this function. Show how the protected access specifier allows the derived
class to call the startEngine() function.
20 | P a g e
Activity No.3
Create a base class Person with private attributes name and age. Provide a public member
function in the base class to display the person's information. Derive a class Student from
Person and demonstrate how the derived class can access the base class's private attributes
through the member function.
21 | P a g e
Activity No.4
Define a base class Employee with a protected attribute employeeID. Create a derived class
Manager that has a public member function to access and display the employeeID.
Activity No.5
Implement a base class Animal with a private attribute species. Create a derived class Dog that
inherits the species attribute but adds a public member function getSpecies() to access it.
22 | P a g e
Activity No.6
Use the virtual keyword to declare a virtual function display() in a base class Shape. Derive two
classes, Circle and Rectangle, and override the display() function in each. Create an array of
pointers to the base class and call the display() function on objects of the derived classes to
demonstrate dynamic binding.
23 | P a g e
Activity No.7
Create a base class BankAccount with protected attributes accountNumber and balance.
Provide public member functions to deposit and withdraw funds. Derive a class SavingsAccount
that inherits from BankAccount and includes a private attribute interestRate. Implement a
public member function in SavingsAccount to calculate interest based on the balance and
interest rate.
24 | P a g e
Activity No.8
Define a base class Person with private attributes name and age. Create a derived class Student
with additional private attributes like studentID and major. Provide public member functions to
set and get these attributes.
Activity No.9
Implement a base class Shape with protected attributes width and height. Derive a class
Rectangle from Shape and add a public member function calculateArea() that calculates the
area of the rectangle using the width and height attributes.
25 | P a g e
Activity No.10
Create a base class Employee with private attributes employeeID and salary. Derive a class
Manager that inherits these attributes. Implement public member functions in both classes to
display the employee's information, including their ID and salary.
26 | P a g e
Activity No.11
Define a base class Animal with a protected member function makeSound(). Derive classes Dog
and Cat that override makeSound() to produce different sounds. Demonstrate polymorphism
by calling makeSound() on objects of both derived classes using a base class pointer.
Activity No.12
Implement a base class Vehicle with private attributes speed and fuelType. Create a derived
class Car with a public member function displayInfo() that accesses and displays the speed and
fuelType attributes.
27 | P a g e
Activity No.13
Create a base class BankAccount with a private attribute accountNumber. Derive a class
SavingsAccount that inherits the accountNumber attribute. Demonstrate how to access and
modify the accountNumber attribute using the derived class.
Activity No.14
Define a base class Shape with a public member function printInfo() that displays information
about the shape. Derive classes Circle and Rectangle from Shape and override the printInfo()
function in each derived class to provide specific information.
28 | P a g e
Activity No.15
Implement a base class Employee with a private attribute employeeID. Create a derived class
Manager with a public member function getEmployeeID() that returns the employeeID.
29 | P a g e
Activity No.16
Create a base class Animal with protected attributes name and type. Derive classes Mammal
and Bird from Animal and provide public member functions in each derived class to access and
display the name and type attributes.
Activity No.17
Define a base class Person with a protected member function printName(). Create a derived
class Student that inherits this function and provides its own implementation. Demonstrate
how to call both the base class and derived class versions of printName().
30 | P a g e
Activity No.18
Implement a base class Fruit with private attributes name and color. Derive classes Apple and
Banana from Fruit and provide public member functions in each derived class to access and
display the name and color attributes.
Activity No.19
Create a base class Shape with protected attributes width and height. Derive a class Rectangle
from Shape and add public member functions setWidth() and setHeight() to modify the
attributes.
31 | P a g e
Activity No.20
Define a base class Animal with protected attributes name and type. Create a derived class
Mammal with an additional attribute habitat and a public member function to display all
attributes of the animal.
32 | P a g e
Activity No.21
Create a base class BankAccount with attributes accountNumber ,name and
balance with function Deposit() and withdraw(). Create a derived class
SavingsAccount (2 Function(), inherits from BankAccount and includes attributes
like interestRate and withdrawLimit.
Users want to open a saving account and deposit some money
33 | P a g e
Single Inheritance
In this inheritance, a
derived class is created
from a single base class.
In the given example,
Class A is the parent
class and Class B is the
child class since Class B
inherits the features and
behavior of the parent
class A.
34 | P a g e
Multi-Level Inheritance
In this inheritance, a derived class is
created from another derived class.
In the given example, class c inherits the
properties and behavior of class B and
class B inherits the properties and
behavior of class B. So, here A is the
parent class of B and class B is the parent
class of C. So, here class C implicitly
inherits the properties and behavior of
class A along with Class B i.e there is a
multilevel of inheritance.
35 | P a g e
Multiple – Inheritance
Multi-path Inheritance
In this inheritance,
a derived class is
created from more
than one base
class.
In this inheritance,
a derived class is
created from other
derived classes
and the same base
class of other
derived classes
36 | P a g e
Hierarchical Inheritance
• In this inheritance,
more than one
derived class is
created from a
single base class
and further child
classes act as
parent classes for
more than one
child class.
• In the given
example, class A
has two children
class B and class D.
Further, class B
and class C both
are having two
children - class D
and E; class F and
G respectively.
37 | P a g e
Constructors
Constructor is a special method or function within a class that is
automatically called when an object of that class is created.
Its main purpose is to initialize the object's state and perform any
necessary setup for the object to be used.
Constructors typically have the same name as the class and do not
have a return type specified.
They can have parameters to accept initial values that need to be
assigned to the object's attributes during the object's creation.
38 | P a g e
Activity No.1
39 | P a g e
Parameterized
and
Copy constructor
A copy constructor in C++ is
a special member function
that creates a new object by
initializing it with an
existing object of the same
class.
It essentially creates a copy
of an object, allowing for
proper initialization of
objects when they are
passed by value or returned
from a function.
 A parameterized constructor in C++ is a constructor that
accepts one or more parameters or arguments.
 Unlike the default constructor, which has no parameters,
a parameterized constructor allows you to initialize the
object's data members with specific values when an
object is created.
40 | P a g e
Activity No.11
Activity No.2
Student Class with Parameterized Constructor: Create a class representing a student with attributes like
name, roll number, and marks. Define a parameterized constructor that initializes these attributes with
values provided as arguments. Implement methods to display student details and calculate the average
marks of a group of students.
Activity No.3
41 | P a g e
Employee Class with Copy Constructor: Develop a class representing an employee with attributes like
name, employee ID, and salary. Define a copy constructor that copies the attributes from another
employee object. Implement methods to compare employee details, update salary, and display employee
information.
Activity No.4
Date Class with Parameterized Constructor: Design a class representing a date with attributes like day,
month, and year. Define a parameterized constructor that initializes these attributes with given values.
Implement methods to validate the date, calculate the difference between two dates, and display the
date in various formats.
Activity No.5
42 | P a g e
Vector Class with Copy Constructor: Create a class representing a mathematical vector with attributes for
magnitude and direction. Define a copy constructor that duplicates the vector attributes from another
vector object. Implement methods to perform vector addition, subtraction, scalar multiplication, and
vector normalization.
Activity No.6
Book Class with Parameterized Constructor: Develop a class representing a book with attributes like title,
author, and ISBN. Define a parameterized constructor that initializes these attributes with provided
values. Implement methods to compare books, display book details, and update information like the
number of pages or publication year.
43 | P a g e
Activity No.7
Bank Account Class with Copy Constructor: Design a class representing a bank account with attributes
like account number, account holder name, and balance. Define a copy constructor that duplicates the
account details from another bank account object. Implement methods to deposit, withdraw, and transfer
funds between accounts.
44 | P a g e
Activity No.8
Triangle Class with Parameterized Constructor: Create a class representing a triangle with attributes for
the lengths of its sides. Define a parameterized constructor that initializes these attributes with given
values. Implement methods to calculate the area, perimeter, and classify the type of triangle (e.g.,
equilateral, isosceles, scalene).
45 | P a g e
Activity No.9
String Class with Copy Constructor: Develop a class representing a string with attributes for storing
character data. Define a copy constructor that duplicates the string content from another string object.
Implement methods for string concatenation, substring extraction, and comparison.
Activity No.10
Car Class with Parameterized Constructor: Design a class representing a car with attributes like make,
model, and year of manufacture. Define a parameterized constructor that initializes these attributes with
provided values. Implement methods to calculate the mileage, check for maintenance requirements, and
display car information.
46 | P a g e
Activity No.11
Matrix Class with Copy Constructor: Create a class representing a mathematical matrix with attributes
for storing matrix elements. Define a copy constructor that duplicates the matrix content from another
matrix object. Implement methods for matrix addition, multiplication, transpose, and determinant
calculation.
47 | P a g e
Activity No.122
Rectangle Class with Parameterized Constructor: Develop a class representing a rectangle with attributes
for length and width. Define a parameterized constructor that initializes these attributes with given
values. Implement methods to calculate the area, perimeter, and check for squareness.
Activity No.13
Playlist Class with Copy Constructor: Design a class representing a playlist with attributes like song title,
artist, and duration. Define a copy constructor that duplicates the playlist content from another playlist
object. Implement methods to add, remove, shuffle, and display songs.
48 | P a g e
Activity No.14
Customer Class with Parameterized Constructor: Create a class representing a customer with attributes
like name, address, and phone number. Define a parameterized constructor that initializes these
attributes with provided values. Implement methods to update customer details and display information.
49 | P a g e
Activity No.15
Circle Class with Copy Constructor: Develop a class representing a circle with attributes for radius and
center coordinates. Define a copy constructor that duplicates the circle attributes from another circle
object. Implement methods to calculate the area, circumference, and check for intersection with another
circle.
Activity No.16
Email Class with Parameterized Constructor: Design a class representing an email message with
attributes like sender, recipient, subject, and body. Define a parameterized constructor that initializes
these attributes with provided values. Implement methods to send, receive, and format email messages.
50 | P a g e
Activity No.17
House Class with Copy Constructor: Create a class representing a house with attributes like address,
number of rooms, and price. Define a copy constructor that duplicates the house details from another
house object. Implement methods to update house information and calculate property taxes.
51 | P a g e
Activity No.18
Point Class with Parameterized Constructor: Develop a class representing a point in a 2D coordinate
system with attributes for x and y coordinates. Define a parameterized constructor that initializes these
attributes with given values. Implement methods to calculate the distance between two points and find
the midpoint.
Activity No.19
Invoice Class with Copy Constructor: Design a class representing an invoice for goods or services with
attributes like invoice number, item description, quantity, and price. Define a copy constructor that
duplicates the invoice details from another invoice object. Implement methods to calculate the total
amount and generate a printable invoice.
52 | P a g e
Activity No.20
53 | P a g e
Arrays Vs Vectors
Array:
 Support fixed number of elements
 Memory should be managed accordingly
 Less efficient
 Multiple data types cannot be stored
 Index based
 Occupies less memory space
Vector:
 Support dynamic number of elements
 Automatic memory management
 More efficient
 Multiple data types can be stored
 Non index based
 Occupies more memory space
54 | P a g e
Array Program:
Vector Program:
55 | P a g e
Try Throw Catch

More Related Content

Similar to Sample Lab Manual Word Edited aaaaaaaaaaaaaaa

Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
cis247
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variables
sdjdskjd9097
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
ccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
ccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
cis247
 
Cis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfacesCis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfaces
sdjdskjd9097
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
sdjdskjd9097
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
sdjdskjd9097
 
M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)
yuvanalagadapati
 

Similar to Sample Lab Manual Word Edited aaaaaaaaaaaaaaa (20)

Cis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee classCis247 a ilab 2 of 7 employee class
Cis247 a ilab 2 of 7 employee class
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variables
 
Joel Landis Net Portfolio
Joel Landis Net PortfolioJoel Landis Net Portfolio
Joel Landis Net Portfolio
 
Oose unit 3 ppt
Oose unit 3 pptOose unit 3 ppt
Oose unit 3 ppt
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
OOSE Unit 3 PPT.ppt
OOSE Unit 3 PPT.pptOOSE Unit 3 PPT.ppt
OOSE Unit 3 PPT.ppt
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfacesCis247 i lab 4 composition and class interfaces
Cis247 i lab 4 composition and class interfaces
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
 
M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 

Recently uploaded

MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 

Sample Lab Manual Word Edited aaaaaaaaaaaaaaa

  • 1. 1 | P a g e LAB MANUAL (Object-Oriented Programming.) Submitted By Name: ________________M.Faizan_______________________ Roll No#: _________________Bsf23006565_______________________ __________________________________________________________________ Prepared By _____________________________________________________________________________
  • 2. 2 | P a g e CONTENTS 1. ------------------------------------Problem Solving ------------------------------------------ 2. ---------------------------------Programming Paradigms ------------------------------------ 3. ---------------------------------Procedural programming------------------------------------ 4. ------------------------------Object-oriented programming --------------------------------- 5. -------------------------------Procedural Oriented Programming------------------------------ VS -----------------------------Object Oriented Programming---------------------------------- 6. --------------------------------------Encapsulation ------------------------------------------- 7. --------------------------------------Abstraction ---------------------------------------------- 8. -------------------------------------- Inheritance----------------------------------------------- 9. -------------------------------------- Constructors---------------------------------------------
  • 3. 3 | P a g e Problem Solving Understanding the problem Understanding Analyzing the problem Analyzing Formulating a plan Formulating Implementing the plan Implementing Programming paradigms
  • 4. 4 | P a g e Procedural programming
  • 5. 5 | P a g e Object-oriented programming • Object-oriented programming is a paradigm that focuses on the data and behavior of the entities or objects that a program manipulates. • It organizes the code into classes, which are templates or blueprints for creating objects. • Classes define the attributes and methods of the objects, which are the data and functions that belong to them. • Objects can interact with each other through messages, which are calls to their methods. Object- oriented programming is based on the idea of bottom-up design, where the problem is modeled by identifying the objects and their relationships. • Object-oriented programming is often associated with languages like Java, C++, and Python.
  • 6. 6 | P a g e  In object-oriented programming, the program is divided into small parts called objects.  OOp follows a bottom-up approach.  OOP has access specifiers like private, public, protected, etc.  Adding new data and function is easy.  Object-oriented programming provides data hiding so it is more secure.  Overloading is possible in object oriented programming.  In object-oriented programming, the concept of data hiding and inheritance is used.  In object-oriented programming, data is more important than function.  Object-oriented programming is based on the real world.  Object-oriented programming uses the concept of data abstraction.  Code reusability present in object- oriented programming  Examples:C++,C#,Python,Java Procedural Oriented Programming VS Object Oriented Programming  In procedural programming, the program is divided into small parts called functions.  Procedural programming follows a top- down approach.  There is no access specifier in procedural programming.  Adding new data and functions is not easy.  Procedural programming does not have any proper way of hiding data so it is less secure.  In procedural programming, overloading is not possible.  In procedural programming, there is no concept of data hiding and inheritance.  In procedural programming, the function is more important than the data.  Procedural programming is based on the unreal world.  Procedural programming uses the concept of procedure abstraction.  Code reusability absent in procedural programming,  Examples: C, FORTRAN, Pascal, Basic, etc.
  • 7. 7 | P a g e Classes And Functions Activity No.1 Write a C++ function that takes two integers as parameters and returns their sum. Activity No.2222 Implement a C++ function to calculate the area of a circle given its radius.
  • 8. 8 | P a g e Activity No.3 Create a C++ function that checks whether a given number is even or odd.
  • 9. 9 | P a g e Activity No.4 Write a C++ program that uses a function to find the maximum of three numbers. Activity No.5 Implement a C++ function that reverses a string.
  • 10. 10 | P a g e Activity No.6 Write a C++ function that takes two integers as parameters and returns their sum.
  • 11. 11 | P a g e Activity No.7 Implement a C++ function to calculate the area of a circle given its radius.
  • 12. 12 | P a g e Activity No.8 Create a C++ function that checks whether a given number is even or odd.
  • 13. 13 | P a g e Activity No.9 Write a C++ program that uses a function to find the maximum of three numbers
  • 14. 14 | P a g e Activity No.10 Implement a C++ function that reverses a string. Activity No.11
  • 15. 15 | P a g e Encapsulation • • • • • • • • • • • • • Data and behaviour are tightly coupled inside an object Both the information structure and implementation details of its operations are hidden from the outer world Example: Ali stores his personal information and knows how to translate it to the desired language We don’t know How the data is stored How Ali translates this information Example: A Phone stores phone numbers in digital format and knows how to convert it into human-readable characters We don’t know How the data is stored How it is converted to human-readable characters Encapsulation – Advantages ► Simplicity and clarity ► Low complexity ► Better understanding
  • 16. 16 | P a g e Abstraction • • • • • • • • • • • Smalltalk was the first pure object-oriented language, where everything was an object, even numbers and functions. Smalltalk also introduced the concepts of dynamic typing, garbage collection, and graphical user interface. Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only those details about an object that are relevant to current perspective” Example: Ali is a PhD student and teaches BS students ► Attributes - Name - Employee ID - Student Roll No - Designation - Year of Study - Salary - CGPA - Age Ali is a PhD student and teaches BS students ► behaviour - Study - DevelopExam - GiveExam - TakeExam - PlaySports - Eat - DeliverLecture - Walk Abstraction – Advantages  Simplifies the model by hiding irrelevant details  Abstraction provides the freedom to defer implementation decisions by avoiding commitment to details
  • 17. 17 | P a g e Inheritance ► A child inherits characteristics of its parents ► Besides inherited characteristics, a child may have its own unique characteristics Inheritance in Classes: ► If a class B inherits from class A then it contains all the characteristics (information structure and behaviour) of class A ► The parent class is called base class and the child class is called derived class ► Besides inherited characteristics, derived class may have its own unique characteristics Example: Person Teacher Doctor Student
  • 18. 18 | P a g e Inheritance – Advantages ► Reuse ► Less redundancy ► Increased maintainability
  • 19. 19 | P a g e Inheritance Activity No.1 Define a base class Shape with private attributes width and height. Create public member functions in the base class to set and get the values of these attributes. Derive a class Rectangle from Shape and demonstrate how to access and modify the private attributes through the public member functions. Activity No.2 Implement a base class Vehicle with a protected member function startEngine() and a derived class Car that inherits this function. Show how the protected access specifier allows the derived class to call the startEngine() function.
  • 20. 20 | P a g e Activity No.3 Create a base class Person with private attributes name and age. Provide a public member function in the base class to display the person's information. Derive a class Student from Person and demonstrate how the derived class can access the base class's private attributes through the member function.
  • 21. 21 | P a g e Activity No.4 Define a base class Employee with a protected attribute employeeID. Create a derived class Manager that has a public member function to access and display the employeeID. Activity No.5 Implement a base class Animal with a private attribute species. Create a derived class Dog that inherits the species attribute but adds a public member function getSpecies() to access it.
  • 22. 22 | P a g e Activity No.6 Use the virtual keyword to declare a virtual function display() in a base class Shape. Derive two classes, Circle and Rectangle, and override the display() function in each. Create an array of pointers to the base class and call the display() function on objects of the derived classes to demonstrate dynamic binding.
  • 23. 23 | P a g e Activity No.7 Create a base class BankAccount with protected attributes accountNumber and balance. Provide public member functions to deposit and withdraw funds. Derive a class SavingsAccount that inherits from BankAccount and includes a private attribute interestRate. Implement a public member function in SavingsAccount to calculate interest based on the balance and interest rate.
  • 24. 24 | P a g e Activity No.8 Define a base class Person with private attributes name and age. Create a derived class Student with additional private attributes like studentID and major. Provide public member functions to set and get these attributes. Activity No.9 Implement a base class Shape with protected attributes width and height. Derive a class Rectangle from Shape and add a public member function calculateArea() that calculates the area of the rectangle using the width and height attributes.
  • 25. 25 | P a g e Activity No.10 Create a base class Employee with private attributes employeeID and salary. Derive a class Manager that inherits these attributes. Implement public member functions in both classes to display the employee's information, including their ID and salary.
  • 26. 26 | P a g e Activity No.11 Define a base class Animal with a protected member function makeSound(). Derive classes Dog and Cat that override makeSound() to produce different sounds. Demonstrate polymorphism by calling makeSound() on objects of both derived classes using a base class pointer. Activity No.12 Implement a base class Vehicle with private attributes speed and fuelType. Create a derived class Car with a public member function displayInfo() that accesses and displays the speed and fuelType attributes.
  • 27. 27 | P a g e Activity No.13 Create a base class BankAccount with a private attribute accountNumber. Derive a class SavingsAccount that inherits the accountNumber attribute. Demonstrate how to access and modify the accountNumber attribute using the derived class. Activity No.14 Define a base class Shape with a public member function printInfo() that displays information about the shape. Derive classes Circle and Rectangle from Shape and override the printInfo() function in each derived class to provide specific information.
  • 28. 28 | P a g e Activity No.15 Implement a base class Employee with a private attribute employeeID. Create a derived class Manager with a public member function getEmployeeID() that returns the employeeID.
  • 29. 29 | P a g e Activity No.16 Create a base class Animal with protected attributes name and type. Derive classes Mammal and Bird from Animal and provide public member functions in each derived class to access and display the name and type attributes. Activity No.17 Define a base class Person with a protected member function printName(). Create a derived class Student that inherits this function and provides its own implementation. Demonstrate how to call both the base class and derived class versions of printName().
  • 30. 30 | P a g e Activity No.18 Implement a base class Fruit with private attributes name and color. Derive classes Apple and Banana from Fruit and provide public member functions in each derived class to access and display the name and color attributes. Activity No.19 Create a base class Shape with protected attributes width and height. Derive a class Rectangle from Shape and add public member functions setWidth() and setHeight() to modify the attributes.
  • 31. 31 | P a g e Activity No.20 Define a base class Animal with protected attributes name and type. Create a derived class Mammal with an additional attribute habitat and a public member function to display all attributes of the animal.
  • 32. 32 | P a g e Activity No.21 Create a base class BankAccount with attributes accountNumber ,name and balance with function Deposit() and withdraw(). Create a derived class SavingsAccount (2 Function(), inherits from BankAccount and includes attributes like interestRate and withdrawLimit. Users want to open a saving account and deposit some money
  • 33. 33 | P a g e Single Inheritance In this inheritance, a derived class is created from a single base class. In the given example, Class A is the parent class and Class B is the child class since Class B inherits the features and behavior of the parent class A.
  • 34. 34 | P a g e Multi-Level Inheritance In this inheritance, a derived class is created from another derived class. In the given example, class c inherits the properties and behavior of class B and class B inherits the properties and behavior of class B. So, here A is the parent class of B and class B is the parent class of C. So, here class C implicitly inherits the properties and behavior of class A along with Class B i.e there is a multilevel of inheritance.
  • 35. 35 | P a g e Multiple – Inheritance Multi-path Inheritance In this inheritance, a derived class is created from more than one base class. In this inheritance, a derived class is created from other derived classes and the same base class of other derived classes
  • 36. 36 | P a g e Hierarchical Inheritance • In this inheritance, more than one derived class is created from a single base class and further child classes act as parent classes for more than one child class. • In the given example, class A has two children class B and class D. Further, class B and class C both are having two children - class D and E; class F and G respectively.
  • 37. 37 | P a g e Constructors Constructor is a special method or function within a class that is automatically called when an object of that class is created. Its main purpose is to initialize the object's state and perform any necessary setup for the object to be used. Constructors typically have the same name as the class and do not have a return type specified. They can have parameters to accept initial values that need to be assigned to the object's attributes during the object's creation.
  • 38. 38 | P a g e Activity No.1
  • 39. 39 | P a g e Parameterized and Copy constructor A copy constructor in C++ is a special member function that creates a new object by initializing it with an existing object of the same class. It essentially creates a copy of an object, allowing for proper initialization of objects when they are passed by value or returned from a function.  A parameterized constructor in C++ is a constructor that accepts one or more parameters or arguments.  Unlike the default constructor, which has no parameters, a parameterized constructor allows you to initialize the object's data members with specific values when an object is created.
  • 40. 40 | P a g e Activity No.11 Activity No.2 Student Class with Parameterized Constructor: Create a class representing a student with attributes like name, roll number, and marks. Define a parameterized constructor that initializes these attributes with values provided as arguments. Implement methods to display student details and calculate the average marks of a group of students. Activity No.3
  • 41. 41 | P a g e Employee Class with Copy Constructor: Develop a class representing an employee with attributes like name, employee ID, and salary. Define a copy constructor that copies the attributes from another employee object. Implement methods to compare employee details, update salary, and display employee information. Activity No.4 Date Class with Parameterized Constructor: Design a class representing a date with attributes like day, month, and year. Define a parameterized constructor that initializes these attributes with given values. Implement methods to validate the date, calculate the difference between two dates, and display the date in various formats. Activity No.5
  • 42. 42 | P a g e Vector Class with Copy Constructor: Create a class representing a mathematical vector with attributes for magnitude and direction. Define a copy constructor that duplicates the vector attributes from another vector object. Implement methods to perform vector addition, subtraction, scalar multiplication, and vector normalization. Activity No.6 Book Class with Parameterized Constructor: Develop a class representing a book with attributes like title, author, and ISBN. Define a parameterized constructor that initializes these attributes with provided values. Implement methods to compare books, display book details, and update information like the number of pages or publication year.
  • 43. 43 | P a g e Activity No.7 Bank Account Class with Copy Constructor: Design a class representing a bank account with attributes like account number, account holder name, and balance. Define a copy constructor that duplicates the account details from another bank account object. Implement methods to deposit, withdraw, and transfer funds between accounts.
  • 44. 44 | P a g e Activity No.8 Triangle Class with Parameterized Constructor: Create a class representing a triangle with attributes for the lengths of its sides. Define a parameterized constructor that initializes these attributes with given values. Implement methods to calculate the area, perimeter, and classify the type of triangle (e.g., equilateral, isosceles, scalene).
  • 45. 45 | P a g e Activity No.9 String Class with Copy Constructor: Develop a class representing a string with attributes for storing character data. Define a copy constructor that duplicates the string content from another string object. Implement methods for string concatenation, substring extraction, and comparison. Activity No.10 Car Class with Parameterized Constructor: Design a class representing a car with attributes like make, model, and year of manufacture. Define a parameterized constructor that initializes these attributes with provided values. Implement methods to calculate the mileage, check for maintenance requirements, and display car information.
  • 46. 46 | P a g e Activity No.11 Matrix Class with Copy Constructor: Create a class representing a mathematical matrix with attributes for storing matrix elements. Define a copy constructor that duplicates the matrix content from another matrix object. Implement methods for matrix addition, multiplication, transpose, and determinant calculation.
  • 47. 47 | P a g e Activity No.122 Rectangle Class with Parameterized Constructor: Develop a class representing a rectangle with attributes for length and width. Define a parameterized constructor that initializes these attributes with given values. Implement methods to calculate the area, perimeter, and check for squareness. Activity No.13 Playlist Class with Copy Constructor: Design a class representing a playlist with attributes like song title, artist, and duration. Define a copy constructor that duplicates the playlist content from another playlist object. Implement methods to add, remove, shuffle, and display songs.
  • 48. 48 | P a g e Activity No.14 Customer Class with Parameterized Constructor: Create a class representing a customer with attributes like name, address, and phone number. Define a parameterized constructor that initializes these attributes with provided values. Implement methods to update customer details and display information.
  • 49. 49 | P a g e Activity No.15 Circle Class with Copy Constructor: Develop a class representing a circle with attributes for radius and center coordinates. Define a copy constructor that duplicates the circle attributes from another circle object. Implement methods to calculate the area, circumference, and check for intersection with another circle. Activity No.16 Email Class with Parameterized Constructor: Design a class representing an email message with attributes like sender, recipient, subject, and body. Define a parameterized constructor that initializes these attributes with provided values. Implement methods to send, receive, and format email messages.
  • 50. 50 | P a g e Activity No.17 House Class with Copy Constructor: Create a class representing a house with attributes like address, number of rooms, and price. Define a copy constructor that duplicates the house details from another house object. Implement methods to update house information and calculate property taxes.
  • 51. 51 | P a g e Activity No.18 Point Class with Parameterized Constructor: Develop a class representing a point in a 2D coordinate system with attributes for x and y coordinates. Define a parameterized constructor that initializes these attributes with given values. Implement methods to calculate the distance between two points and find the midpoint. Activity No.19 Invoice Class with Copy Constructor: Design a class representing an invoice for goods or services with attributes like invoice number, item description, quantity, and price. Define a copy constructor that duplicates the invoice details from another invoice object. Implement methods to calculate the total amount and generate a printable invoice.
  • 52. 52 | P a g e Activity No.20
  • 53. 53 | P a g e Arrays Vs Vectors Array:  Support fixed number of elements  Memory should be managed accordingly  Less efficient  Multiple data types cannot be stored  Index based  Occupies less memory space Vector:  Support dynamic number of elements  Automatic memory management  More efficient  Multiple data types can be stored  Non index based  Occupies more memory space
  • 54. 54 | P a g e Array Program: Vector Program:
  • 55. 55 | P a g e Try Throw Catch