SlideShare a Scribd company logo
Introduction to Programming in C++
Eight Edition
Lesson 4.2:
5th step : Desk Check
An Introduction to Programming with C++, Eight Edition
• Fifth step is to desk-check the program to make sure
instructions were translated correctly
• You should desk-check the program using sample data
used to desk-check the algorithm
• Results of both desk-checks should be the same
• First, place names of the declared memory locations in a
new desk-check table along with each memory location’s
initial value
• Next, desk-check remaining C++ instructions in order,
recording any changes made to the variables
Step 5–Desk-Check the Program
2
An Introduction to Programming with C++, Eight Edition
Step 5–Desk-Check the Program
(cont’d.)
3
An Introduction to Programming with C++, Eight Edition
Step 5–Desk-Check the Program
(cont’d.)
4
An Introduction to Programming with C++, Eight Edition
• Final step in the problem-solving process
• You evaluate a program by running the program on the
computer and entering the sample data used when desk-
checking the program
• If evaluation reveals errors (known as bugs), they must
be fixed
• Process of locating and fixing errors is called debugging
• Two types of bugs: syntax errors and logic errors
Step 6–Evaluate and Modify the
Program
5
An Introduction to Programming with C++, Eight Edition
• Syntax errors result from breaking programming
language’s rules; cause compiler errors
• Logic errors don’t cause compiler errors; can be hard to
identify – Example: entering instructions in the wrong
order
• Need a text editor to enter C++ instructions
• Instructions are called source code and are saved in
source files with extension .cpp
• Need a compiler to translate source code into machine
code (also called object code)
Step 6–Evaluate and Modify the
Program (cont’d.)
6
An Introduction to Programming with C++, Eight Edition
• Compiler saves object code in object files with
extension .obj
• Linker combines .obj files with other machine code
necessary to run the program and produces an executable
file with extension .exe
• An IDE (integrated development environment) is a
development tool that contains both an editor and
compiler
• A command-line compiler contains only the compiler
and requires a separate editor to enter source code
Step 6–Evaluate and Modify the
Program (cont’d.)
7
An Introduction to Programming with C++, Eight Edition
• A comment is a form of internal documentation;
written by placing // in front of the comment text
– Ignored by the compiler
– Considered good programming practice; makes code
more readable
• A #include directive allows you to merge the source code
in one file with that in another file
• The #include <iostream> is required when using the cin
or cout stream objects
– Not a statement, so no semicolon needed at the
end
Step 6–Evaluate and Modify the
Program (cont’d.)
8
An Introduction to Programming with C++, Eight Edition
• A using directive tells the compiler where in internal
memory it can find definitions of C++ keywords and
classes like double or string
• The using namespace std; directive indicates that the
definitions of the standard C++ keywords and classes are
located in the std (standard) namespace
– Is a statement, so semicolon required at the end
• A namespace is a special area in internal memory
Step 6–Evaluate and Modify the
Program (cont’d.)
9
An Introduction to Programming with C++, Eight Edition
• A function is a block of code that performs a task
• Functions have parentheses following their name
(Example: main())
• Some functions require information between the
parentheses; others do not
• Every C++ program has one (and only one) main
function; this is where program execution begins
• Some functions return a value, and the data type they
return appears to the left of the function name
– Example: int main()
Step 6–Evaluate and Modify the
Program (cont’d.)
10
An Introduction to Programming with C++, Eight Edition
• Other functions do not return a value, and void appears
to the left of the function name
• The return type, name, and parameters (information in
parentheses) constitute the function header, which marks
the beginning of the function
• After the function header, you enter the function’s code
• You enclose a function’s code in a set of braces ({})
• The code between the braces is called the function body
Step 6–Evaluate and Modify the
Program (cont’d.)
11
An Introduction to Programming with C++, Eight Edition
The sample program based on the
Figure 4-21
12
An Introduction to Programming with C++, Eight Edition
The output displayed in command
prompt
13
An Introduction to Programming with C++, Eight Edition
The End ♥ ♥ ♥
14

More Related Content

