Download presentation
Presentation is loading. Please wait.
Published byFrederica Greene Modified over 9 years ago
1
Overview
2
What is Computer Programming? It is the process of planning a sequence of steps (called instructions) for a computer to follow. 2 STEP 1 STEP 2 STEP 3...
3
Programming Life Cycle Phases Problem-Solving Implementation Maintenance 3
4
Problem-Solving Phase Analyze the problem and specify what the solution must do Develop a general solution(algorithm) to solve the problem Verify that your solution really solves the problem 4
5
Algorithm An algorithm is a finite list of step-by-step instructions for solving a problem. It can be presented by Pseudo Code If score is positive Add score to Total Else Display an error message How to put an elephant into a fridge?
6
Example Problem: Coin Counting I have 100 coins (quarter, dime, nickel and penny only), and I want to figure out how much their total value is. Count and add the coins one by one. Divide the coins into four piles (quarter, dime, nickel and penny), then count them separately. Sum the values of the four piles. What will you do? OR Which one is better? (for human and for computer)
7
Example Problem: Coin Counting Count and add the coins one by one. Algorithm : 1) Read coin 2) Add the coin value to the summed value 3) Repeat Step 1) and 2) if # of coins counted is not 100 yet
8
Example: Triangle The triangle program accepts 3 integers: a, b and c, which are taken to be sides of a triangle. The output of the program is the type of triangle determined by the three sides: Equilateral, Isosceles, Scalene, or NotATriangle. Can you write an algorithm for this problem?
9
What is a programming language? It is a language (just like English, German,…) with strict Grammar rules Symbols Special words that can be interpreted by a computer (compiler to be exact).
10
Example Program int numCoin = 0; float sumValue = 0; string coinType; while ( numCoin < 100 ) { cin >> coinType; if ( coinType == "quarter" ) sumValue = sumValue + 0.25; if ( coinType == "dime" ) sumValue = sumValue + 0.1; if ( coinType == "nickel" ) sumValue = sumValue + 0.05; if ( coinType == "penny" ) sumValue = sumValue + 0.01; numCoin = numCoin + 1; } Note: This is NOT a complete program! Let’s try if it works. Do you understand?
11
High-level programming language more like a nature language (You almost understand it!) C++ Java C C# PHP similar to English But computers don’t understand it!
12
Low-level programming language machine language (computer’s native language) machine specific, not portable composed of 0 and 1’s assembly language: symbolic representation of the machine codes 10010110 00000000 10100101 Add AX, Score
13
Running a program We need to translate the C++ program into machine code! other code from libraries, etc. other code from libraries, etc. written in machine language written in machine language written in machine language written in machine language written in C++ written in C++ via compiler via linker SOURCEOBJECT EXECUTABLE Lab0.cppLab0.objLab0.exe
14
Always solve the problem before writing the program!
15
15 Problem Solving Techniques Ask questions what is the input data? what should be the output? what if …? Look for familiar things find the cheapest product in the inventory find the coldest day of the year Solve by analogy how to play tennis? I know how to play badminton. It’s similar! Use means-ends analysis determine the I/O and then work out the details A B, how?
16
Problem Solving Techniques For a large problem: divide and conquer building-block approach merging solutions How to build a house?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.