C++,logical statements and assighnment statement

Post on 24-Jun-2015

563 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

i had made it with hard work so i offer it you because i can feel your feelings text tym i shall upload mora beautiful and comprehensive ppts.

Transcript

Switch statement Logical Statement

Assignment Statement

Computer programmingC++

Instructor

Sir Aamir Jamshid

Crew Members

Azeem Mumtaz Saqib Munawar Hafiz Ashfaq M.Zeeshan Arshad

Logical Statements

AND operatorIt is used to evaluate two conditions .It produces true result if both conditions are

trueIt produces false if any one condition is

falseSymbol: “&&”

Working

Example

Output

Enter the first number1Enter the second number00

OR operatorIt is used to evaluate two conditionsIt produces true if either condition is

true It produces false result if both

conditions are false

Symbol: “| |”

Working

Example

Output

Enter the first number1Enter the second number01

Not Operator

It is the reverses the result of conditionIt gives True if condition is falseIt gives false if condition is trueSymbol: “!”

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

Enter the number8The number is even

Hafiz Ashfaq

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

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

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 ≡ 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

Example

Output

a+b=15

a-b=5

a*b=50

a/b=2

a%b=0

Compound Statement Operator

It combines the assignment statement with arithmetic operator

Syntax: Variable op= expressionVariable: The variable to assign a valueOp: Any arithmetic operatorExpression: It can be a constant, variable

or arithmetic operationExample: N+=10 ~ N=N+10

SAQIB MUNAWAR

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

Example

Nested Switch

top related