SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Welcome again
Presented By: Ahmed Nobi ;
Ahmed nobi
- Android developer with one year experience
- Android Developer at Cleodev software House.
- programming instructor with three year experience in Luxor and Aswan.
- working on online course (programming school)
- former chair IEEE Aswan SB
- Ex Vice Student representative IEEE Egypt Section
contact me:
LinkedIn: www.linkedin.com/in/ahmed-nobi
Facebook: www.facebook.com/Ahmed.Nobi.Eltwins
mail: ahmed.nobi95@gmail.com
Brief about me
Course’s outline
• Variables
• Data type
• Operators
• Selection
• Loop
• Arrays
• Functions
Session’s outline today
• Variables
• Data type
• Operators
• Selection
Structure of a C++ Program
Hello World++
// Hello World program
#include <iostream>
Using namespace std;
int main() {
cout << "Hello Worldn";
return 0;
}
comment
Allows access to an I/O
library
output (print) a
string
Program returns a status
code (0 means OK)
Starts definition of special function
main()
Some common includes
 Basic I/O: iostream.h
 I/O manipulation: iomanip.h
 Standard Library: stdlib.h
 Time and Date support: time.h
Variables/ constants
Variables are just names for locations in memory.
• Variables are just names for locations in memory.
• In C++ all variables must have a type (not all languages require this).
• In C++ all variables must be declared before they can be used.
Data type var_name;
• Sometimes, it is just convenient to give a name to a constant value
Const Data type var_name= value;
Variable Names
How to name you variables ?
C++ variable naming Rules:
 made up of letters, digits and underscore.
 Must start with a non-digit.
 Case sensitive
a is not the same name as A
 Can be any length
 Good variable names tell the reader what the
variable is used for!
Data type
data type indicate what is the type of variables
Data type (cont.)
Common data type which will we use
• int for integer numbers ex 1 ,2 ,4, 77
• double for real numbers ex 1.77 , 55.8845
• char for characters ex A ,b , e
• bool for Boolean values ex true , false
operators
• Athematic (math)
• Relational
• logical
Mathematical Operators
+ - * / %
 Operators have rules of precedence and associativity that control how
expressions are evaluated.
 What is the value of this C++ expression ?:
2 / 3 / 4 + 5
 Answer: You can't tell unless you know the rules.
C++ Math Operator Rules
Operator Associativity Precedence
() left to right high
* / % left to right middle
+ - left to right low
 Now - what is the value of this?:
2 / 3 / 4 + 5
 How about this: (7*3/4-2)*5
Relational and Equality Operators
Relational and Equality operators are used to
compare values:
 Relational Operators:
> Greater than
>= Greater than or equal
< Less than
<= Less than or equal
 Equality Operators:
