CS143: Programming in C++
Download
Report
Transcript CS143: Programming in C++
What is programming?
• Steps to solve a problem.
• Repeatable by executing or “doing” the steps
again.
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
1
Write a program
1. Problem solve phase
2. Implement phase
(Maintenance phase)
Program VCR to tape American Idol
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
2
Problem Solving
• Solve the problem before writing any
program
• Pseudo Code
If score is positive
Add score to Total
Else
Display an error message
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
3
Algorithm
• Instructions on how to do something
– Details
– If you leave out steps…
Can you write an algorithm to set an alarm
clock?
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
4
What is a programming
language?
• Set of instructions, rules, and symbols
known by a computer that can be interpreted
by the computer to solve a problem.
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
5
High Level Programming
Languages
C++
BASIC
Java
COBOL
English Like
Easy to Read and Write
(Compared with low level)
C++ Code Example
Total = Total + Score;
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
6
Low Level Programming
Languages
Total = Total + Score;
Machine Code
10010110 00000000 10100101
Assembly Code
Add AX, Score
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
7
Programming Steps
•
•
•
•
Create source code file: Lab0.cpp
Compile to machine code: Lab0.obj
Link to executable program: Lab0.exe
Run Lab0.exe
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
8
What is a computer?
Network
CPU
Input
Output
MEMORY
Storage
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
9
Hardware
•
•
•
•
•
•
CPU
Memory
Keyboard
Monitor
Disk
…
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
10
Problem-Solving Techniques
• ASK for HELP!!!!
• Look for things that are familiar
– Given salary, compute a 10% salary increase.
– Given the price of a product, compute a 10% price
increase
• Solve by analogy
– I know how to rollerblade.
– This is similar to ice skating.
• Means/Ends Analysis
– If I’m on one side of the river, how can I get to the
other side?
UWP - Landgraf Some slides are from Dr.
Qi Yang's notes
11
Problem-Solving Techniques
• Divide and conquer
– Build a house with electrician, carpenter,
plumber etc.
• Building-block approach
– Components of a sound system
• Merging solutions
– What things can be done at the same time?
UWP - Landgraf Some slides are from Dr.
Qi Yang's notes
12
Mental Blocks
• Fear of starting
– Just do it
• Algorithmic problem solving
– Not always easy
– May fail (it will make you stronger)
UWP - Landgraf Some slides are from Dr.
Qi Yang's notes
13
How to Store Data in
Computer
Bit
Electronic Device
On / Off
Value: 1 / 0
Byte
8 bits
Possible combinations
256
28
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
14
How to Store Data in
Computer
Binary Number
27 26 25 24 23 22 21 20
1
27
128
0
0
0
1
1
1
1
+ 23 + 22 + 21 + 20
+8 +4 +2 +1
Decimal Number: 143
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
15
How to Store Data in
Computer
0
1
0
0
0
0
0
1
Binary Number
65
Character
ASCII
(EBCDIC)
ASCII Character is
See Appendix D pp. 695-696
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
16
How to Store Data in
Computer
Word
2 bytes (16 bits)
Double Word
4 bytes (32 bits)
Integers
Binary Numbers
Characters
ASCII
Unicode (p. 34 footnote)
Float Numbers?
Negative numbers?
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
17
How to Store Data in
Computer
KB
1024 Bytes
210
MB
1024 * 1024 Bytes
220
GB
1024 * 1024 * 1024 Bytes
230
TB…
UWP - Landgraf
Some slides are from Dr. Qi Yang's notes
18