C++,logical statement and assignment statement

Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Switch statement Logical Statement Assignment Statement :

Switch statement Logical Statement Assignment Statement Computer programming C++

Instructor:

Instructor Sir Aamir Jamshid

Crew Members:

Crew Members Azeem Mumtaz Saqib Munawar Hafiz Ashfaq M.Zeeshan Arshad

Logical Statements:

Logical Statements AND operator It is used to evaluate two conditions . It produces true result if both conditions are true It produces false if any one condition is false Symbol: “&&”

Working:

Working

Example:

Example

Output:

Output Enter the first number 1 Enter the second number 0 0

Slide 10:

OR operator It is used to evaluate two conditions It produces true if either condition is true It produces false result if both conditions are false Symbol: “| |”

Working:

Working

Example:

Example

Output :

Output Enter the first number 1 Enter the second number 0 1

Not Operator:

Not Operator It is the reverses the result of condition It gives True if condition is false It gives false if condition is true Symbol: “!”

Example:

Example ≡ File Edit Search Run Compile Debug Project Options Window Help ╔═[■]════════════════════════════ NONAME00.CPP ══════════════════════════1═[↑]═╗ ║#include< iostream.h > ▲ ║#include< conio.h > ■ ║void main() ▒ ║{ ▒ ║ clrscr (); ▒ ║ int a; ▒ ║ cout <<"Enter the number"<< endl ; ▒ ║ cin >>a; ▒ ║if(a%2!=0) ▒ ║ cout <<"the number is odd"; ▒ ║else ▒ ║ cout <<"the number is even"; ▒ ║ getch (); ▒ ║} ▼ ╚═☼════ 14:3 ═════◄■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒►─┘ ┌────────────────────────────────── Message ─────────────────────────────2─────┐ │•Compiling NONAME00.CPP: │ │ Linking TCDEF.EXE: │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────────┘ F1 Help Alt-F8 Next Msg Alt-F7 Prev Msg Alt-F9 Compile F9 Make F10 Menu

Output:

Output Enter the number 8 The number is even

Hafiz Ashfaq:

Hafiz Ashfaq

Assignment Statement :

Assignment Statement A statement that assigns a value to a variable is known as assignment statement. The assignment =is used in assignment statement to assign a value or computational result to a variable. The name of variable is written on the left side of assignment operator and the value is written on the right side. The value can be a constant ,variable ,expression or a function.

Syntax :

Syntax Variable=Expression Examples A=100; C= a+b ; X=c-d+10;

LVALUE & RVALUE:

LVALUE & RVALUE An L value is an operand that can be written on the left side of assignment operator=it must always be a single value. An rvalue is an operand that can be written on the right side of assignment statement=. All Lvaues can be used as Rvalues .

Example:

Example ≡ File Edit Search Run Compile Debug Project Options Window Help ╔═[■]════════════════════════════ NONAME00.CPP ══════════════════════════1═[↑]═╗ ║#include< iostream.h > ▲ ║#include< conio.h > ■ ║void main() ▒ ║{ clrscr (); ▒ ║ int a,b ; ▒ ║a=10; ▒ ║b=5; ▒ ║ cout <<" a+b ="<< a+b << endl ; ▒ ║ cout <<"a-b="<<a-b<< endl ; ▒ ║ cout <<"a*b="<<a*b<< endl ; ▒ ║ cout <<"a/b="<<a/b<< endl ; ▒ ║ cout <<" a%b ="<< a%b << endl ; ▒ ║ getch (); ▒ ║} ▼ ╚═☼════ 14:2 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒►─┘ ┌────────────────────────────────── Message ─────────────────────────────2─────┐ │•Compiling NONAME00.CPP: │ │ Linking NONAME00.EXE: │ │ │ │ │ │ │ └──────────────────────────────────────────────────────────────────────────────┘ F1 Help Alt-F8 Next Msg Alt-F7 Prev Msg Alt-F9 Compile F9 Make F10 Menu

M.Zeeshan Arshad:

M.Zeeshan Arshad

Example:

Example

Output:

Output a+b =15 a-b=5 a*b=50 a/b=2 a%b =0

Compound Statement Operator:

Compound Statement Operator It combines the assignment statement with arithmetic operator Syntax: Variable op= expression Variable: The variable to assign a value Op: Any arithmetic operator Expression: It can be a constant, variable or arithmetic operation Example: N+=10 ~ N=N+10

Saqib munawar:

Saqib munawar

Switch Statement:

Switch Statement It is a conditional structure It is an alternative of “nested if” It is used when there are many choices are available and we need one to be executed

Syntax:

Syntax

Example:

Example

Nested Switch:

Nested Switch