Basic Object-
Oriented Concepts
By,
Shashikant pabari
Identifiers :
• They refer to the names of variables, function, array, classes
etc., created by the programmer.
• Each language has its own rules for naming these identifiers.
• Following are common rules for both C and C++:
o Only alphabetic characters, digit and underscores are
permitted.
o The name cannot start with a digit.
o Uppercase and lowercase letters are distinct.
o A declared keyword cannot be used as a variable name.
Some Examples of Identifier
Identifier Validity Reason
1digit Invalid Digit at first location is not allowed
digit-1 Invalid Special characters other than
underscore is not allowed
num 1 Invalid Space not allowed
num_1 Valid Underscore is valid identifier.
3
Constants :
• Constants refer to fixed values that do not change during
the execution of a program.
• They include integers, characters, floating point number
and strings.
• Literal constant do not have memory location.
• Ex :
• 123 // decimal integer
• 12.34 // floating point integer
• “c++” // string constant
• ‘A’ // character constant
4
Variable :
• A variable is the name for a place in the computer’s
memory where you store some data.
• Declaration of variable :
• A variable can be declared right at the place of its first use.
• This make the program much easier to write and reduces the errors
that may be caused by having to scan back and forth.
• It also make the program easier to understand because the
variables are declared in the context of their use.
• Ex :
float x; //declaration
int a; //declaration
5
Continue…
• Reference Variable :
• A new kind of variable known as the reference variable.
• A reference variable provides an alternative name for a previously
define variable.
• For example, If we make the variable sum a reference to the
variable total, then sum and total can be used interchangeable to
represent that variable.
• Syntax :
data-type & reference-name = variable-name
Ex:
float total = 50;
float & sum = total;
6
Operators :
• An operator is a symbol that tells the compiler to perform certain
mathematical or logical operation.
1. Arithmetic Operators :
o Arithmetic operators are used for mathematical calculation.
o Arithmetic operators are +, -, *, /, and %.
1. Relation operators :
o used to compare two numbers and taking decisions based on their
relation.
o Relation operators are <, <=, >, >=, ==, and != .
1. Logical operators:
o Used to test more than one condition and make decisions.
o Logical operators are &&, ||, and !.
7
Continue…
4. Assignment operators :
o Used to assign the result of an expression to a variable.
o Assignment operators are =, +=, -=, *=, /=, and %=.
5. Increment operators :
o These are special operators in c++.
o Increment operators are ++, and --.
6. Conditional operators:
o A ternary operator is known as conditional operators.
o Ex : x = (a>b) ? a : b; which is same as
if(a>b)
x=a;
else x=b;
8
Continue…
7. Bitwise operator :
o Used to perform operators bit by bit and may not be applied to
float or double.
o Bitwise operators are &, |, ^, <<, and >>.
8. Special operators :
o Special operators are
& is used to determine address of the variable.
* is used declare a pointer variable and to get value from it.
‘ is used to link the related expression together.
. is used in structure.
-> is used in pointer to structure.
9
Continue…
9. Extraction operators (>>) :
o Is used with cin to input data from keyboard.
10. Insertion operators (<<) :
o Is used with cout to output data from keyboard.
11. Scope resolution operators (::)
o It can be used in constructing programs. We know that the same
variable name can be used to have different meanings in different
blocks.
o Ex : int m=10;
{ int m=20; Output : m = 20
cout << “m” << m; ::m = 10
cout << “::m” << ::m;
}
10
Type Casting :
• It is used to convert the type of a variable, function, object,
expression or return value to another type.
• Type casting can also done using some typecast operators
available in c++.
• Static_cast operator : The static_cast keyword can be used for any
normal conversion between types. Conversions that rely on static
(compile-time) type information.
• Syntax : Static_cast <type> (object).
• Const_cast operator : The const_cast keyword can be used to remove
the const or volatile property from an object.
• Syntax : const_cast <type> (object).
11
Continue…
• Reinterpret_cast operator : The reinterpret_cast keyword is used
to simply cast one type bitwise to another. Any pointer or integral
type can be cast to any other with reinterpret cast, easily allowing
for misuse.
• Syntax : reinterpret_cast <type> (object).
• Dynamic_cast operator : The dynamic_cast keyword is used to
casts a datum from one pointer or reference of a polymorphic type
to another, similar to static_cast but performing a type safety check
at runtime to ensure the validity of the cast.
• Syntax : dynamic_cast <type> (object).
12
Continue…
• Example :
Main()
{
double a = 21.09399;
float b = 10.20;
int c;
c = int (a);
cout << “value of int(a) is :” << c << endl;
c = int (b);
cout << “value of int(b) is :” << c << endl;
return 0;
}
Output : value of int(a) is : 21
value of int(b) is : 10
13
Enumerated Data Type :
• An enumerated data type is another user-defined type which
provides a way for attaching names to numbers, thereby
increasing comprehensibility of the code.
• The enum keyword (from c) automatically enumerates a list of
words by assigning them values 0,1,2, and so on.
• This facility provides an alternative means for creative symbolic
comstants.
• The syntax of an enum statement is similar to that of the struct
statement.
• Ex : enum shape {circle, square, triangle}
enum colour {red, blue, green, yellow}
enum position {off, on}
14
Control Structures
• A large number of function are used that pass messages,
and process the data contained in objects.
• A function is set to perform a task. when the task is
complex, many different algorithms can be designed to
achieve the same goal. Some are simple to comprehend,
while others are not.
• The format should be such that it is easy to trace the flow of
execution of statements.
• Control structure tells about the order in which the
statement are executed and helps to perform manipulative,
repetitive and decision making actions.
• It can be used in three ways :
15
Continue…
1) Sequence structure (straight line)
2) Selection structure (branching)
3) Loop structure (iteration or repetition)
• Basic control structures
16(a) Sequence (b) Selection (c) Loop
Continue…
• Selection Structure (Branching Statements) :
• if statement.
• if-else statement.
• switch statement.
• goto statement.
• Loop structure (iteration or repetition) :
• While statement.
• Do-while statement.
• For statement.
if Selection Structure
• Selection structure
• Choose among alternative courses of action
• Pseudocode example:
If student’s grade is greater than or equal to 60
Print “Passed”
• If the condition is true
• Print statement executed, program continues to next
statement
• If the condition is false
• Print statement ignored, program continues
• Indenting makes programs easier to read
• C++ ignores whitespace characters (tabs, spaces, etc.)
• Translation into C++
If student’s grade is greater than or equal to 60
Print “Passed”
if ( grade >= 60 )
cout << "Passed";
• if structure
• Single-entry/single-exit
true
false
grade >= 60 print “Passed”
if/else Selection Structure
• if
• Performs action if condition true
• if/else
• Different actions if conditions true or false
• Pseudocode
if student’s grade is greater than or equal to 60
print “Passed”
else
print “Failed”
• C++ code
if ( grade >= 60 )
cout << "Passed";
else
cout << "Failed";
20
Example
if ( grade >= 90 ) // 90
and above
cout << "A";
else if ( grade >= 80 ) // 80-89
cout << "B";
else if ( grade >= 70 ) // 70-79
cout << "C";
else if ( grade >= 60 ) // 60-69
cout << "D";
else // less than
60
cout << "F";
21
Switch Case
• switch
• Test variable for multiple values
• Series of case labels and optional default case
switch ( variable ) {
case value1: // taken if variable == value1
statements
break; // necessary to exit switch
case value2:
case value3: // taken if variable == value2 or == value3
statements
break;
default: // taken if variable matches no other cases
statements
break;
}
22
While loop
23
sample <= 2000 sample = 2 * sample
true
false
• Flowchart of while loop
While loop
• Repetition structure
• Action repeated while some condition remains true
• Psuedocode
while there are more items on my shopping list
Purchase next item and cross it off my list
• while loop repeated until condition becomes false
• Example
int sample = 2;
while (sample <= 2000 )
sample = 2 * sample;
24
25
for loop
• General format when using for loops
for ( initialization; LoopCount ;increment/decrement )
• Example
for( int sample = 1; sample <= 10; sample++ )
cout << sample << endl;
• Prints int value from one to ten
 
