0% found this document useful (0 votes)
11 views13 pages

LAB MANUAL 4 - Code

The document outlines a lab session on Object-Oriented Programming (OOP) for Spring 2024, focusing on concepts such as classes, objects, data members, and member functions. It highlights the advantages of OOP over procedural programming and provides syntax examples for defining classes and creating objects in C++. Additionally, it includes scenarios for practical application of the concepts learned.

Uploaded by

sm1385442
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

LAB MANUAL 4 - Code

The document outlines a lab session on Object-Oriented Programming (OOP) for Spring 2024, focusing on concepts such as classes, objects, data members, and member functions. It highlights the advantages of OOP over procedural programming and provides syntax examples for defining classes and creating objects in C++. Additionally, it includes scenarios for practical application of the concepts learned.

Uploaded by

sm1385442
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

OOP – Class | Object | Data Members |Member Functions |

Object Oriented Programming


LAB 04

Lab Instructor: Jawad Hassan


Department of Artificial Intelligence
Email: [email protected]

SESSION: Spring-2024
SEMESTER: 2nd
OOP – Class | Object | Data Members |Member Functions |
Outlines
Lab - 1
Revised Programming Fundamentals
Lab – 2
 OOP Introduction
 Class
 Object
 Data Members
 Member Member Functions
Lab - 3
Unified Modeling Language to Code
 Class
 Object
 Data Members
 Member Member Functions
 Constructor
 Defualt
 Parametrize
Lab - 4
Code to the given Scenarios
OOP – Class | Object | Data Members |Member Functions |
OOP Introduction
OOP stands for Object-Oriented Programming.
Procedural programming is about writing procedures or functions that perform operations on the
data, while object-oriented programming is about creating objects that contain both data and
functions.
Object-oriented programming has several advantages over procedural programming:
 OOP is faster and easier to execute
 OOP provides a clear structure for the programs
 OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to
maintain, modify and debug
 OOP makes it possible to create full reusable applications with less code and shorter
development time
OOP – Class | Object | Data Members |Member Functions |
Class
A class is a blueprint for the object.
We can think of a class as a sketch (prototype) of a house.
It contains all the details about the floors, doors, windows, etc - we build the house based on these
descriptions.

Syntax:

class className {
// data member
// member function
};

class Car {
// data member
// member function
};

Object
When a class is defined, only the specification for the object is defined; no memory or storage is
OOP – Class | Object | Data Members |Member Functions |
allocated.
To use the data and access functions defined in the class, we need to create objects.

Syntax:

Int main() {
Class_name Object;
};

Int main() {
Car car1,car2,car3;
};

Data Members
In C++, a data member is a variable declared within a class. It represents the state or attributes of
objects created from that class. Data members hold information that is specific to each instance of
OOP – Class | Object | Data Members |Member Functions |
the class.
Syntax:

class Car {
int model;
double price;
string height;
int bulid_year;
// member function
};

Member Functions
In C++, a member function is a function that is declared as part of a class definition. Member
functions operate on objects of the class and have access to the class's data members (variables) and
other member functions. They encapsulate the behavior or actions that objects of the class can
perform.
Syntax:

#include <iostream>
using namespace std;

class Car {
public:
string model = GLI;
double price = 1000000;
string color = “white”;
int bulid_year = 2002;
void display_info()
{
cout<<model<<price<<color<<bulid_year;
}
};
OOP – Class | Object | Data Members |Member Functions |

Draw a class diagram of Car…….


OOP – Class | Object | Data Members |Member Functions |

Class Name
{
Private:
string model;
string color;
double price;
int bulid year;
Public:
Member Functions
};

Task
Scenario 1:
OOP – Class | Object | Data Members |Member Functions |
Once upon a time, in a friendly neighborhood, there was a lively dog named Fido. Fido was always
cheerful and full of energy, eager to explore everything around him…………………………..

Scenraio 2:
Once upon a time, in the big sandy deserts, there was a special creature called the Camel. The Camel
OOP – Class | Object | Data Members |Member Functions |
was big and strong but also gentle and kind…………………………

Scenario 3:
Once upon a time, in a peaceful country side surrounded by hills and green fields, there was a gentle
cow named Daisy. Daisy wasn't like any other cow; she was famous for giving lots of milk and for her
OOP – Class | Object | Data Members |Member Functions |
sweet "moo" that echoed across the land………………………………………..

Scenraio 4:
OOP – Class | Object | Data Members |Member Functions |
OOP – Class | Object | Data Members |Member Functions |

You might also like