== Equal to
!= Not Equal to
Logical operators
Category Operator Associativity
LogicalAND && Left to right
LogicalOR || Left to right
Logical Not ! Right to left
I/O • Cin >> to read data
• Cout << to write data or display on
secreen
• Cerr << for error msg
examples • Write a program to sum two numbers
• Write a program to calculate the area of circle
Output format
That helps you to format your output.
Escape Sequence Description
• n Newline. Position the screen cursor to the beginning of the next line.
• t Horizontal tab. Move the screen cursor to the next tab stop
• a Alert. Sound the system bell
•  Backslash.Used to print a backs lash character
• “ Double quote. Used to print a double quote character
Blocks and its
importance
• We can make a block in code by { } to put limits for
executed lines and when we need it to execute
• For example : the main block of main function
• Block of output response for if statement
Selection
• The condition expression of the if statement must be within parentheses. If it is true, the statement
immediately following the if statement is executed
ex: if (cond.) what you need to do
• If multiple statements must be executed, they must be enclosed in curly braces following the if
statement (this is called a statement block):
ex: if (cond.)
{ // begins statement block
what you need to do
} // ends statement block
• The if statement also supports an else clause.An else clause represents one or a block of
statements to be executed if the tested condition is false. For example,
Ex : if (cond.)
{
// user guessed correctly
}
else
{
// user guessed incorrectly
}
• A second use of the else clause is to string together two or more if statements. For example, if the user guesses
incorrectly, we want our response to differ based on the number of guesses. We could write the three tests as
independent if statements:
If (num_tries == 1) cout << "Oops! Nice guess but not quite it.n";
if (num_tries == 2) cout << "Hmm. Sorry. Wrong a second time.n";
if (num_tries == 3) cout << "Ah, this is harder than it looks, isn't
it?n";
• However, only one of the three conditions can be true at any one time. If one of the if statements is true, the others
must be false. We can reflect the relationship among the if statements by stringing them together with a series of
else-if clauses:
if (num_tries == 1)
cout << "Oops! Nice guess but not quite it.n";
else if (num_tries == 2)
cout << "Hmm. Sorry. Wrong again.n";
else if (num_tries == 3)
cout << "Ah, this is harder than it looks, isn't it?n";
else
cout << "It must be getting pretty frustrating by now!n";
• One confusing aspect of nested if-else clauses is the difficulty of organizing their logic correctly. For example,
EX if (usr_guess == next_elem)
{
// user guessed correctly
}
else
{
if (num_tries == 1)
// ... output response
else if (num_tries == 2)
// ... output response
else if (num_tries == 3)
// ... output response
else
// ... output response
}
Briefly:
If (conditional statement )
{
If (conditional statement )
{
output response
}
}
Now let us try to use { }
Modify the following code to produce the output shown. You must not
make any changes other than inserting braces. The compiler ignores
indentation in a C++ program. We eliminated the indentation from the
following code to make the problem more challenging.
a) Assuming x = 5 and y = 8, the following output is produced. @@@@@ $$$$$
&&&&&
b) Assuming x = 5 and y = 8, the following output is produced. @@@@@
c) Assuming x = 5 and y = 8, the following output is produced. @@@@@
&&&&&
d) Assuming x = 5 and y = 7, the following output is produced. [Note: The last
three output statements after the else are all part of a block.] #####
$$$$$ &&&&&
if ( y == 8 )
if ( x == 5 )
cout << "@@@@@" << endl;
else
cout << "#####" << endl;
cout << "$$$$$" << endl;
cout << "&&&&&" << endl;
a) Assuming x = 5 and y = 8, the following output is produced. @@@@@ $$$$$ &&&&&
b) Assuming x = 5 and y = 8, the following output is produced. @@@@@
c) Assuming x = 5 and y = 8, the following output is produced. @@@@@ &&&&&
d) Assuming x = 5 and y = 7, the following output is produced. [Note: The last three output
statements after the else are all part of a block.] ##### $$$$$ &&&&&
if ( y == 8 )
if ( x == 5 )
cout << "@@@@@" << endl;
else
cout << "#####" << endl;
cout << "$$$$$" << endl;
cout << "&&&&&" << endl;
Summary
• Simple if
If ( cond. ) executable statement
• If with block
If ( cond. ) { executable statements }
• If else with block
If ( cond. ) { executable statements }
Else
{
executable statements }
• If with else if
If (cond) {executable statements }
Else ifv
{executable statements }
Else {executable statements }

Weitere ähnliche Inhalte

Was ist angesagt?

Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and AssociativityNicole Ynne Estabillo
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control StructuresLasithNiro
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3Munsif Ullah
 
Operators
OperatorsOperators
OperatorsKamran
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statementEyelean xilef
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8MuhammadAtif231
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vballdesign
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - SelectionMichael Heron
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsShameer Ahmed Koya
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityAakash Singh
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsShameer Ahmed Koya
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++zeeshan turi
 

Was ist angesagt? (20)

Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and Associativity
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Operators
OperatorsOperators
Operators
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Variable, constant, operators and control statement
Variable, constant, operators and control statementVariable, constant, operators and control statement
Variable, constant, operators and control statement
 
Operators In Java Part - 8
Operators In Java Part - 8Operators In Java Part - 8
Operators In Java Part - 8
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Python : Operators
Python : OperatorsPython : Operators
Python : Operators
 
Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vb
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB Scripts
 
Control Structures: Part 1
Control Structures: Part 1Control Structures: Part 1
Control Structures: Part 1
 
Ch03
Ch03Ch03
Ch03
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
MATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output CommandsMATLAB programming tips 2 - Input and Output Commands
MATLAB programming tips 2 - Input and Output Commands
 
Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++
 

