1 / 28

Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving

Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving. What is Computer Science? The Computing Curriculum 1991 (ACM/IEEE). Algorithms and Data Structures Architecture Artificial Intelligence and Robotics Database and Information Retrieval

abbottr
Download Presentation

Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving

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. Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving

  2. What is Computer Science?The Computing Curriculum 1991 (ACM/IEEE) • Algorithms and Data Structures • Architecture • Artificial Intelligence and Robotics • Database and Information Retrieval • Human-Computer Communication • Numerical and Symbolic Computation • Operating Systems • Programming Languages • Software Engineering • Social and Professional Context

  3. Machine Language • Is not portable • Runs only on specific type of computer • Is made up of binary-coded instructions (strings of 0s and 1s) • Is the language that can be directly used by the computer.

  4. High Level Languages • Are portable • User writes program in language similar to natural language • Compiler translates high-level language program into machine language • Examples of high level languages • FORTRAN, ALGOL, BASIC, COBOL, Pascal, C, Ada, Modula-2, C++

  5. Early History of C++ • 1969 -- Ken Thompson at AT&T’s Bell Labs begins to design UNIX operating system • Writing UNIX using assembly language on DEC PDP-7 • For more powerful PDP-11 wants to write UNIX in a high level language • No appropriate high-level language exists

  6. More C++ History • 1970 -- Thompson designs new B language • 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

  7. myprog.cpp myprog.obj myprog.exe SOURCE OBJECT EXECUTABLE written in C++ written in machine language written in machine language via compiler via linker other code from libraries, etc. Three Program Stages

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

  9. Memory Organization • Two circuit states correspond to 0 and 1. • Bit (short for binary digit) refers to a single 0 or 1. Bit patterns represent both the computer instructions and computer data. • 1 byte = 8 bits • 1 KB = 1024 bytes • 1 MB = 1024 x 1024 = 1,048,576 bytes

  10. Binary Numbers System • Place Number System • Two Digits; 1 and 0 • 1st position is 2 to 0 power = 1 • 2nd position is 2 to 1 power = 2 • 3rd position is 2 to 2 power = 4 • 4th position is 2 to 3 power = 8 • 5th position is 2 to 4 power = 16

  11. Binary Numbers System • 000001 in binary is equal to 1 base 10 • 111111 in binary is equal to 63 base 10 • 000101 in binary is equal to 5 base 10 • 010000 in binary is equal to 16 base 10 • 111001 in binary is equal to 57 base 10 • 000111 in binary is equal to 7 base 10 • 000110 in binary is equal to 6 base 10

  12. How Many Possible Digits? • Binary (Base 2) Numbers use 2 digits: JUST 0 and 1 • Decimal(Base 10) Numbers use 10 digits: 0 THROUGH 9

  13. Basic Programming Structures • A sequence is a series of statements to be executed one after another. • Selection (branch) is a structure that executes different statements depending on certain conditions. • Looping (repetition) is a structure to repeat statements while certain conditions are met. • The subprogram is used to break the program into smaller units.

  14. SEQUENCE . . . Statement Statement Statement

  15. SELECTION (branch) IF Condition THEN Statement1 ELSE Statement2 True Statement1 Statement Condition . . . Statement2 False

  16. WHILE Condition DO Statement1 False . . . Condition True Statement LOOP (repetition)

  17. . . . SUBPROGRAM1 SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM SUBPROGRAM (function)

  18. Programming Life Cycle • Problem-Solving Phase Analysis and Specification General Solution ( Algorithm Development ) • Implementation Phase Concrete Solution ( Program ) Test • Maintenance Phase Use Maintain

  19. Sample Problem • A programmer needs an algorithm to determine an employee’s weekly wages. • How would the calculations be done by hand?

  20. 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 ___________ $ 1435.50 One Employee’s Wages • During one week an employee works 52 hours at the hourly pay rate $24.75 • How much is the employee’s wages? • Assume a 40.0 hour normal work week. • Assume an overtime pay rate factor of 1.5

  21. Problem-Solving Phase • What information will be used? • INPUT VALUE from outside the program • CONSTANT VALUE assumed in program • COMPUTED VALUE produced by program • OUTPUT VALUE written to file or screen by program

  22. Problem-Solving Phase CONSTANTS OUTPUT INPUT Hourly payRate Hours worked Wages Hourly payRate Hours worked Normal work hours ( 40.0 ) Overtime pay rate factor (1.5) COMPUTED VALUE Wages

  23. Weekly Wages, in General If hours is over 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate RECALL EXAMPLE ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) =$ 1435.50

  24. An Algorithm is . . . • a step-by-step procedure for solving a problem in a finite amount of time.

  25. Algorithm to Determine an Employee’s Weekly Wages 1. Get the employee’s hourly payRate 2. Get the hours worked this week 3. Calculate this week’s regular wages 4. Calculate this week’s overtime wages (if any) 5. Add the regular wages to overtime wages (if any) to determine total wages for the week

  26. Implementation Phase:Program • Translate your algorithm into a programming language. • With C++, you use • Documentation -- written explanations • Compiler -- translates your program into machine code • Main Program -- may call subalgorithms

  27. Implementation Phase: Test • TEST the program using sample input data for which correct results are already known, or can be manually checked. • Use a variety of sample data to test many situations. • If you find errors, analyze the program and algorithm to determine their source, and make corrections.

  28. Maintenance Phase • USE and MODIFY the program to meet changing requirements or correct errors that show up in using it.

More Related