Introduction of OOPs and C++
Introduction of OOPs and C++
• Programming Concept
• Basic C++
• C++ Extension from C
• Characteristics of OOPL:
• Encapsulation
• Inheritance
• Polymorphism
• OOPLs support :
• Modular Programming
• Ease of Development
• Maintainability
• Information Hiding
• Making objects and algorithms invisible to portions of the system that do not
need them.
Employee Student
Faculty Staff
Administrator Teacher
TwoDimensionalShape ThreeDimensionalShape
cout<<"Addition : ";
cout<<number1+number2; //Display Addition
return 0;
}
CONSTANTS
NUMERIC CHARACTER
CONSTANTS CONSTANTS
SINGLE
INTEGER REAL STRING
CHARACTER
CONSTANTS CONSTANTS CONSTANTS
CONSTANTS
i.e. i.e. i.e.
i.e.
123,-321, 6543 0.0083, -0.75 “Hello”, “197”
‘5’, ‘X’, ‘;’
9/19/2024 Dr. ASHISH KUMAR SAHU 36
C++ Operators
Literal: ex. i = 1;
Variable identifier: ex. start = i;
Expression: ex. sum = first + second;
9/19/2024 Dr. ASHISH KUMAR SAHU 42
Assignment
Syntax: Operators (Shorthand)
leftSide Op= rightSide ;
It is an arithmetic
operator.
x = 10 ; After execution
p = ++x; x will be 11
First increment value of p will be 11
x by one
Operator Description
Post increment operator (x++) value of x is incremented after assigning it
to the variable on the left
x = 10 ; After execution
p = x++; x will be 11
p will be 10
First assign value of x
9/19/2024 Dr. ASHISH KUMAR SAHU 45
What is the output of this program?
#include <iostream>
using namespace std;
int main ()
{
int x, y;
x = 5;
y = ++x * ++x;
cout << x << y;
x = 5;
y = x++ * ++x;
cout << x << y;
}
(A) 749735
(B) 736749
(C) 367497
(D) none of the mentioned
9/19/2024 Dr. ASHISH KUMAR SAHU 46
Conditional
Syntax: Operator
exp1 ? exp2 : exp3
Working of the ? Operator:
▪ exp1 is evaluated first
• if exp1 is true(nonzero) then
- exp2 is evaluated and its value becomes the value of the expression
• If exp1 is false(zero) then
- exp3 is evaluated and its value becomes the value of the expression
Ex: Ex:
m=2; m=2;
n=3; n=3;
r=(m>n) ? m : n; r=(m<n) ? m : n;
Value of r will be 3 Value of r will be 2
9/19/2024 Dr. ASHISH KUMAR SAHU 47
Bitwise Operator
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
p
addr
r i
addr
A reference is a A pointer is a variable
variable which refers which stores the address
to another variable. of another variable.
9/19/2024 Dr. ASHISH KUMAR SAHU 54
Control Structures
if ( grade >= 60 )
cout << "Passed";
true
examGrade < 60
false true
quizGrade < 10
case value2:
case value3: // taken if variable == value2 or == value3
statements
break;
false
true
case b case b action(s) break
false
.
.
.
true
case z case z action(s) break
false
default action(s)
• Vary the control variable over the following sequence: 2, 5, 8, 11, 14, 17, 20
• Vary the control variable over the following sequence: 99, 88, 77, 66, 55, 44, 33, 22, 11, 0
false