1 / 19

Communicating with Computers

***** SWTJC STEM *****. Communicating with Computers. "A person who wants to use a computer must learn to be precise.  One does not communicate with a computer by hand waving and mumbling.  A computer can be of service only if it is instructed carefully and according to preset rules ." .

adler
Download Presentation

Communicating with Computers

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. ***** SWTJC STEM ***** Communicating with Computers "A person who wants to use a computer must learn to be precise.  One does not communicate with a computer by hand waving and mumbling.  A computer can be of service only if it is instructed carefully and according to preset rules."  Michael Kennedy and Martin Soloman Chapter 1-2 cg 15

  2. ***** SWTJC STEM ***** Program Style and Structure • Program style refers to the “look and feel” of the program. • Program structure refers to how the internal parts of programs are put together. • Automobiles have body styles such as sedan, hardtop, convertible, etc. • Automobiles have structure such as frame, rack and pinion steering, etc. • Consider now program style and structure. Chapter 1-2 cg 26

  3. ***** SWTJC STEM ***** Program Style • Style refers to the “look and feel” of the program. • Programs have two distinct styles or “looks”, procedure-oriented and object-oriented. • Procedure-oriented programs • Characterized by reliance on step-by-step procedures to accomplish tasks. • Manual tasks become program steps. • Data and output are separate and form the input and output to the procedure. • Older languages such as Basic, Fortran, and Cobol are procedural. Chapter 1-2 cg 26

  4. ***** SWTJC STEM ***** Program Style • Object-oriented programs • Combines data and task into objects. • Object has behaviors called methods and attributes called properties. • Methods and properties embody the problem solution. • Offer greater flexibility and modularity in modern GUI (eg., Windows) environments. • Java and C++ are object oriented languages. Chapter 1-2 cg 15

  5. ***** SWTJC STEM ***** Program Style • Procedural style is the traditional style use by engineers in problem solving. • In recent years, most programming has moved to object style. • Our text focuses on object oriented programming, and so will we. • However, the actual coding buried within object programs is often by its nature procedural. • Therefore, object programming requires a basic knowledge of procedural style. Chapter 1-2 cg 15

  6. ***** SWTJC STEM ***** Program Structure • Structure refers to how the internal parts of programs are put together. • Software is “structured” by design rules that have been adopted and used. • Design rules make structured programs . . . • Easy to write and read • Easy to debug (find  mistakes and errors) • Easy to understand • Easy to modify • Easy to reuse Chapter 1-2 cg 15

  7. ***** SWTJC STEM ***** Program Structure cont. • Program Structure (cont.) • No one wants an expensive, flashy sports car that stalls in traffic because of poor design. • No one wants a program with a trendy, colorful Windows interface that suddenly crashes with the infamous “blue screen of death”. Chapter 1-2 cg 15

  8. ***** SWTJC STEM ***** Design Rules • Structured program design rules: • Structured programs are modular and self-contained. • Modules are meaningfully named, single entry and exit, limited in length (20-30 lines of code). • Variables are meaningfully named, explicitly declared, and of limited scope. • Structured programs are documented at all levels. • Structured programs do not use unconditional transfers (GOTO’s). • Structured programs use only three control structures: sequence, selection, and repetition. Chapter 1-2 cg 15

  9. ***** SWTJC STEM ***** Design Rules Cont. • Structured program design rules (cont.): • Control structures are single entry and exit, may be stacked or nested, but never overlapped. • Nested control structures should be indented for clarity. • Java supports and reinforces these structure rules. That’s why it is a very good beginner’s language! • Java helps you form good programming habits. • Habits that will serve you well, no matter what programming language you eventually use! Chapter 1-2 cg 15

  10. ***** SWTJC STEM ***** Problem Solving Steps with a Computer Problem Solving Steps • Formulate the problem exactly . • Decide on a solution method (an algorithm). • Outline solution procedure (flowchart or pseudocode). • Assemble information and data to be used. • Choose test data to produce known results . • Prepare the program • Execute the program. • Check the solution against the known results . • Use the program with actual data. • Prepare a documentation package. Chapter 1-2 cg 16

  11. ***** SWTJC STEM ***** Does an algorithm exist? Speaking of algorithms . . • Does an algorithm exist that will produce a computer solution for a given problem?  • Is there a way to know? • Apply Knuth’s definition to the problem. • Donald Knuth, Professor Emeritus at Stanford University • The Art of Computer Programming (TAOCP) • Considered among the ten best scientific monographs of the 20th century Chapter 1-2 cg 16

  12. ***** SWTJC STEM ***** Knuth’s Definition of Algorithm An algorithm is a finite set of rules which gives a sequence of operations for solving a specific type of problem.  An algorithm has these features: • Finiteness- An algorithm must always terminate after a finite number of steps. • Definiteness - Each step in an algorithm must be precisely defined; the actions to be taken must be rigorously and unambiguously specified for each case. • Input - An algorithm has zero or more inputs, i.e., quantities which are given to it before thealgorithm begins. [We call inputs the data.] Chapter 1-2 cg 16

  13. ***** SWTJC STEM ***** Definition of Algorithm Cont. • Output - An algorithm has one or more outputs, i.e., quantities which have a specified relationship to the inputs. [We call output the results.] • Effectiveness - An algorithm is generally expected to be effective.  This means that all of the operations to be performed must be sufficiently basic that they can in principle be done exactly and in a finite length of time by a person using a paper and pencil. Chapter 1-2 cg 16

  14. ***** SWTJC STEM ***** Problem Algorithm - Block Diagram Process Data (Steps) Input(s) 0 or more (Data) Output(s) 1 or more (Results) Chapter 1-2 cg 16

  15. ***** SWTJC STEM ***** Problem AlgorithmZero Input, One Output Calculate PI (No Input) “3.1415926...” Chapter 1-2 cg 16

  16. ***** SWTJC STEM ***** Problem AlgorithmOne-Input, One Output Calculate Area of Circle A = PI * r2 Radius r Circle Area Chapter 1-2 cg 16

  17. ***** SWTJC STEM ***** Problem Algorithm Two-Input, One Output Calculate Volume of Cylinder V = PI * r2*h Radius r Cylinder Volume Height h Chapter 1-2 cg 16

  18. Calculate Mean & Standard deviation Value 1 Mean Value 2 . . . SD Value n ***** SWTJC STEM ***** Problem AlgorithmMany-Input, Two Output • Note that algorithmic problem solving follows the “input”, “process”, “output” approach that characterizes the proceduralstyleof programming. • For this reason, engineers and scientists who are heavily involved in problem solving have traditionally preferred the procedural style of programming. Chapter 1-2 cg 16

  19. ***** SWTJC STEM ***** Conclusion • In recent years, the object style of programming has achieved unprecedented popularity, even among engineers and scientists. • Algorithmic based problem solving is still used, but the approach to programming the solution is more likely to be in object style. • As engineers and scientists, we may initially think out the problem solution in procedural style, we will learn to formulate the programming solution in object style. • In the next lecture we will explore object style in greater detail. Chapter 1-2 cg 16

More Related