C++ Programming Unit-1(ii) - UPDATED
C++ Programming Unit-1(ii) - UPDATED
Features of C++
C++ Objects
OBJECT-BASED OBJECT-ORIENTED
PROGRAMMING LANGUAGE PROGRAMMING LANGUAGE
ENCAPSULATION
DATA ABSTARCTION
Encapsulation:
• The wrapping up of data and functions into a single unit is called as Encapsulation.
Data Abstraction:
Inheritance:
• It is the process of one class acquires the properties of another class.
• This concept is the idea of reusability. It means the additional features can be added to an
Polymorphism:
• The word polymorphism is derived from the Greek meaning many forms.
Message Passing:
• It is a communication technique that allows different parts of a program or
Delegation:
• It means using the object of another class as a class member of another
Genericity:
• It allows the declaration of data items without specifying their exact data type.
Extensibility:
• The extension of the functionality of the existing software components.
• In other words, adding new functionality by inheriting new data types from the
Persistence:
• The object outlives the execution time and exists between execution of a program
is known as persistence.
CLASS
• The class mechanism in object-oriented languages provides a way to
create objects.
A class encloses both the data and function that operate on the data into a single unit.
The variables and functions enclosed in a class are called Data members and
class Class_Name
PRIVATE:
• In general, data members are declared as private specifier.
• Once the data members are declared as private, it becomes completely hidden
Syntax-1:
class Class_Name
{
Syntax-2:
class Class_Name Object-1, Object-2, ………...;
Syntax-3:
Class_Name Object-1, Object-2, …………….....;
DR. BAPUJI RAO, Department of CSE(CORE)
EXAMPLE
21
Note:
The size of objects OBJ and SRM are 23 bytes each. DR. BAPUJI RAO, Department of CSE(CORE)
MEMBER ACCESS OPERATOT ( . [DOT] )
22
The data members and member functions of a class are accessed through its
object with DOT ( . ) operator.
a b c
class PrivateProtected
{ obj 10 20 30
private:
void main( )
int a;
• The definition of the member function is given inside the class declaration.
• Syntax:
• The prototype or declaration of member function is given inside the class declaration;
where as the definition is given outside the class declaration.
• Syntax:
// Sum of Two Numbers using Outline Member Function // outline member function definition
#include<iostream.h> void TwoNumberSum::Assign(float m, float n)
{
class TwoNumberSum a = m;
void main( )
{
TwoNumberSum A;
A.Assign(4.5, 10);
A.Sum();
}
DR. BAPUJI RAO, Department of CSE(CORE)
QUESTION-1
29
Assign {7, 1, 4, 3, 10, 66, 67} in an array and display it using class and object.
#include<iostream.h>
class Array
Write a C++ Program to read rXc numbers in a matrix. Then display it using class and object.
#include<iostream.h>
#include<iomanip.h>
void main( )
{
Time T1, T2, T3;
Matrix Matrix::Multiply(Matrix A)
{
Matrix B;
void main ( )
{
int mat1[][2] = {{1, 2}, {3, 4}} ;
• PASS-BY-REFERENCE
o The value object is passed to the member function.
Syntax:
class class_name
{ private:
// data member(s);
public:
return_type function_name(class_name &object-1, class_name &object-2, ……)
{
// statement(s);
}
};
DR. BAPUJI RAO, Department of CSE(CORE)
Program: Add arr1 = {1, 3, 4, 7, 67} and arr2 = {2, 5, 6, 7, 1}
and store in arr2 using reference objects in a member 52
function.
void Array::Assign(int b[])
{
for (int i=0; i<5; i++)
void main ( )
{
int arr1[] = {1, 3, 4,7, 67};
• PASS-BY-ADDRESS / POINTER
o An address of the object is passed to the member function.
Syntax:
class class_name
{ private:
// data member(s);
public:
return_type function_name(class_name *object-1, class_name *object-2, ……)
{
// statement(s);
}
};
DR. BAPUJI RAO, Department of CSE(CORE)
Program: Add arr1 = {1, 3, 4, 7, 67} and arr2 = {2, 5, 6, 7, 1}
and store in arr2 using pointer objects in a member function. 55
void main ( )
{
int arr1[] = {1, 3, 4,7, 67};
INTRODUCTION
• Unified Modeling Language (UML) is used for documentation of the systems and
It is useful both for abstract modelling and for designing the actual programs.
It provides a graphic notation for modelling classes and their relationships, thereby describing possible
objects.
Class Name:
Class Name Mandatory
• Every class must have a unique name.
• Classes are used to describe a part of the real world, or part of
Operations: Operation-1
• Operations describe what can be done with the instances of a Operation-2
--------------- Optional
class.
---------------
• Each operation has a signature, which specifies the types of its Operation-N
parameters and the type of the value it returns (if any).
Person
- name : string
The UML symbol for an object is a box with an object name followed by a
12. Anchor It is used to connect between the use case and note.
MOBILE BILL
MANAGEMENT SYSTEM
Actor
Mobile Phone Handle Call
Actors
Bill Mobile Company
Management
Customer
ATM SYSTEM
Check Balance
Customer
Cash
Withdrawal
Bank
Money Transfer
Maintenance
Technician
Repair
Process Order
Customer Place Order
Manage
Make Payment
Inventory
Company
Receive Order Manage
Payments
Notify
Customer
DR. BAPUJI RAO, Department of CSE(CORE)
GENERALIZATION
73
Example-1:
Parent
Child
Example-2:
• The Graduate use case inherits the behaviour and meaning of the Registration
Registration
Example-3:
• The actor Order Registry Clerk can instantiate the general use case Place
Order.
Place Order
Order Registry
Clerk
Phone
Internet Order
Order
Internet Customer
Customer
THANK YOU