>a; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT"> >a; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT">
Download presentation
Presentation is loading. Please wait.
Published byĒΔανιήλ Ηλιόπουλος Modified over 5 years ago
1
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
C++ CODES PART#07 ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
2
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
USING IF STATEMENT #include<constream.h> void main() {clrscr(); int a; cout<<"input a number:"; cin>>a; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
3
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… if(a>100) cout<<"that number is greater than 100\n"; getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
4
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output…. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
5
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Using if statement #include<constream.h> void main() {clrscr(); int a; cout<<"enter a number:"; cin>>a; if(a>100) ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
6
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… {cout<<"the number "<<a; cout<<"is greater than 100\n"; } getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
7
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
OUTPUT…. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
8
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
If else statement #include<constream.h> void main() { clrscr(); int x; cout<<"\n enter a number:"; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
9
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… cin>>x; if(x>100) cout<<"that number is greater than 100\n"; else cout<<"that number is not greater than 100\n"; getch(); } ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
10
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output…. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
11
Using library function exit()
#include<constream.h> #include<process.h>// used for exit() void main() {clrscr(); int a,b; cout<<"\n enter any integer values of a and b:"; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
12
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue…. cin>>a>>b; clrscr(); if(a%b==0) cout<<a<<"is proper divisible of"<<b; else exit(0); getch(); } ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
13
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output………. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
14
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Switch () statement #include<constream.h> void main () {clrscr(); char ch; cin>>ch; switch(ch){ case 'a': ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
15
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… case 'e': case 'i': case 'o': case 'u': cout<<"vowel"; default:cout<<" alphabet";} getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
16
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output… ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
17
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Conditional operator #include<constream.h> void main() {clrscr(); float per; cout<<"\enter the obtained percentage:"; cin>>per; cout<<(per>=60?"\n pass":"\nfail"); getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
18
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output….. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
19
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
ctype.h Character handling This header declares a set of functions to classify and transform individual characters. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
20
Example of switch statement using ctype.h
#include <constream.h> #include <ctype.h> void main() { clrscr(); char ch; cout << "Enter Any Alphabat !"; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
21
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… ch = getche(); if(isalpha(ch)) { ch = toupper(ch); switch(ch) { case 'A': case 'E': ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
22
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue.. case 'I': case 'O': case 'U': cout <<"\nThis is a vowel"; break; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
23
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue… default: cout <<"\nThis is a consonant"; } else cout <<"\nInvalid Entry"; getch(); ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
24
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output… ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
25
Logical OR oerator (||)
#include<constream.h> void main() {char a; clrscr(); cin>>a; if(a==int('a')||a==int('e')||a==int('i')||a==int('0')||a==int('u')) ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
26
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue…. {cout<<endl<<"vowel";} else cout<<endl<<"consonant"; getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
27
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output…. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
28
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Continue statement #include<constream.h> void main() {clrscr(); long dividend,divisor; char ch; do{ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
29
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
CONTINUE…. cout<<"enter dividend:"; cin>>dividend; cout<<"enter divisor:"; cin>>divisor; if(divisor==0) {cout<<"illegal divisor \n"; ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
30
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
CONTINUE… continue; } cout<<"quotient is"<<dividend/divisor; cout<<",remainder is"<<dividend%divisor; cout<<"\n do another?(y/n):"; cin>>ch; while(ch!='n'); getch();} ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
31
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Output…. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
32
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
NICE WORDINGS…….. Jab Tum dunya ki Muflisi se tang aa jao aur Rizaq ka koi rasta na niklay to Sadqa day ker Allah se tajaarat kiya kero. ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.