The End
26

More Related Content

ODP
Datatype in JavaScript
PPTX
PPTX
Java if else condition - powerpoint persentation
PPTX
Java Data Types and Variables
PPTX
Tokens expressionsin C++
PDF
Print function in PHP
PPTX
Operators in java
PPTX
Introduction to JavaScript Basics.
Datatype in JavaScript
Java if else condition - powerpoint persentation
Java Data Types and Variables
Tokens expressionsin C++
Print function in PHP
Operators in java
Introduction to JavaScript Basics.

What's hot (20)

PPTX
Variable and constants in Vb.NET
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPTX
PPTX
Statements and Conditions in PHP
PDF
Lect 1-java object-classes
PDF
JavaScript - Chapter 11 - Events
PPTX
Python oop - class 2 (inheritance)
PPTX
Coding standards and guidelines
PDF
PPTX
Python oop class 1
PPTX
Python
PDF
Python libraries
PPTX
Event In JavaScript
PPTX
Unit 7. Functions
PPTX
Object Oriented Programming Concepts for beginners
PPTX
Coding standards for java
PPT
CSS Basics
PPT
Operators in C++
Variable and constants in Vb.NET
The Three Basic Selection Structures in C++ Programming Concepts
Statements and Conditions in PHP
Lect 1-java object-classes
JavaScript - Chapter 11 - Events
Python oop - class 2 (inheritance)
Coding standards and guidelines
Python oop class 1
Python
Python libraries
Event In JavaScript
Unit 7. Functions
Object Oriented Programming Concepts for beginners
Coding standards for java
CSS Basics
Operators in C++
Ad

