problem solving

446
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
446
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

problem solving

  1. 1. CS 115 Chapter 1 Overview of Programming and Problem Solving
  2. 2. Chapter 1 <ul><li>Every programmer needs a mental model of a computer </li></ul><ul><li>Every program does: input / process / output </li></ul><ul><li>von Neumann model - the &quot;stored program&quot; concept </li></ul>
  3. 3. Computer Hardware <ul><li>CPU - central processing unit </li></ul><ul><ul><li>Where decisions are made, computations are performed, and input/output requests are delegated </li></ul></ul><ul><li>Main Memory </li></ul><ul><ul><li>Stores information being processed by the CPU short-term (volatile) </li></ul></ul><ul><li>Secondary Memory (Mass Storage) </li></ul><ul><ul><li>Stores data and programs long-term </li></ul></ul>
  4. 4. Computer Hardware Components <ul><li> Central Processing Unit(CPU) </li></ul>Arithmetic Logic Unit Control Unit Auxiliary Storage Device Memory Unit(RAM & Registers) Peripherals Input Device Output Device
  5. 5. Memory (RAM) <ul><li>a memory cell (also called a word) </li></ul><ul><li>has an address, has contents </li></ul><ul><li>Contents expressed in bits / bytes - binary code </li></ul><ul><li>Holds a value which may be data, may be an instruction </li></ul><ul><li>data retrieval = a &quot;copy&quot; not a &quot;cut&quot; </li></ul>
  6. 6. Memory Cells <ul><li>Address Contents </li></ul>-27.2 354 0.005 -26 H X 75.62 RTV 001 . . . 0 1 2 3 4 5 6 . . . 999
  7. 7. Secondary Storage <ul><li>files - source files, data file, output file </li></ul><ul><li>hard disk, floppy, CD, flash memory stick </li></ul><ul><li>slower than RAM, and cheaper per byte </li></ul><ul><li>usually much larger capacity than RAM </li></ul><ul><li>Units of capacity - Kilobyte, Megabyte, Gigabyte, Terabyte </li></ul>
  8. 8. Languages <ul><li>Machine languages </li></ul><ul><ul><li>take a step, lift arm, grasp knob, turn knob... </li></ul></ul><ul><li>Assembly languages </li></ul><ul><ul><li>LEAVE through DOOR </li></ul></ul><ul><li>High-level languages </li></ul><ul><ul><li>&quot;get outta here!&quot; </li></ul></ul>
  9. 9. Programming Languages <ul><li>Machine Language </li></ul><ul><ul><li>Most fundamental language of the computer, the one the CPU &quot;understands&quot; </li></ul></ul><ul><ul><li>Unique for each processor type, so not &quot;portable&quot; </li></ul></ul><ul><ul><li>Binary 0s and 1s that specify what to do </li></ul></ul><ul><ul><ul><li>0010 0000 0000 0100 </li></ul></ul></ul><ul><ul><ul><li>1000 0000 0000 0101 </li></ul></ul></ul><ul><ul><ul><li>0011 0000 0000 0110 </li></ul></ul></ul>
  10. 10. A Program in Machine and Assembly Language
  11. 11. High Level Languages <ul><li>Are portable </li></ul><ul><li>Programmer writes program in language similar to natural language (human) </li></ul><ul><li>Examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java </li></ul><ul><li>Most are standardized by ISO/ANSI to provide an official description of the language </li></ul>
  12. 12. Software Development <ul><li>Analyze and specify the problem </li></ul><ul><li>Design the algorithm </li></ul><ul><li>Implement in code </li></ul><ul><li>Testing </li></ul><ul><li>Maintenance </li></ul>
  13. 13. Software Development <ul><li>Problem Analysis </li></ul><ul><ul><li>Identify data objects </li></ul></ul><ul><ul><li>Determine Input / Output data </li></ul></ul><ul><ul><li>Constraints on the problem </li></ul></ul><ul><li>Design </li></ul><ul><ul><li>Decompose into smaller problems </li></ul></ul><ul><ul><li>Top-down design (divide and conquer) </li></ul></ul><ul><ul><li>Develop Algorithm (Desk check) </li></ul></ul><ul><ul><ul><li>Algorithm refinement ( Pseudocode) </li></ul></ul></ul>
  14. 14. Software Development Method <ul><li>Implementation </li></ul><ul><ul><li>Converting the algorithm into programming language </li></ul></ul><ul><li>Testing </li></ul><ul><ul><li>Verify the program meets requirements </li></ul></ul><ul><ul><li>System and Unit tests </li></ul></ul><ul><li>Maintenance </li></ul><ul><ul><li>All programs undergo change over time </li></ul></ul>
  15. 15. A Tempting Shortcut? GOAL THINKING CODE REVISE REVISE REVISE DEBUG DEBUG DEBUG TEST CODE Shortcut?
  16. 16. Translators and Tools <ul><li>Assemblers for assembly languages </li></ul><ul><li>Compilers for high-level languages </li></ul><ul><li>IDE (integrated development environment) </li></ul><ul><ul><li>compiler </li></ul></ul><ul><ul><li>editor (creates text format files) </li></ul></ul><ul><ul><li>linker </li></ul></ul><ul><ul><li>loader </li></ul></ul><ul><ul><li>debugger </li></ul></ul>
  17. 17. Translation <ul><li>Syntax - the rules governing the formation of statements in the language </li></ul><ul><ul><li>Spelling </li></ul></ul><ul><ul><li>Order of words, statements </li></ul></ul><ul><ul><li>Punctuation </li></ul></ul><ul><li>Semantics – meaning of the statement </li></ul><ul><ul><li>What does it DO? What action does the computer do when the statement is executed? </li></ul></ul>
  18. 18. Processing a Program <ul><li>Editor used to enter the program </li></ul><ul><ul><li>Creates source program file </li></ul></ul><ul><li>Compiler translates the source program </li></ul><ul><ul><li>Displays syntax errors </li></ul></ul><ul><ul><li>Creates (usually) temporary object code </li></ul></ul><ul><li>Linker to combine object file with other object files (like library code) </li></ul><ul><ul><li>Creates final executable program (.exe) </li></ul></ul><ul><li>Loader copies exe file into RAM to be run by machine </li></ul>
  19. 19. Three C++ Program Stages other code from libraries, etc. written in machine language written in machine language written in C++ via compiler via linker SOURCE OBJECT EXECUTABLE myprog.cpp myprog.obj myprog.exe
  20. 20. Ethics <ul><li>Responsibility comes with knowledge </li></ul><ul><li>hacking </li></ul><ul><li>piracy </li></ul><ul><li>data theft and data privacy </li></ul><ul><li>Responsibility to develop programs without errors </li></ul>
  21. 21. Some C++ History <ul><li>1972 : Dennis Ritchie at Bell Labs designs C and 90% of UNIX is then written in C </li></ul><ul><li>Late 70’s : OOP becomes popular </li></ul><ul><li>Bjarne Stroustrup at Bell Labs adds features to C to form “C with Classes” </li></ul><ul><li>1983 : Name C++ first used </li></ul><ul><li>1998 : ISO/ANSI standardization of C++ </li></ul>
  22. 22. Objects in a hierarchy
  23. 23. Some C++ History Dennis Ritchie Bjarne Stroustrup
  24. 24. Problem Solving Techniques <ul><li>Ask questions -- about the data, the process, the output, error conditions </li></ul><ul><li>Look for familiar things -- certain situations arise again and again </li></ul><ul><li>Solve by analogy -- it may give you a place to start </li></ul><ul><li>Use means-ends analysis -- determine the I/O and then work out the details </li></ul>
  25. 25. More Problem Solving Techniques <ul><li>Divide and conquer -- break up large problems into manageable units </li></ul><ul><li>Building-block approach -- can you solve small pieces of the problem? </li></ul><ul><li>Merge solutions -- instead of joining them end to end to avoid duplicate steps </li></ul><ul><li>Overcome mental block -- by rewriting the problem in your own words </li></ul>
  26. 26. Case Study: Converting Miles to Kilometers <ul><ul><li>Problem    Your summer surveying job requires you to study some maps that give distances in kilometers and some that use miles. You and your coworkers prefer to deal in metric measurements. Write a program that performs the necessary conversion. </li></ul></ul>
  27. 27. Case Study <ul><ul><li>Analysis   The first step in solving this problem is to determine what you are asked to do. You must convert from one system of measurement to another, but are you supposed to convert from kilometers to miles, or vice versa? The problem states that you prefer to deal in metric measurements, so you must convert distance measurements in miles to kilometers. </li></ul></ul>
  28. 28. Data Requirements <ul><li>Problem Input </li></ul><ul><li>miles distance in miles </li></ul><ul><li>Problem Output </li></ul><ul><li>kms the distance in kilometers </li></ul><ul><li>Relevant Formula </li></ul><ul><li>1 mile = 1.609 kilometers </li></ul>
  29. 29. Design an Algorithm that solves the problem <ul><li>Algorithm (Pseudocode) </li></ul><ul><ul><li>1. Get the distance in miles. </li></ul></ul><ul><ul><li>2. Convert the distance to kilometers. </li></ul></ul><ul><ul><li>3. Display the distance in kilometers. </li></ul></ul><ul><li>Algorithm Refinement </li></ul><ul><ul><li>2.1 The distance in kilometers is 1.609 times the distance in miles </li></ul></ul><ul><li>Desk check! </li></ul>
  30. 30. Miles to kilometers Implementation
  31. 31. Testing <ul><li>Test with input data for which you can easily determine the expected results </li></ul><ul><li>E.g. </li></ul><ul><li>10 miles should convert to 16.09 kilometers </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×