Ähnlich wie c++ Data Types and Selection

Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsJames Brotsos
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptMahyuddin8
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptghoitsun
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operatorsmcollison
 
java basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arraysjava basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arraysmellosuji
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 
Understanding F# Workflows
Understanding F# WorkflowsUnderstanding F# Workflows
Understanding F# Workflowsmdlm
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jamJamaicaAubreyUnite
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptxVAIBHAVKADAGANCHI
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBasil Bibi
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Ahmad Bashar Eter
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview QuestionsGradeup
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptxMattMarino13
 
C++.pptx
C++.pptxC++.pptx
C++.pptxSabi995708
 

Ähnlich wie c++ Data Types and Selection (20)

Ch02 primitive-data-definite-loops
Ch02 primitive-data-definite-loopsCh02 primitive-data-definite-loops
Ch02 primitive-data-definite-loops
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
 
Pi j1.3 operators
Pi j1.3 operatorsPi j1.3 operators
Pi j1.3 operators
 
java basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arraysjava basics - keywords, statements data types and arrays
java basics - keywords, statements data types and arrays
 
Arrays
ArraysArrays
Arrays
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
Understanding F# Workflows
Understanding F# WorkflowsUnderstanding F# Workflows
Understanding F# Workflows
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
Brixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 RecapBrixton Library Technology Initiative Week1 Recap
Brixton Library Technology Initiative Week1 Recap
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1Acm aleppo cpc training introduction 1
Acm aleppo cpc training introduction 1
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 

KĂźrzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

