SlideShare a Scribd company logo
1 of 36
Created By:
IEEE MIU SB Academic Committee
Arduino Workshop
1
PART 4: PROGRAMING 101
2
Content
 What is Programing?
 What is a Programing Language?
 How do Computers Understand Us?
 Machine Language
 Low Level Languages
 High Level Languages
 Compilation Process
 Integrated Development Environment
(IDE)
 Code::Blocks IDE
 Install Code Blocks & Start First Project
 Variables
 Variable Naming Guidelines
 Data Types
 Variable Declaration & Initialization
 Output Statement
 Input Statement
 if…else Statement
 Nested if statement
 Switch…case
 Prefix VS Postfix
 While Loop
 Program Errors
 Tasks 3
What is Programing?
 it’s a method that allows you to
write specific commands with a
certain programing language which
enables you create & run
applications.
 Example: Web Development, Games
Development, Mobile App
Development, ….etc.
4
What is a Programing Language?
 Programing language is like our
English language it has a grammar
that we should follow which is
called syntax and for each
programing language it has it’s
own syntax rules.
5
How do Computers Understand Us?
 Computers can not use human languages, and programming in the
binary language of computers is a very difficult.
 Therefore, all programs are written using a programming language
which is then converted to Binary Code for the machine to
understand.
 Due to this revolution; a lot of programing languages were created
each with a different generic purpose in mind.
6
Machine Language
 Natural language of a particular
computer.
 Primitive instructions built into every
computer.
 The instructions are in the form of
binary code.
 Any other types of languages must be
translated down to this level.
7
Machine Language
(Binary Code)
Low Level Languages
 English-like Abbreviations used for operations (Load R1, R8).
 Assembly languages were developed to make programming easier.
8
Low level language
(Assembly Code)
High Level Languages
 English-like and easy to learn and program.
 Common mathematical notation
 Ex: Java, C, C++, FORTRAN, VISUAL BASIC,
PASCAL, ….etc
9
High level
language
(C++,java)
Compilation Process
10
High Level
Language
(C++,java)
Low Level
Language
(Assembly)
Machine Language
(Binary Code)
Integrated Development Environment
(IDE)
 An integrated development
environment (IDE) is a software
application that provides
comprehensive facilities to
computer programmers for
software development.
 An IDE normally consists of a
source code editor, build
automation tools, and a
debugger.
 An IDE consists of:
 Text Editor.
 GUI (Graphical User Interface).
 Tool-Chain:
1. Pre-Compiler.
2. Compiler.
3. Linker.
4. Assembler.
5. Debugger.
11
Code::Blocks IDE
 Code::Blocks is a free C, C++ and Fortran IDE built to meet the most
demanding needs of its users.
 It is designed to be very extensible and fully configurable.
12
Install Code::Blocks & Start 1st Project
13
Variables (1/2)
 Variables are used to store information to be referenced and
manipulated in a computer program.
 They provide a way of labeling data with a descriptive name, so our
programs can be understood more clearly by the reader and ourselves.
Their sole purpose is to label and store data in memory. This data can
then be used throughout your program.
14
Variables (2/2)
 It is helpful to think of variables as
containers that hold information.
15
Variable Naming Guidelines
16
Declaration:
Initialization:
We can use underscores and capital
letters in a variable name
Can’t use: keywords, just numbers,
spaces, or special characters ($, &, !,
etc)
Data Types (1/2)
17
Data types
Primitive types
Integer
Float
Character
Boolean
Non-primitive
types
Arrays
Strings
Data type Size Use Example
int 2 bytes Used to hold positive
and negative whole
numbers
1453
float 4 bytes Used to hold fractional
or decimal values
7.54
char 1 byte Used to hold individual
characters
‘A’
boolean 1 byte Used for logic; true or
false
true
Data Types (2/2)
 Every variable must have two things: a data type and a name.
 Defines the kind of data the variable can hold.
 For example, can this variable hold numbers? Can it hold text?
18
Variable Declaration & Initialization
type variable-name = value;
Meaning: variable <variable-name> will be a variable of type <type> and is initialized with value
<value>
Where type can be:
 int //integer
 double //real number
 char //character
