1 / 16

Chapter 1

Chapter 1. Overview. STEP 1. STEP 2. STEP 3. What is Computer Programming?. It is the process of planning a sequence of steps ( called instructions) for a computer to follow. . . . Programming Life Cycle Phases. Problem-Solving Implementation Maintenance.

makya
Download Presentation

Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 Overview

  2. STEP 1 STEP 2 STEP 3 What is Computer Programming? • It is the process of planning a sequence of steps (called instructions) for a computer to follow. . . .

  3. Programming Life Cycle Phases • Problem-Solving • Implementation • Maintenance

  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

  5. Algorithm  How to put an elephant into a fridge? • An algorithm is a finitelist 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

  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: • Read coin • Add the coin value to the summed value • 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; } Do you understand? Note: This is NOT a complete program! Let’s try if it works.

  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. Lab0.cpp Lab0.obj Lab0.exe SOURCE OBJECT EXECUTABLE written in C++ written in machine language written in machine language via linker via compiler other code from libraries, etc. Running a program • We need to translate the C++ program into machine code!

  14. Always solve the problem before writing the program!

  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?

More Related