Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 115 Chapter 1 Overview of Programming and Problem Solving.

Similar presentations


Presentation on theme: "CS 115 Chapter 1 Overview of Programming and Problem Solving."— Presentation transcript:

1 CS 115 Chapter 1 Overview of Programming and Problem Solving

2 Chapter 1 Every programmer needs a mental model of a computer Every program does: input / process / output von Neumann model - the "stored program" concept

3 Computer Hardware CPU - central processing unit Where decisions are made, computations are performed, and input/output requests are delegated Main Memory Stores information being processed by the CPU short-term (volatile) Secondary Memory (Mass Storage) Stores data and programs long-term

4 Computer Hardware Components Arithmetic Logic Unit Control Unit Auxiliary Storage Device Memory Unit(RAM & Registers) Central Processing Unit(CPU) Input Device Output Device Peripherals

5 Memory (RAM) a memory cell (also called a word) has an address, has contents Contents expressed in bits / bytes - binary code Holds a value which may be data, may be an instruction data retrieval = a "copy" not a "cut"

6 Memory Cells AddressContents -27.2 354 0.005 -26 H X 75.62 RTV 001... 0 1 2 3 4 5 6... 999

7 Secondary Storage files - source files, data file, output file hard disk, floppy, CD, flash memory stick slower than RAM, and cheaper per byte usually much larger capacity than RAM Units of capacity - Kilobyte, Megabyte, Gigabyte, Terabyte

8 Languages Machine languages take a step, lift arm, grasp knob, turn knob... Assembly languages LEAVE through DOOR High-level languages "get outta here!"

9 Programming Languages Machine Language Most fundamental language of the computer, the one the CPU "understands" Unique for each processor type, so not "portable" Binary 0s and 1s that specify what to do 0010 0000 0000 0100 1000 0000 0000 0101 0011 0000 0000 0110

10 A Program in Machine and Assembly Language

11 High Level Languages Are portable Programmer writes program in language similar to natural language (human) Examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java Most are standardized by ISO/ANSI to provide an official description of the language

12 Software Development Analyze and specify the problem Design the algorithm Implement in code Testing Maintenance

13 Software Development Problem Analysis Identify data objects Determine Input / Output data Constraints on the problem Design Decompose into smaller problems Top-down design (divide and conquer) Develop Algorithm (Desk check) Algorithm refinement (Pseudocode)

14 Software Development Method Implementation Converting the algorithm into programming language Testing Verify the program meets requirements System and Unit tests Maintenance All programs undergo change over time

15 A Tempting Shortcut? GOAL THINKING CODE REVISE DEBUG TEST CODE Shortcut?

16 Translators and Tools Assemblers for assembly languages Compilers for high-level languages IDE (integrated development environment) compiler editor (creates text format files) linker loader debugger

17 Translation Syntax - the rules governing the formation of statements in the language Spelling Order of words, statements Punctuation Semantics – meaning of the statement What does it DO? What action does the computer do when the statement is executed?

18 Processing a Program Editor used to enter the program Creates source program file Compiler translates the source program Displays syntax errors Creates (usually) temporary object code Linker to combine object file with other object files (like library code) Creates final executable program (.exe) Loader copies exe file into RAM to be run by machine

19 Three C++ Program Stages 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 compilervia linker SOURCEOBJECT EXECUTABLE myprog.cppmyprog.objmyprog.exe

20 Ethics Responsibility comes with knowledge hacking piracy data theft and data privacy Responsibility to develop programs without errors

21 Some C++ History 1972 : Dennis Ritchie at Bell Labs designs C and 90% of UNIX is then written in C Late 70’s : OOP becomes popular Bjarne Stroustrup at Bell Labs adds features to C to form “C with Classes” 1983 : Name C++ first used 1998 : ISO/ANSI standardization of C++

22 Objects in a hierarchy

23 Some C++ History Dennis Ritchie Bjarne Stroustrup

24 Problem Solving Techniques Ask questions -- about the data, the process, the output, error conditions Look for familiar things -- certain situations arise again and again Solve by analogy -- it may give you a place to start Use means-ends analysis -- determine the I/O and then work out the details

25 More Problem Solving Techniques Divide and conquer -- break up large problems into manageable units Building-block approach -- can you solve small pieces of the problem? Merge solutions -- instead of joining them end to end to avoid duplicate steps Overcome mental block -- by rewriting the problem in your own words

26 Case Study: Converting Miles to Kilometers 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.

27 Case Study 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.

28 Data Requirements Problem Input milesdistance in miles Problem Output kmsthe distance in kilometers Relevant Formula 1 mile = 1.609 kilometers

29 Design an Algorithm that solves the problem Algorithm (Pseudocode) 1. Get the distance in miles. 2. Convert the distance to kilometers. 3. Display the distance in kilometers. Algorithm Refinement 2.1 The distance in kilometers is 1.609 times the distance in miles Desk check!

30 Miles to kilometers Implementation

31 Testing Test with input data for which you can easily determine the expected results E.g. 10 miles should convert to 16.09 kilometers


Download ppt "CS 115 Chapter 1 Overview of Programming and Problem Solving."

Similar presentations


Ads by Google