PDF
Lesson 4.1 completing the problem solving process
PDF
Lesson 3.1 variables and constant
PDF
Lesson 5.2 logical operators
PDF
Lesson 5 .1 selection structure
PDF
Lesson 2 beginning the problem solving process
PDF
Lesson 3.2 data types for memory location
PDF
Lesson 1 introduction to programming
PPTX
Lesson 13 object and class
Lesson 4.1 completing the problem solving process
Lesson 3.1 variables and constant
Lesson 5.2 logical operators
Lesson 5 .1 selection structure
Lesson 2 beginning the problem solving process
Lesson 3.2 data types for memory location
Lesson 1 introduction to programming
Lesson 13 object and class

What's hot (19)

PPTX
Programming in c (importance of c)
PPT
Csc1100 lecture03 ch03-pt2-s14
PPT
Csc1100 lecture03 ch03-pt2-s14
PPT
test(3)arithmetic in c
PDF
Lecture 7
PPTX
Code Optimization
PPTX
PPTX
Principle source of optimazation
PPTX
Object oriented programming 11 preprocessor directives and program structure
PDF
Compiler Design- Machine Independent Optimizations
PPTX
Data flow model -Lecture-4
PDF
Lesson 9.2 guessing the game program
PPTX
Programming the basic computer
PPTX
Fda unit 1 lec 1
PPTX
Verilog operators
PPTX
Peephole optimization techniques in compiler design
PPTX
C basics
Programming in c (importance of c)
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
test(3)arithmetic in c
Lecture 7
Code Optimization
Principle source of optimazation
Object oriented programming 11 preprocessor directives and program structure
Compiler Design- Machine Independent Optimizations
Data flow model -Lecture-4
Lesson 9.2 guessing the game program
Programming the basic computer
Fda unit 1 lec 1
Verilog operators
Peephole optimization techniques in compiler design
C basics
Ad

Similar to Lesson 4.2 5th and 6th step (20)

PDF
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
PPTX
Introduction to C Language (By: Shujaat Abbas)
PDF
An introduction to programming
PDF
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
PPT
8.3 program structure (1 hour)
PPT
2621008 - C++ 1
PPT
Basic structure of C++ program
PDF
Cp week _2.
PDF
Solutions manual for c++ programming from problem analysis to program design ...
PPTX
Esc3.Intro to C++ and computer program.pptx
PDF
Lesson 8 more on repitition structure
PPTX
Common Programming Errors
PPT
Chapter 8 - More on the Repetition Structure
PPTX
Whole c++ lectures ITM1 Th
PPT
Programming of c++
PDF
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
PDF
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
DOCX
Comso c++
PDF
Lecture 1
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
Introduction to C Language (By: Shujaat Abbas)
An introduction to programming
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
8.3 program structure (1 hour)
2621008 - C++ 1
Basic structure of C++ program
Cp week _2.
Solutions manual for c++ programming from problem analysis to program design ...
Esc3.Intro to C++ and computer program.pptx
Lesson 8 more on repitition structure
Common Programming Errors
Chapter 8 - More on the Repetition Structure
Whole c++ lectures ITM1 Th
Programming of c++
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
C++ Programming From Problem Analysis to Program Design 8th Edition Malik Sol...
Comso c++
Lecture 1
Ad

More from MLG College of Learning, Inc (20)

PPTX
PPTX
PC111-lesson1.pptx
PPTX
PC LEESOON 6.pptx
PPTX
PC 106 PPT-09.pptx
PPTX
PPTX
PPTX
PPTX
PC 106 Slide no.02
PPTX
PPTX
PPTX
PC 106 Slide 1.pptx
PDF
Db2 characteristics of db ms
PDF

Recently uploaded (20)

PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
My India Quiz Book_20210205121199924.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
1_English_Language_Set_2.pdf probationary
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
advance database management system book.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Share_Module_2_Power_conflict_and_negotiation.pptx
What if we spent less time fighting change, and more time building what’s rig...
Computer Architecture Input Output Memory.pptx
B.Sc. DS Unit 2 Software Engineering.pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
My India Quiz Book_20210205121199924.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Indian roads congress 037 - 2012 Flexible pavement
FORM 1 BIOLOGY MIND MAPS and their schemes
1_English_Language_Set_2.pdf probationary
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Virtual and Augmented Reality in Current Scenario
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
advance database management system book.pdf
Hazard Identification & Risk Assessment .pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx

Lesson 4.2 5th and 6th step

  • 1. Introduction to Programming in C++ Eight Edition Lesson 4.2: 5th step : Desk Check
  • 2. An Introduction to Programming with C++, Eight Edition • Fifth step is to desk-check the program to make sure instructions were translated correctly • You should desk-check the program using sample data used to desk-check the algorithm • Results of both desk-checks should be the same • First, place names of the declared memory locations in a new desk-check table along with each memory location’s initial value • Next, desk-check remaining C++ instructions in order, recording any changes made to the variables Step 5–Desk-Check the Program 2
  • 3. An Introduction to Programming with C++, Eight Edition Step 5–Desk-Check the Program (cont’d.) 3
  • 4. An Introduction to Programming with C++, Eight Edition Step 5–Desk-Check the Program (cont’d.) 4
  • 5. An Introduction to Programming with C++, Eight Edition • Final step in the problem-solving process • You evaluate a program by running the program on the computer and entering the sample data used when desk- checking the program • If evaluation reveals errors (known as bugs), they must be fixed • Process of locating and fixing errors is called debugging • Two types of bugs: syntax errors and logic errors Step 6–Evaluate and Modify the Program 5
  • 6. An Introduction to Programming with C++, Eight Edition • Syntax errors result from breaking programming language’s rules; cause compiler errors • Logic errors don’t cause compiler errors; can be hard to identify – Example: entering instructions in the wrong order • Need a text editor to enter C++ instructions • Instructions are called source code and are saved in source files with extension .cpp • Need a compiler to translate source code into machine code (also called object code) Step 6–Evaluate and Modify the Program (cont’d.) 6
  • 7. An Introduction to Programming with C++, Eight Edition • Compiler saves object code in object files with extension .obj • Linker combines .obj files with other machine code necessary to run the program and produces an executable file with extension .exe • An IDE (integrated development environment) is a development tool that contains both an editor and compiler • A command-line compiler contains only the compiler and requires a separate editor to enter source code Step 6–Evaluate and Modify the Program (cont’d.) 7
  • 8. An Introduction to Programming with C++, Eight Edition • A comment is a form of internal documentation; written by placing // in front of the comment text – Ignored by the compiler – Considered good programming practice; makes code more readable • A #include directive allows you to merge the source code in one file with that in another file • The #include <iostream> is required when using the cin or cout stream objects – Not a statement, so no semicolon needed at the end Step 6–Evaluate and Modify the Program (cont’d.) 8
  • 9. An Introduction to Programming with C++, Eight Edition • A using directive tells the compiler where in internal memory it can find definitions of C++ keywords and classes like double or string • The using namespace std; directive indicates that the definitions of the standard C++ keywords and classes are located in the std (standard) namespace – Is a statement, so semicolon required at the end • A namespace is a special area in internal memory Step 6–Evaluate and Modify the Program (cont’d.) 9
  • 10. An Introduction to Programming with C++, Eight Edition • A function is a block of code that performs a task • Functions have parentheses following their name (Example: main()) • Some functions require information between the parentheses; others do not • Every C++ program has one (and only one) main function; this is where program execution begins • Some functions return a value, and the data type they return appears to the left of the function name – Example: int main() Step 6–Evaluate and Modify the Program (cont’d.) 10
  • 11. An Introduction to Programming with C++, Eight Edition • Other functions do not return a value, and void appears to the left of the function name • The return type, name, and parameters (information in parentheses) constitute the function header, which marks the beginning of the function • After the function header, you enter the function’s code • You enclose a function’s code in a set of braces ({}) • The code between the braces is called the function body Step 6–Evaluate and Modify the Program (cont’d.) 11
  • 12. An Introduction to Programming with C++, Eight Edition The sample program based on the Figure 4-21 12
  • 13. An Introduction to Programming with C++, Eight Edition The output displayed in command prompt 13
  • 14. An Introduction to Programming with C++, Eight Edition The End ♥ ♥ ♥ 14