Example:
int sum; //Variable Declaration
sum =1; // Variable Initialization
double x = 5.6; // Variable is declared and initialized
int a, b, c; // Multiple Variable Declarations
char my-character;
19
data type identifier
semi-colon
Output Statement
20
 2 // Printing a line with multiple statements.
 3 #include <iostream>
 4 using namespace std;
 5 // function main begins program execution
 6 int main()
 7 {
 8 cout << "Welcome ";
 9 cout << "to C++!n";
 10 cout << "Welcome” << endl;
 11 cout << "tonnC++!n";
 12
 13 return 0; // indicate that program ended successfully
 14 } // end function main
Welcome to C++!
Welcome
to
C++!
Input Statement
21
 1 #include <iostream>
 2 using namespace std;
 3 // function main begins program execution
 4 int main()
 5 {
 6 int integer1; // first number to be input by user
 7 int integer2; // second number to be input by user
 8 int sum; // variable in which sum will be stored
 9 cout << "Enter first integern"; // prompt
 10 cin >> integer1; // read an integer
 11 cout << "Enter second integern"; // prompt
 12 cin >> integer2; // read an integer
 13 sum = integer1 + integer2; // assign result to sum
 14 cout << "Sum is " << sum << endl; // print sum
 15 return 0; // indicate that program ended successfully
 16
 17 } // end function main
Enter first integer
45
Enter second integer
72
Sum is 117
if…else Statement (1/5)
22
if (Condition) {
S1;
}
else if(Condition){
S2;
}
else{
S3;
}
if…else Statement (2/5)
 Comparison operators
== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
 Boolean operators
&& and
|| or
! not
23
if…else Statement (3/5)
 Assume we declared the following variables:
int a = 2, b=5, c=10;
 Here are some examples of Boolean conditions we can use:
 if (a == b)
 if (a != b)
 if (a >= b)
 if(a <= b)
 if(a < b) && (a > c)
 if(a == b) || (a == c)
24
if…else Statement (4/5)
25
 1 // Using if statements, relational
 2 // operators, and equality operators.
 3 #include <iostream>
 4 using namespace std;
 5 // function main begins program execution
 6 int main()
 7 {
 8 int num1; // first number to be read from user
 9 int num2; // second number to be read from user
 10
 11 cout << "Enter two integers, and I will tell youn"
 12 << "the relationships they satisfy: ";
 13 cin >> num1 >> num2; // read two integers
 14
 15 if ( num1 == num2 )
 16 cout << num1 << " is equal to " << num2 << endl;
 17
 18 if ( num1 != num2 )
 19 cout << num1 << " is not equal to " << num2 << endl;
if…else Statement (5/5)
26
 20 if ( num1 < num2 )
 21 cout << num1 << " is less than " << num2 << endl;
 22
 23 if ( num1 > num2 )
 24 cout << num1 << " is greater than " << num2 << endl;
 25
 26 if ( num1 <= num2 )
 27 cout << num1 << " is less than or equal to "
 28 << num2 << endl;
 29
 30 if ( num1 >= num2 )
 31 cout << num1 << " is greater than or equal to "
 32 << num2 << endl;
 33
 34 return 0; // indicate that program ended successfully
 35
 36 } // end function main
Enter two integers, and I will tell you
the relationships they satisfy: 22 12
22 is not equal to 12
22 is greater than 12
22 is greater than or equal to 12
Nested if Statement
27
Switch…Case (1/4)
 Often you want to do a series of tests:
 if i==0 … else if i==1 …. else if i==2 … else if i==3 ….
 C++ provides the switch statement to help in this situation
 It allows you to specify a large set of cases you want to be able to match,