Viewers also liked (18)

PPT
Basic of c &c++
PPTX
Memory organisation ppt final presentation
PPTX
Java programming course for beginners
PPTX
Memory Organization
PDF
Memory organization
PPT
Java basic
PPSX
C++ Programming Language
PPSX
Hacking
PPTX
ETHICAL HACKING PPT
PPTX
Introduction To Ethical Hacking
PPTX
C++ ppt
PPTX
Ethical hacking presentation
PPTX
Introduction to java
PPT
Cloud computing ppt
PPT
Cloud computing simple ppt
PPT
Java tutorial PPT
PPT
Basics of c++ Programming Language
PPTX
Introduction of Cloud computing
Basic of c &c++
Memory organisation ppt final presentation
Java programming course for beginners
Memory Organization
Memory organization
Java basic
C++ Programming Language
Hacking
ETHICAL HACKING PPT
Introduction To Ethical Hacking
C++ ppt
Ethical hacking presentation
Introduction to java
Cloud computing ppt
Cloud computing simple ppt
Java tutorial PPT
Basics of c++ Programming Language
Introduction of Cloud computing
Ad

Similar to Basic concept of c++ (20)

PPT
Introduction to c
PPTX
Unit 2- Control Structures in C programming.pptx
PPTX
Programming fundamental 02.pptx
PPTX
C Language Part 1
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
PPTX
C programming language:- Introduction to C Programming - Overview and Importa...
PPTX
C Programming with oops Concept and Pointer
PPTX
Lecture 2 variables
PPTX
comp 122 Chapter 2.pptx,language semantics
PDF
Lamborghini Veneno Allegheri #2004@f**ck
PPTX
OOP in C++ – Complete Unit 1 Guide with Examples & Key Concepts
PPT
lecture2 (1).ppt variable s and operators
PPTX
Fundamentals of .Net Programming concepts
PPTX
Review of C programming language.pptx...
PPTX
Cs1123 4 variables_constants
PDF
C programing Tutorial
PPTX
C sharp part 001
PDF
2nd PUC Computer science chapter 5 review of c++
PPTX
Computer programming - variables constants operators expressions and statements
PPT
c-programming
Introduction to c
Unit 2- Control Structures in C programming.pptx
Programming fundamental 02.pptx
C Language Part 1
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
C programming language:- Introduction to C Programming - Overview and Importa...
C Programming with oops Concept and Pointer
Lecture 2 variables
comp 122 Chapter 2.pptx,language semantics
Lamborghini Veneno Allegheri #2004@f**ck
OOP in C++ – Complete Unit 1 Guide with Examples & Key Concepts
lecture2 (1).ppt variable s and operators
Fundamentals of .Net Programming concepts
Review of C programming language.pptx...
Cs1123 4 variables_constants
C programing Tutorial
C sharp part 001
2nd PUC Computer science chapter 5 review of c++
Computer programming - variables constants operators expressions and statements
c-programming

More from shashikant pabari (6)

