0% found this document useful (0 votes)
15 views2 pages

Practical 1

Uploaded by

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

Practical 1

Uploaded by

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

CO207U Object Oriented Programming Lab

Government College of Engineering, Jalgaon


(An Autonomous Institute of Government of Maharashtra)

PRN: ____________________ Name of the Student:________________________________

Class :_________ Semester :__________ Session:________________________

Subject Teacher: Shrutika Mahajan Subject Coordinator:

Aim:​ Write a program for a simple class and object. Performing simple arithmetic operations using
C ++ class and object like, Addition, Subtraction, Multiplication & Division.​

Compiler used:​ We used the g++ compiler to compile the C++ program.
Operating System used:​ Ubuntu

Theory:
The main purpose of C++ programming is to add object orientation to the C programming
language and classes are the central feature of C++ that supports object-oriented programming and
are often called user-defined types.
A class is used to specify the form of an object and it combines data representation and
methods for manipulating that data into one neat package. The data and functions within a class are
called members of the class.
A class definition starts with the keyword ​class​ followed by the class name; and the class
body, enclosed by a pair of curly braces. A class definition must be followed either by a semicolon
or a list of declarations. For example, we defined the Box data type using the keyword ​class​ as
follows −
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
The keyword ​public​ determines the access attributes of the members of the class that
follows it. A public member can be accessed from outside the class anywhere within the scope of
the class object. You can also specify the members of a class as ​private​ or ​protected​ which we
will discuss in a sub-section.

Define C++ Objects


A class provides the blueprints for objects, so basically an object is created from a class. We
declare objects of a class with exactly the same sort of declaration that we declare variables of
basic types. Following statements declare two objects of class Box −
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box

Prepared By: Mrs. Shrutika S.Mahajan


CO207U Object Oriented Programming Lab

Both of the objects Box1 and Box2 will have their own copy of data members.

Accessing the Data Members


The public data members of objects of a class can be accessed using the direct member access
operator (.).
This program demonstrates how classes and its objects are created in program. Using
add(),sub(),mul(),div(),mod() member functions arithmetic operations are performed.

Pseudo Code:
1. Start.
2. Declare the class Arithmetic
3. Declare the private and public data members and 5 member functions.
4. Define the member functions add(),sub(),mul(),div(),mod() in class and returning
statements.
5. In main function create an object of a class Arithmetic class
6. Access all member functions such as add(),sub(),mul(),div(),mod()by calling it using
object(“ .” operator)
7. Print results of all arithmetic operations.
8. Stop
Conclusion:

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
----------------

Sign of Teacher

Prepared By: Mrs. Shrutika S.Mahajan

You might also like