COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT C++ CODES PART#07 COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue… if(a>100) cout<<"that number is greater than 100\n"; getch();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output…. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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) COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue… {cout<<"the number "<<a; cout<<"is greater than 100\n"; } getch();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT OUTPUT…. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT If else statement #include<constream.h> void main() { clrscr(); int x; cout<<"\n enter a number:"; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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(); } COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output…. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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:"; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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(); } COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output………. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Switch () statement #include<constream.h> void main () {clrscr(); char ch; cin>>ch; switch(ch){ case 'a': COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue… case 'e': case 'i': case 'o': case 'u': cout<<"vowel"; default:cout<<" alphabet";} getch();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output… COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output….. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Example of switch statement using ctype.h #include <constream.h> #include <ctype.h> void main() { clrscr(); char ch; cout << "Enter Any Alphabat !"; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue… ch = getche(); if(isalpha(ch)) { ch = toupper(ch); switch(ch) { case 'A': case 'E': COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue.. case 'I': case 'O': case 'U': cout <<"\nThis is a vowel"; break; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue… default: cout <<"\nThis is a consonant"; } else cout <<"\nInvalid Entry"; getch(); COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output… COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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')) COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue…. {cout<<endl<<"vowel";} else cout<<endl<<"consonant"; getch();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output…. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Continue statement #include<constream.h> void main() {clrscr(); long dividend,divisor; char ch; do{ COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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"; COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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();} COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT Output…. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
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. COPYRIGHT@ ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT