CS100: COMPUTATIONAL
PROBLEM SOLVING
(FALL 2022-23)
Lecture 3
REVISION
2
PROGRAM ANALYSIS EXAMPLE
ANALYZE YOUR FIRST C++
PROGRAM
u The classic first program that everyone writes:
Hello, World!
ch01/hello.cpp
1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 cout << "Hello, World!" << endl;
8 return 0;
9 }
C++ for Everyone by Cay Horstmann
Copyright © 2012 by John Wiley & Sons. All rights reserved
Analyzing Your First Program
C++ for Everyone by Cay Horstmann
Copyright © 2012 by John Wiley & Sons. All rights reserved
ANALYZING YOUR FIRST C++
PROGRAM
u Write the pseudo code and make the
Flowchart and Hierarchy chart
TODAYS TOPICS:
u Stages from Programming till Execution
HELPFUL READINGS:
u Cay Horstmann:
§ Chapter 1: Section 1.6,1.3
BE AWARE OF PROGRAMMING ERRORS
u Programing language follow very strict syntax
conventions and may generate a compile time
error (syntax error) or runtime error/Logic error.
For example:
§ cot << "Hello World!" << endl;
§ cout << "Hello, World! << endl;
§ cout << "Hello, World!" << endl
return 0;
§ cout << "Hollo, World!" << endl;
§ int Main() (note: Main is not main)
ESCAPE SEQUENCES (USING ESCAPE
HATCH)
u Use of backslash “\” as escape hatch
Escape sequence example:
§ \” denotes a literal quote
§ \\ denotes a literal backslash
§ \n denotes a new line
u What will be printed?
§ cout << ”\”Hello\””;
§ cout << ”a-Ace\nb-bat\nc-city”;
MORE ON ESCAPE SEQUENCES
Escape Sequence Character
\n New line
\t Horizontal tab
\\ Backslash
\’ Single quote
\” Double quote
\b Backspace
https://en.cppreference.com/w/cpp/language/escape
PROGRAMMING TILL EXECUTION
u The compiler translates C++ programs into machine
code.
The linker combines machine code with library code
into an executable program.
C++ for Everyone by Cay Horstmann
Copyright © 2012 by John Wiley & Sons. All rights reserved
THE EDIT-COMPILE-RUN LOOP
This process
reflects the way
programmers work
(shown as a flowchart)
C++ for Everyone by Cay Horstmann
Copyright © 2012 by John Wiley & Sons. All rights reserved