PPTX
Remote spy(Real Time Spy)
PPTX
File System and File allocation tables
PPTX
Basic shortcut keys of computer or PC
PPTX
Imap(internet massege access protocaols)
PPT
Data representation
PPTX
Newton cotes integration method
Remote spy(Real Time Spy)
File System and File allocation tables
Basic shortcut keys of computer or PC
Imap(internet massege access protocaols)
Data representation
Newton cotes integration method

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
HVAC Specification 2024 according to central public works department
PDF
advance database management system book.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
Trump Administration's workforce development strategy
History, Philosophy and sociology of education (1).pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
AI-driven educational solutions for real-life interventions in the Philippine...
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
HVAC Specification 2024 according to central public works department
advance database management system book.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
LDMMIA Reiki Yoga Finals Review Spring Summer
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Unit 4 Computer Architecture Multicore Processor.pptx

Basic concept of c++

  • 2. Identifiers : • They refer to the names of variables, function, array, classes etc., created by the programmer. • Each language has its own rules for naming these identifiers. • Following are common rules for both C and C++: o Only alphabetic characters, digit and underscores are permitted. o The name cannot start with a digit. o Uppercase and lowercase letters are distinct. o A declared keyword cannot be used as a variable name.
  • 3. Some Examples of Identifier Identifier Validity Reason 1digit Invalid Digit at first location is not allowed digit-1 Invalid Special characters other than underscore is not allowed num 1 Invalid Space not allowed num_1 Valid Underscore is valid identifier. 3
  • 4. Constants : • Constants refer to fixed values that do not change during the execution of a program. • They include integers, characters, floating point number and strings. • Literal constant do not have memory location. • Ex : • 123 // decimal integer • 12.34 // floating point integer • “c++” // string constant • ‘A’ // character constant 4
  • 5. Variable : • A variable is the name for a place in the computer’s memory where you store some data. • Declaration of variable : • A variable can be declared right at the place of its first use. • This make the program much easier to write and reduces the errors that may be caused by having to scan back and forth. • It also make the program easier to understand because the variables are declared in the context of their use. • Ex : float x; //declaration int a; //declaration 5
  • 6. Continue… • Reference Variable : • A new kind of variable known as the reference variable. • A reference variable provides an alternative name for a previously define variable. • For example, If we make the variable sum a reference to the variable total, then sum and total can be used interchangeable to represent that variable. • Syntax : data-type & reference-name = variable-name Ex: float total = 50; float & sum = total; 6
  • 7. Operators : • An operator is a symbol that tells the compiler to perform certain mathematical or logical operation. 1. Arithmetic Operators : o Arithmetic operators are used for mathematical calculation. o Arithmetic operators are +, -, *, /, and %. 1. Relation operators : o used to compare two numbers and taking decisions based on their relation. o Relation operators are <, <=, >, >=, ==, and != . 1. Logical operators: o Used to test more than one condition and make decisions. o Logical operators are &&, ||, and !. 7
  • 8. Continue… 4. Assignment operators : o Used to assign the result of an expression to a variable. o Assignment operators are =, +=, -=, *=, /=, and %=. 5. Increment operators : o These are special operators in c++. o Increment operators are ++, and --. 6. Conditional operators: o A ternary operator is known as conditional operators. o Ex : x = (a>b) ? a : b; which is same as if(a>b) x=a; else x=b; 8
  • 9. Continue… 7. Bitwise operator : o Used to perform operators bit by bit and may not be applied to float or double. o Bitwise operators are &, |, ^, <<, and >>. 8. Special operators : o Special operators are & is used to determine address of the variable. * is used declare a pointer variable and to get value from it. ‘ is used to link the related expression together. . is used in structure. -> is used in pointer to structure. 9
  • 10. Continue… 9. Extraction operators (>>) : o Is used with cin to input data from keyboard. 10. Insertion operators (<<) : o Is used with cout to output data from keyboard. 11. Scope resolution operators (::) o It can be used in constructing programs. We know that the same variable name can be used to have different meanings in different blocks. o Ex : int m=10; { int m=20; Output : m = 20 cout << “m” << m; ::m = 10 cout << “::m” << ::m; } 10
  • 11. Type Casting : • It is used to convert the type of a variable, function, object, expression or return value to another type. • Type casting can also done using some typecast operators available in c++. • Static_cast operator : The static_cast keyword can be used for any normal conversion between types. Conversions that rely on static (compile-time) type information. • Syntax : Static_cast <type> (object). • Const_cast operator : The const_cast keyword can be used to remove the const or volatile property from an object. • Syntax : const_cast <type> (object). 11
  • 12. Continue… • Reinterpret_cast operator : The reinterpret_cast keyword is used to simply cast one type bitwise to another. Any pointer or integral type can be cast to any other with reinterpret cast, easily allowing for misuse. • Syntax : reinterpret_cast <type> (object). • Dynamic_cast operator : The dynamic_cast keyword is used to casts a datum from one pointer or reference of a polymorphic type to another, similar to static_cast but performing a type safety check at runtime to ensure the validity of the cast. • Syntax : dynamic_cast <type> (object). 12
  • 13. Continue… • Example : Main() { double a = 21.09399; float b = 10.20; int c; c = int (a); cout << “value of int(a) is :” << c << endl; c = int (b); cout << “value of int(b) is :” << c << endl; return 0; } Output : value of int(a) is : 21 value of int(b) is : 10 13
  • 14. Enumerated Data Type : • An enumerated data type is another user-defined type which provides a way for attaching names to numbers, thereby increasing comprehensibility of the code. • The enum keyword (from c) automatically enumerates a list of words by assigning them values 0,1,2, and so on. • This facility provides an alternative means for creative symbolic comstants. • The syntax of an enum statement is similar to that of the struct statement. • Ex : enum shape {circle, square, triangle} enum colour {red, blue, green, yellow} enum position {off, on} 14
  • 15. Control Structures • A large number of function are used that pass messages, and process the data contained in objects. • A function is set to perform a task. when the task is complex, many different algorithms can be designed to achieve the same goal. Some are simple to comprehend, while others are not. • The format should be such that it is easy to trace the flow of execution of statements. • Control structure tells about the order in which the statement are executed and helps to perform manipulative, repetitive and decision making actions. • It can be used in three ways : 15
  • 16. Continue… 1) Sequence structure (straight line) 2) Selection structure (branching) 3) Loop structure (iteration or repetition) • Basic control structures 16(a) Sequence (b) Selection (c) Loop
  • 17. Continue… • Selection Structure (Branching Statements) : • if statement. • if-else statement. • switch statement. • goto statement. • Loop structure (iteration or repetition) : • While statement. • Do-while statement. • For statement.
  • 18. if Selection Structure • Selection structure • Choose among alternative courses of action • Pseudocode example: If student’s grade is greater than or equal to 60 Print “Passed” • If the condition is true • Print statement executed, program continues to next statement • If the condition is false • Print statement ignored, program continues • Indenting makes programs easier to read • C++ ignores whitespace characters (tabs, spaces, etc.)
  • 19. • Translation into C++ If student’s grade is greater than or equal to 60 Print “Passed” if ( grade >= 60 ) cout << "Passed"; • if structure • Single-entry/single-exit true false grade >= 60 print “Passed”
  • 20. if/else Selection Structure • if • Performs action if condition true • if/else • Different actions if conditions true or false • Pseudocode if student’s grade is greater than or equal to 60 print “Passed” else print “Failed” • C++ code if ( grade >= 60 ) cout << "Passed"; else cout << "Failed"; 20
  • 21. Example if ( grade >= 90 ) // 90 and above cout << "A"; else if ( grade >= 80 ) // 80-89 cout << "B"; else if ( grade >= 70 ) // 70-79 cout << "C"; else if ( grade >= 60 ) // 60-69 cout << "D"; else // less than 60 cout << "F"; 21
  • 22. Switch Case • switch • Test variable for multiple values • Series of case labels and optional default case switch ( variable ) { case value1: // taken if variable == value1 statements break; // necessary to exit switch case value2: case value3: // taken if variable == value2 or == value3 statements break; default: // taken if variable matches no other cases statements break; } 22
  • 23. While loop 23 sample <= 2000 sample = 2 * sample true false • Flowchart of while loop
  • 24. While loop • Repetition structure • Action repeated while some condition remains true • Psuedocode while there are more items on my shopping list Purchase next item and cross it off my list • while loop repeated until condition becomes false • Example int sample = 2; while (sample <= 2000 ) sample = 2 * sample; 24
  • 25. 25 for loop • General format when using for loops for ( initialization; LoopCount ;increment/decrement ) • Example for( int sample = 1; sample <= 10; sample++ ) cout << sample << endl; • Prints int value from one to ten