Copy Oc++f Public and Private

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

Subject: Object Oriented Programming

Dept of Electrical Engineering

GC University Faisalabad

Muhammad Nadeem Roll No 2522 Section (A)

Topic

Public and Private data Using Class

Access specifier is the keyword used for defining the scope of the member of class. There are two important access specifier in c++.
Private Public

(Private Access specifier)

Private

The private data and function can be accessed within the class

Only member of the same class can access the private data

It cant be accessed by functions outside the class Private access specifier is for internal use only.

(Private Access specifier)

Private

Data is important

The private data and function can be accessed within the class

It cant be accessed by functions outside the class Private access specifier is for internal use only.

Graphically Data Privatization


Class

Now Data is Protected

Data

In capsulation

Public
Inside the member of the class

Data & Function


Outside the member of the class

Public

Syntax

class class_name { private:

Access specifier

int a; char b; public:


show(); input(); };

private data members

Public function members

Rouf-ur-Rehman Roll No 2511 Section (A)

Topic

If Structure

If Structure
If statement Is a decision-making statement. It is the simplest form of selection constructs. it is used to execute or skip a statement or simply checking a statement

Using if/else
The if/else structure is sometimes called a two-way selection structure. Using if/else, one block of code is executed if the control expression is true. The else portion of the structure is executed if the control expression is false.

True or False

Syntex Flow Chart


if (<Boolean expression>) { <statement 1> . . }

Condition
true

false

else { <statement 1> . . }

statement

True or False

Confusing = and = =

Dont confuse the meaning of = in Math with its meaning in C++. The symbol = means assigning a value to an identifier, and not that two objects or expressions are equal in C++. The symbol = = means equality in a comparison in C++. Side effects are caused if we confuse the two operators.

15

You might also like