yet works efficiently to find and execute the particular case matched.
28
Switch…Case (2/4)
29
switch (expression) {
case
constant_expression:
statements;
break;
case
constant_expression:
statements;
break;
default:
statements;
}
Switch…Case (3/4)
30
 1 #include <iostream>
 2 using namespace std;
 3 // function main begins program execution
 4 int main()
 5 {
 6 cout << “Enter simple expression:” ; // first number to be input by user
 7 int left; // second number to be input by user
 8 int right; // variable in which sum will be stored
 9 char operator; // prompt
 10 cin >> left >> operator >> right; // read an integer
 11 cout << left<< “ “<< operator<< “” << right<< “ = “; // prompt
 12 switch (operator) { // read an integer
 13 case ‘+’ : cout << left + right <<endl; break;// assign result to sum
 14 case ‘-’ : cout << left - right <<endl; break;//
 15 case ‘*’ : cout << left * right <<endl; break;//
 16 case ‘/’ : cout << left / right <<endl; break;//
 17 default: cout << “Illegal operation”” <<endl;
 18 return 0; // indicate that program ended successfully
 19
 20 } // end function main
Enter simple expression:
4
+
5
4 + 5 = 9
Switch…Case (4/4)
 Notes:
 Unless you have many conditions (4 or more), use if-else-if instead of
switch.
 Always provide a default case – if you are pretty sure you have all cases
covered, putting an error message in the default is good to identify
unexpected errors.
 Order the cases in some logical order (numeric, alphabetic).
31
Prefix VS Postfix
 Increment then use the variable
 Sum = ++count
 Use the variable then increment
 Sum = count++
32
count
10
11
sum
0
11
Before
After
count
10
11
sum
0
10
Before
After
While Loop (1/2)
33
while (condition) {
S1;
condition
(incrementation/decrementation);
}
S2;
While Loop (2/2)
//read 100 numbers from the user and output their sum
#include <iostream.h>
void main() {
int i, sum, x;
sum=0;
i=1;
while (i <= 100) {
cin >> x;
sum = sum + x;
i = i+1;
}
cout << “sum is “ << sum << endl;
}
34
Program Errors
35
 Syntax Errors:
 Errors in grammar of the language.
 Runtime error:
 When there are no syntax errors, but the program can’t complete
execution:
 Divide by zero.
 Invalid input data.
 Logical errors:
 The program completes execution, but delivers incorrect results.
 Incorrect usage of parentheses.
Tasks
 Write a program that takes 3 integer numbers from the user & outputs the
greatest integer number without using any conditional statements.
 Write a program that performs a swapping code without using a temporary
variable.
 Output a pyramid shape of asterisks “*”. (Hint: Use cout + Loops + if
statement)
 Make a Calculator using C++ Code on Code::Blocks.
36

More Related Content

What's hot

Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devicesandy_s_king
 
Chapter01Introducing Hardware
Chapter01Introducing HardwareChapter01Introducing Hardware
Chapter01Introducing HardwarePatty Ramsey
 
Personālā datora svarīgākās ierīces, to funkcijas
Personālā datora svarīgākās ierīces, to funkcijasPersonālā datora svarīgākās ierīces, to funkcijas
Personālā datora svarīgākās ierīces, to funkcijasSanta T
 
Introduction to Computer System
Introduction to Computer System Introduction to Computer System
Introduction to Computer System sonykhan3
 
Ibm aix technical deep dive workshop advanced administration and problem dete...
Ibm aix technical deep dive workshop advanced administration and problem dete...Ibm aix technical deep dive workshop advanced administration and problem dete...
Ibm aix technical deep dive workshop advanced administration and problem dete...solarisyougood
 
Processors and its Types
Processors and its TypesProcessors and its Types
Processors and its TypesNimrah Shahbaz
 
Introduction to Computing - Essentials of Technology - Day 1
Introduction to Computing -  Essentials of Technology - Day 1Introduction to Computing -  Essentials of Technology - Day 1
Introduction to Computing - Essentials of Technology - Day 1Mark John Lado, MIT
 
Basic Features of MS Word 2016.pptx
Basic Features of MS Word 2016.pptxBasic Features of MS Word 2016.pptx
Basic Features of MS Word 2016.pptxmhavzgreda1
 

What's hot (20)

Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devices
 
Intro to Computers
Intro to ComputersIntro to Computers
Intro to Computers
 
Computer Essentials
Computer EssentialsComputer Essentials
Computer Essentials
 
Computer software
Computer softwareComputer software
Computer software
 
Chapter01Introducing Hardware
Chapter01Introducing HardwareChapter01Introducing Hardware
Chapter01Introducing Hardware
 
Word 2016
Word 2016Word 2016
Word 2016
 
Laptop Basic Knowledge
Laptop Basic KnowledgeLaptop Basic Knowledge
Laptop Basic Knowledge
 
Personālā datora svarīgākās ierīces, to funkcijas
Personālā datora svarīgākās ierīces, to funkcijasPersonālā datora svarīgākās ierīces, to funkcijas
Personālā datora svarīgākās ierīces, to funkcijas
 
Introduction to Computer System
Introduction to Computer System Introduction to Computer System
Introduction to Computer System
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
Chapter 8: Tables
Chapter 8: TablesChapter 8: Tables
Chapter 8: Tables
 
Harware ppt
Harware pptHarware ppt
Harware ppt
 
Ibm aix technical deep dive workshop advanced administration and problem dete...
Ibm aix technical deep dive workshop advanced administration and problem dete...Ibm aix technical deep dive workshop advanced administration and problem dete...
Ibm aix technical deep dive workshop advanced administration and problem dete...
 
Ports
PortsPorts
Ports
 
Computer hardware and its components
Computer hardware and its componentsComputer hardware and its components
Computer hardware and its components
 
Processors and its Types
Processors and its TypesProcessors and its Types
Processors and its Types
 
Hardware software components
Hardware software componentsHardware software components
Hardware software components
 
Introduction to Computing - Essentials of Technology - Day 1
Introduction to Computing -  Essentials of Technology - Day 1Introduction to Computing -  Essentials of Technology - Day 1
Introduction to Computing - Essentials of Technology - Day 1
 
Basic Features of MS Word 2016.pptx
Basic Features of MS Word 2016.pptxBasic Features of MS Word 2016.pptx
Basic Features of MS Word 2016.pptx
 
Computer
Computer Computer
Computer
 

Similar to 4. programing 101

Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++DSCIGDTUW
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Python programing
Python programingPython programing
Python programinghamzagame
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 

Similar to 4. programing 101 (20)

Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Python programing
Python programingPython programing
Python programing
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

4. programing 101

  • 1. Created By: IEEE MIU SB Academic Committee Arduino Workshop 1
  • 3. Content  What is Programing?  What is a Programing Language?  How do Computers Understand Us?  Machine Language  Low Level Languages  High Level Languages  Compilation Process  Integrated Development Environment (IDE)  Code::Blocks IDE  Install Code Blocks & Start First Project  Variables  Variable Naming Guidelines  Data Types  Variable Declaration & Initialization  Output Statement  Input Statement  if…else Statement  Nested if statement  Switch…case  Prefix VS Postfix  While Loop  Program Errors  Tasks 3
  • 4. What is Programing?  it’s a method that allows you to write specific commands with a certain programing language which enables you create & run applications.  Example: Web Development, Games Development, Mobile App Development, ….etc. 4
  • 5. What is a Programing Language?  Programing language is like our English language it has a grammar that we should follow which is called syntax and for each programing language it has it’s own syntax rules. 5
  • 6. How do Computers Understand Us?  Computers can not use human languages, and programming in the binary language of computers is a very difficult.  Therefore, all programs are written using a programming language which is then converted to Binary Code for the machine to understand.  Due to this revolution; a lot of programing languages were created each with a different generic purpose in mind. 6
  • 7. Machine Language  Natural language of a particular computer.  Primitive instructions built into every computer.  The instructions are in the form of binary code.  Any other types of languages must be translated down to this level. 7 Machine Language (Binary Code)
  • 8. Low Level Languages  English-like Abbreviations used for operations (Load R1, R8).  Assembly languages were developed to make programming easier. 8 Low level language (Assembly Code)
  • 9. High Level Languages  English-like and easy to learn and program.  Common mathematical notation  Ex: Java, C, C++, FORTRAN, VISUAL BASIC, PASCAL, ….etc 9 High level language (C++,java)
  • 10. Compilation Process 10 High Level Language (C++,java) Low Level Language (Assembly) Machine Language (Binary Code)
  • 11. Integrated Development Environment (IDE)  An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development.  An IDE normally consists of a source code editor, build automation tools, and a debugger.  An IDE consists of:  Text Editor.  GUI (Graphical User Interface).  Tool-Chain: 1. Pre-Compiler. 2. Compiler. 3. Linker. 4. Assembler. 5. Debugger. 11
  • 12. Code::Blocks IDE  Code::Blocks is a free C, C++ and Fortran IDE built to meet the most demanding needs of its users.  It is designed to be very extensible and fully configurable. 12
  • 13. Install Code::Blocks & Start 1st Project 13
  • 14. Variables (1/2)  Variables are used to store information to be referenced and manipulated in a computer program.  They provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. Their sole purpose is to label and store data in memory. This data can then be used throughout your program. 14
  • 15. Variables (2/2)  It is helpful to think of variables as containers that hold information. 15
  • 16. Variable Naming Guidelines 16 Declaration: Initialization: We can use underscores and capital letters in a variable name Can’t use: keywords, just numbers, spaces, or special characters ($, &, !, etc)
  • 17. Data Types (1/2) 17 Data types Primitive types Integer Float Character Boolean Non-primitive types Arrays Strings Data type Size Use Example int 2 bytes Used to hold positive and negative whole numbers 1453 float 4 bytes Used to hold fractional or decimal values 7.54 char 1 byte Used to hold individual characters ‘A’ boolean 1 byte Used for logic; true or false true
  • 18. Data Types (2/2)  Every variable must have two things: a data type and a name.  Defines the kind of data the variable can hold.  For example, can this variable hold numbers? Can it hold text? 18
  • 19. Variable Declaration & Initialization type variable-name = value; Meaning: variable <variable-name> will be a variable of type <type> and is initialized with value <value> Where type can be:  int //integer  double //real number  char //character Example: int sum; //Variable Declaration sum =1; // Variable Initialization double x = 5.6; // Variable is declared and initialized int a, b, c; // Multiple Variable Declarations char my-character; 19 data type identifier semi-colon
  • 20. Output Statement 20  2 // Printing a line with multiple statements.  3 #include <iostream>  4 using namespace std;  5 // function main begins program execution  6 int main()  7 {  8 cout << "Welcome ";  9 cout << "to C++!n";  10 cout << "Welcome” << endl;  11 cout << "tonnC++!n";  12  13 return 0; // indicate that program ended successfully  14 } // end function main Welcome to C++! Welcome to C++!
  • 21. Input Statement 21  1 #include <iostream>  2 using namespace std;  3 // function main begins program execution  4 int main()  5 {  6 int integer1; // first number to be input by user  7 int integer2; // second number to be input by user  8 int sum; // variable in which sum will be stored  9 cout << "Enter first integern"; // prompt  10 cin >> integer1; // read an integer  11 cout << "Enter second integern"; // prompt  12 cin >> integer2; // read an integer  13 sum = integer1 + integer2; // assign result to sum  14 cout << "Sum is " << sum << endl; // print sum  15 return 0; // indicate that program ended successfully  16  17 } // end function main Enter first integer 45 Enter second integer 72 Sum is 117
  • 22. if…else Statement (1/5) 22 if (Condition) { S1; } else if(Condition){ S2; } else{ S3; }
  • 23. if…else Statement (2/5)  Comparison operators == equal != not equal < less than > greater than <= less than or equal >= greater than or equal  Boolean operators && and || or ! not 23
  • 24. if…else Statement (3/5)  Assume we declared the following variables: int a = 2, b=5, c=10;  Here are some examples of Boolean conditions we can use:  if (a == b)  if (a != b)  if (a >= b)  if(a <= b)  if(a < b) && (a > c)  if(a == b) || (a == c) 24
  • 25. if…else Statement (4/5) 25  1 // Using if statements, relational  2 // operators, and equality operators.  3 #include <iostream>  4 using namespace std;  5 // function main begins program execution  6 int main()  7 {  8 int num1; // first number to be read from user  9 int num2; // second number to be read from user  10  11 cout << "Enter two integers, and I will tell youn"  12 << "the relationships they satisfy: ";  13 cin >> num1 >> num2; // read two integers  14  15 if ( num1 == num2 )  16 cout << num1 << " is equal to " << num2 << endl;  17  18 if ( num1 != num2 )  19 cout << num1 << " is not equal to " << num2 << endl;
  • 26. if…else Statement (5/5) 26  20 if ( num1 < num2 )  21 cout << num1 << " is less than " << num2 << endl;  22  23 if ( num1 > num2 )  24 cout << num1 << " is greater than " << num2 << endl;  25  26 if ( num1 <= num2 )  27 cout << num1 << " is less than or equal to "  28 << num2 << endl;  29  30 if ( num1 >= num2 )  31 cout << num1 << " is greater than or equal to "  32 << num2 << endl;  33  34 return 0; // indicate that program ended successfully  35  36 } // end function main Enter two integers, and I will tell you the relationships they satisfy: 22 12 22 is not equal to 12 22 is greater than 12 22 is greater than or equal to 12
  • 28. Switch…Case (1/4)  Often you want to do a series of tests:  if i==0 … else if i==1 …. else if i==2 … else if i==3 ….  C++ provides the switch statement to help in this situation  It allows you to specify a large set of cases you want to be able to match, yet works efficiently to find and execute the particular case matched. 28
  • 29. Switch…Case (2/4) 29 switch (expression) { case constant_expression: statements; break; case constant_expression: statements; break; default: statements; }
  • 30. Switch…Case (3/4) 30  1 #include <iostream>  2 using namespace std;  3 // function main begins program execution  4 int main()  5 {  6 cout << “Enter simple expression:” ; // first number to be input by user  7 int left; // second number to be input by user  8 int right; // variable in which sum will be stored  9 char operator; // prompt  10 cin >> left >> operator >> right; // read an integer  11 cout << left<< “ “<< operator<< “” << right<< “ = “; // prompt  12 switch (operator) { // read an integer  13 case ‘+’ : cout << left + right <<endl; break;// assign result to sum  14 case ‘-’ : cout << left - right <<endl; break;//  15 case ‘*’ : cout << left * right <<endl; break;//  16 case ‘/’ : cout << left / right <<endl; break;//  17 default: cout << “Illegal operation”” <<endl;  18 return 0; // indicate that program ended successfully  19  20 } // end function main Enter simple expression: 4 + 5 4 + 5 = 9
  • 31. Switch…Case (4/4)  Notes:  Unless you have many conditions (4 or more), use if-else-if instead of switch.  Always provide a default case – if you are pretty sure you have all cases covered, putting an error message in the default is good to identify unexpected errors.  Order the cases in some logical order (numeric, alphabetic). 31
  • 32. Prefix VS Postfix  Increment then use the variable  Sum = ++count  Use the variable then increment  Sum = count++ 32 count 10 11 sum 0 11 Before After count 10 11 sum 0 10 Before After
  • 33. While Loop (1/2) 33 while (condition) { S1; condition (incrementation/decrementation); } S2;
  • 34. While Loop (2/2) //read 100 numbers from the user and output their sum #include <iostream.h> void main() { int i, sum, x; sum=0; i=1; while (i <= 100) { cin >> x; sum = sum + x; i = i+1; } cout << “sum is “ << sum << endl; } 34
  • 35. Program Errors 35  Syntax Errors:  Errors in grammar of the language.  Runtime error:  When there are no syntax errors, but the program can’t complete execution:  Divide by zero.  Invalid input data.  Logical errors:  The program completes execution, but delivers incorrect results.  Incorrect usage of parentheses.
  • 36. Tasks  Write a program that takes 3 integer numbers from the user & outputs the greatest integer number without using any conditional statements.  Write a program that performs a swapping code without using a temporary variable.  Output a pyramid shape of asterisks “*”. (Hint: Use cout + Loops + if statement)  Make a Calculator using C++ Code on Code::Blocks. 36