KĂźrzlich hochgeladen (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

c++ Data Types and Selection

  • 2. Ahmed nobi - Android developer with one year experience - Android Developer at Cleodev software House. - programming instructor with three year experience in Luxor and Aswan. - working on online course (programming school) - former chair IEEE Aswan SB - Ex Vice Student representative IEEE Egypt Section contact me: LinkedIn: www.linkedin.com/in/ahmed-nobi Facebook: www.facebook.com/Ahmed.Nobi.Eltwins mail: ahmed.nobi95@gmail.com Brief about me
  • 3. Course’s outline • Variables • Data type • Operators • Selection • Loop • Arrays • Functions Session’s outline today • Variables • Data type • Operators • Selection
  • 4. Structure of a C++ Program Hello World++ // Hello World program #include <iostream> Using namespace std; int main() { cout << "Hello Worldn"; return 0; } comment Allows access to an I/O library output (print) a string Program returns a status code (0 means OK) Starts definition of special function main() Some common includes  Basic I/O: iostream.h  I/O manipulation: iomanip.h  Standard Library: stdlib.h  Time and Date support: time.h
  • 5. Variables/ constants Variables are just names for locations in memory. • Variables are just names for locations in memory. • In C++ all variables must have a type (not all languages require this). • In C++ all variables must be declared before they can be used. Data type var_name; • Sometimes, it is just convenient to give a name to a constant value Const Data type var_name= value;
  • 6. Variable Names How to name you variables ? C++ variable naming Rules:  made up of letters, digits and underscore.  Must start with a non-digit.  Case sensitive a is not the same name as A  Can be any length  Good variable names tell the reader what the variable is used for!
  • 7. Data type data type indicate what is the type of variables
  • 8. Data type (cont.) Common data type which will we use • int for integer numbers ex 1 ,2 ,4, 77 • double for real numbers ex 1.77 , 55.8845 • char for characters ex A ,b , e • bool for Boolean values ex true , false
  • 9. operators • Athematic (math) • Relational • logical
  • 10. Mathematical Operators + - * / %  Operators have rules of precedence and associativity that control how expressions are evaluated.  What is the value of this C++ expression ?: 2 / 3 / 4 + 5  Answer: You can't tell unless you know the rules.
  • 11. C++ Math Operator Rules Operator Associativity Precedence () left to right high * / % left to right middle + - left to right low  Now - what is the value of this?: 2 / 3 / 4 + 5  How about this: (7*3/4-2)*5
  • 12. Relational and Equality Operators Relational and Equality operators are used to compare values:  Relational Operators: > Greater than >= Greater than or equal < Less than <= Less than or equal  Equality Operators: == Equal to != Not Equal to
  • 13. Logical operators Category Operator Associativity LogicalAND && Left to right LogicalOR || Left to right Logical Not ! Right to left
  • 14. I/O • Cin >> to read data • Cout << to write data or display on secreen • Cerr << for error msg
  • 15. examples • Write a program to sum two numbers • Write a program to calculate the area of circle
  • 16. Output format That helps you to format your output. Escape Sequence Description • n Newline. Position the screen cursor to the beginning of the next line. • t Horizontal tab. Move the screen cursor to the next tab stop • a Alert. Sound the system bell • Backslash.Used to print a backs lash character • “ Double quote. Used to print a double quote character
  • 17. Blocks and its importance • We can make a block in code by { } to put limits for executed lines and when we need it to execute • For example : the main block of main function • Block of output response for if statement
  • 18. Selection • The condition expression of the if statement must be within parentheses. If it is true, the statement immediately following the if statement is executed ex: if (cond.) what you need to do • If multiple statements must be executed, they must be enclosed in curly braces following the if statement (this is called a statement block): ex: if (cond.) { // begins statement block what you need to do } // ends statement block
  • 19. • The if statement also supports an else clause.An else clause represents one or a block of statements to be executed if the tested condition is false. For example, Ex : if (cond.) { // user guessed correctly } else { // user guessed incorrectly }
  • 20. • A second use of the else clause is to string together two or more if statements. For example, if the user guesses incorrectly, we want our response to differ based on the number of guesses. We could write the three tests as independent if statements: If (num_tries == 1) cout << "Oops! Nice guess but not quite it.n"; if (num_tries == 2) cout << "Hmm. Sorry. Wrong a second time.n"; if (num_tries == 3) cout << "Ah, this is harder than it looks, isn't it?n"; • However, only one of the three conditions can be true at any one time. If one of the if statements is true, the others must be false. We can reflect the relationship among the if statements by stringing them together with a series of else-if clauses: if (num_tries == 1) cout << "Oops! Nice guess but not quite it.n"; else if (num_tries == 2) cout << "Hmm. Sorry. Wrong again.n"; else if (num_tries == 3) cout << "Ah, this is harder than it looks, isn't it?n"; else cout << "It must be getting pretty frustrating by now!n";
  • 21. • One confusing aspect of nested if-else clauses is the difficulty of organizing their logic correctly. For example, EX if (usr_guess == next_elem) { // user guessed correctly } else { if (num_tries == 1) // ... output response else if (num_tries == 2) // ... output response else if (num_tries == 3) // ... output response else // ... output response } Briefly: If (conditional statement ) { If (conditional statement ) { output response } }
  • 22. Now let us try to use { } Modify the following code to produce the output shown. You must not make any changes other than inserting braces. The compiler ignores indentation in a C++ program. We eliminated the indentation from the following code to make the problem more challenging. a) Assuming x = 5 and y = 8, the following output is produced. @@@@@ $$$$$ &&&&& b) Assuming x = 5 and y = 8, the following output is produced. @@@@@ c) Assuming x = 5 and y = 8, the following output is produced. @@@@@ &&&&& d) Assuming x = 5 and y = 7, the following output is produced. [Note: The last three output statements after the else are all part of a block.] ##### $$$$$ &&&&& if ( y == 8 ) if ( x == 5 ) cout << "@@@@@" << endl; else cout << "#####" << endl; cout << "$$$$$" << endl; cout << "&&&&&" << endl;
  • 23. a) Assuming x = 5 and y = 8, the following output is produced. @@@@@ $$$$$ &&&&& b) Assuming x = 5 and y = 8, the following output is produced. @@@@@ c) Assuming x = 5 and y = 8, the following output is produced. @@@@@ &&&&& d) Assuming x = 5 and y = 7, the following output is produced. [Note: The last three output statements after the else are all part of a block.] ##### $$$$$ &&&&& if ( y == 8 ) if ( x == 5 ) cout << "@@@@@" << endl; else cout << "#####" << endl; cout << "$$$$$" << endl; cout << "&&&&&" << endl;
  • 24. Summary • Simple if If ( cond. ) executable statement • If with block If ( cond. ) { executable statements } • If else with block If ( cond. ) { executable statements } Else { executable statements } • If with else if If (cond) {executable statements } Else ifv {executable statements } Else {executable statements }