ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Sort the given string, without using string handling functions.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
C++ programming I Lab#3 Control Statements Instructor: Eng. Ruba A. Salamah Tuseday: 17/10/2010.
CLASS XI By Sumita Arora
One-Dimensional Arrays. Introduction A one-dimensional array is a sequence of homogenous elements stored in contigous memory locations Motivating example:
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Computer Science Department Relational Operators And Decisions.
DECISIONS In the Name of Allah The Most Merciful The Most Compassionate DECISIONS
LECTURE 11 TYPES OF USER DEFINE FUNCTIONS ITC-414.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
OBJECTIVES  Illustration of the Concept of Control Flow  Types of Control Flow  Knowledge about conditional and repetitive statements.  Make more.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
Chapter 05 (Part III) Control Statements: Part II.
Lecture #7 CONTROL STRUCTURE & FLOW CHARTS
Chapters 1-5 Review C++ Class. Chapter 1 – the big picture Objects Class Inheritance Reusability Polymorphism and Overloading.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Chapter 6.  Control Structures are statements that are used to perform repetitive tasks and to make decisions within a program. Loop repeats a sequence.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
1 Remember: Examination is a chance not ability. By ILTAF MEHDI, IT LECTURER, MIHE, KATR-E-PARWAN BRANCH, KABUL.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Computer Programming Control Structure
Statements
Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
LESSON 2 Basic of C++.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
Lecture #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Lecture 05: Object Oriented Programming:2014 Object-Oriented Programming in C++ Exception.
C++ CODES PART#04 1 COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT.
BY ILTAF MEHDI(MCS,MCSE, CCNA) 1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI(MCS,MCSE, CCNA) 2 Programming Fundamentals Chapter.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Basic concepts of C++ Presented by Prof. Satyajit De
LESSON 2 Basic of C++.
LESSON 4 Decision Control Structure
Decisions Chapter 4.
Engineering Problem Solving with C++, Etter/Ingber
Condition Statements.
Enum ,Char Functions& Math Library Functions I.Mona Alshehri
Intro to Programming Week # 4 Switch Statement Lecture # 7
JUMP STATEMENT C++ has the four statements that perform an unconditional branch. They are, 1. return 2. goto 3. break 4. continue In addition to four statements.
Conditionals & Boolean Expressions
Intro to Programming Week # 5 Repetition Structure Lecture # 9
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Tejalal Choudhary “C Programming from Scratch” Pointers
ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Intro to Programming Week # 3 If-else Statement Lecture # 6
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Điều kiện Chương 5.
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Selection Control Structure: Switch Case Statement
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Fundamental Programming
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
CPP Programming Language
ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Control Structures contd… Selection
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
CSCE 206 Lab Structured Programming in C
Programming Fundamental-1
Presentation transcript:

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