Home

1. Introduction to Programming

image

Contents

1. sequence selection repettion gt Sequence v straightforwerd execution of one processing step after another v sequence of pseudocode statenents 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 37 1 6 Writing Pseudocode The structure theorem gt Selection Y condition and choice between two actions depending on whether the condition is true or false v represented by the pseudocode keywords IF THEN ELSE and ENDIF gt Repetition v block of staterrents to be executed repeatedly as long as a condition is true v represented by the pseudocode keywords VVHILE and ENDWHILE 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 38 Computer Science CS 135 1 Introduction to Programming b Writing Pseudocode v Why pseudocode v Six basic computer operations V Thestructure theorem c First Elements of C d Looking Under the Hood 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 39
2. gt Banple find the average of three nunbers V coreofthe programin C cout lt lt Enter 3 numbers cin gt gt x gt gt y gt gt Z sum x y Z avg sum 3 0 cout lt lt endl cout lt lt The average is cout lt lt avg lt lt endl 8 29 2005 CS 135 Computer Science 1 Introduction to Programming average 1 a How to Develop a Program Steps in programdevelopnerrt G amp Runthe programon the conputer v this step uses a programcompiler and sone test data to 8 29 2005 machine check the code for errors syntax errors are detected at compile tre logic errors are detected at run tine a compiler is like an interpreter it translates a high level language such as C into low level machine language lots of O s ard T s compiling and running the programcan be the nost exciting and at the sane tire most frustrating part of the develoorrert process CS 135 Computer Science 1 Introduction to Programming 19 1 a How to Develop a Program Steps in programdevelopnrrt 7 Documert and rrarian the progam Y docunentation should not be the last step but an ongoing task throughout the develooment process extemal docurrertation specifications inqolerrentation user manual etc E intemal docurrentation contrerts in the code 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 20 1 a How to Develop a Program Steps in programdevelopnerrt gt Sunn
3. operations 5 Acomputer can compare wo variables and select one Of two alternate actions v Examples If it starts to rain I ll go inside the building If the cer Starts lIl drive Otherwise l Il take the bus v Keywords IF Student is ferrale THEN IF age gt O THEN Add 1 to ferrele count Add 1 to nuntber_ students ELSE ELSE Add 1 to male court Display In possible ENDIF ENDIF 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 34 1 6 Writing Pseudocode Basic computer operations G amp G A computer can repect a group of actions v Examples E pour wetter in the saucepan until itis full cook the pasta unl itis al dente v Keywords VAILE weater level lt pan_ height THEN Add 1 tablespoon to weter_ volurre vater level weter_ volurre pan _ surface ENDVWVHILE 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 35 1 6 Writing Pseudocode Basic computer operations gt Baanple of pseudocode Find the mean age of the class Prompt the user for nuntboer students Get nurmber_students Prompt the user for all student ages Divide total age by nurmber_studerts Display the result 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 36 1 6 Writing Pseudocode The structure theorem gt Structure theorem vV itis possible to wite any conputer program by using only three basic control structures that are easily represented in pseudocode
4. Science 1 Introduction to Programming 27 1 6 Writing Pseudocode Basic computer operations gt There aresix basic computer operations A W N pP 6 8 29 2005 a computer can receive information a computer can put out information a computer can performanthinetic a computer can assign a value to a vanable or nenory location a computer can compare two variables and select one of two altemate actions a computer can repeat a group of actions CS 135 Computer Science 1 Introduction to Programming 28 1 6 Writing Pseudocode Basic computer operations L Acompuser can receive information Y Geis used when the algorithmmst receive input fromthe keyboard m Get filenane Get dass number V Readis used when the algorithmmust receive input froma file Read course description fromfile Read student nanres fromfile 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 29 1 6 Writing Pseudocode Basic computer operations 2 Acomputer can put out infomation Y Print is used when the output must be sent to the printer 7 Print ProgramCon pleted Y Writeis used when the output must be witten to a file Vite student nanes v Display and Pron pt are used when the output must be displayed on the screen Display Hello world Prompt for class number generally followed by Get 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 30 1 6 Writing Pseudocod
5. University of Nevada Reno CSE Computer Science CS 155 Reno UNIVERSITY 1 Introduction to Programming Ren Doursat Department of Computer Science amp Engineering University of Nevada Reno Fall 2005 8 29 2005 m Pe SS NE Computer Science CS 1535 Introduction to Programming Functions I Passing by Value File Input Output Predefined Functions If and Switch Controls While and For Loops Functions Il Passing by Reference 1 D and 2 D Arrays CS 135 Computer Science 1 Introduction to Programming Computer Science CS 155 1 Introduction to Programming a How to Develop a Program Writing Pseudocode First Elements of C 2 9 p Looking Under the Hood 8 29 2005 CS 135 Computer Science 1 Introduction to Programming Computer Science CS 155 1 Introduction to Programming a How to Develop a Program v A programis like a recipe v Steps in programdevelopnrert Y Procedural programing b Writing Pseudocode c First Elements of C d Looking Under the Hood 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 1 a How to Develop a Program A programis like a recipe 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 1 a How to Develop a Program A programis like a recipe gt Whaetis progranning V programming can be defined as the developorrent of a solution to an identified problem and the setting up of a related se
6. e Basic computer operations 3 Acomputer can performanthneic v 8 29 2005 Either actual mathematical symbols or words can be used m Multiply Length by Width to Conpute Area m Area Length Width Vords and equivalent symbols used in pseudocode Addor z Divide or 7 Subtract or Modulus or 7 Multiply or 5 Parentheses or Con pute and Calculate also possible Con pute degrees Celsius n C F 32 1 8 CS 135 Computer Science 1 Introduction to Programming 31 1 6 Writing Pseudocode Basic computer operations gt Eample of pseudocode 8 29 2005 Find the mean age of the dass Prompt the user for nundboer students Get nurmber_students Prompt the user for all student ages Get all student ages Add all student ages into total age Divide total age by nurmber_studerts Display the result CS 135 Computer Science 1 Introduction to Programming 32 1 6 Writing Pseudocode Basic con puter operations 4 Acomputer can assign a value to a variable or memory location V 8 29 2005 Initialize or Set are used to give cata an initial value Initialize total price to O or lt are used to assign a value as a resutt of processing total pice lt cost price sales tax Save or Store are used to keep a vanable for later use Save custorer_narnre inlast_custorer_nane CS 135 Computer Science 1 Introduction to Programming 33 1 6 Writing Pseudocode Basic con puter
7. ery 6 7 8 29 2005 Define the problem Ouuine the solution design Develop the outline into an algonthm Test the algonthmfor correctness Code the algonthminto a specific lang Run the programon the computer Inplerrentation Docurrent and maintain the program CS 135 Computer Science 1 Introduction to Programming 21 1 a How to Develop a Program go to the kitchen sink place the pan under the tap tum on the tap When the water level is close to the top of the pan tum off the tap 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 22 1 a How to Develop a Program Procedural programming gt Top down development V v v In the top down develoonrert of a programadesign a general solution to the problemis outlined first this is then broken down gradually into more detailed steps unl finally the nost detailed levels have been conpleted hierarchy of procedures sulttasks and derrentary steps gt Mbdular design V v 8 29 2005 procedural programming also incorporates the concept of modular design which involves grouping tasks together because they all performthe sarre function modular design is connected directly to top down development CS 135 Computer Science 1 Introduction to Programming 23 Computer Science CS 135 1 Introduction to Programming a How to Develop a Program v A programis like a recipe v Steps in programdevelopnert V Procedural pro
8. ether nurrber2 Fi average Divide the sumby 3 nurrber3 Display a nessage Display the result 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 14 1 a How to Develop a Program Steps in programdevelopnerrt 3 Develop the ouine into an algorithm VY heeisan equivalent algonthmin a nore fomal style Prompt for three nunbers Get x y Z sum x y Z average average sun7y3 Display a nessage Display average 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 15 1 a How to Develop a Program Steps in programdevelopnrrt 4 Testthe algonthmifor correctness v V 8 29 2005 testing is one of the nost inportant step in the develoorrent of a program yet it is often forgotten the main purpose of desk checking the algonthmis to identify najor logic errors early so that they may be easily corrected e sum x y Z e average sun73 try different test values by hand CS 135 Computer Science 1 Introduction to Programming 16 1 a How to Develop a Program Steps in programdevelopnerrt 5 Code the aigonthminib a specific prograniming language v only after all design considerations have been net should you actually start to code the programinto your chosen progranming language 7 C 2 java FORTRAN a Basic m COBOL a etc 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 17 1 a How to Develop a Program Steps in programdevelopnerrt
9. graniring b Writing Pseudocode c First Elements of C d Looking Under the Hood 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 24 Computer Science CS 135 1 Introduction to Programming b Writing Pseudocode v What is pseudocode v Six basic computer operations V Thestructure theorem c First Elements of C d Looking Under the Hood 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 25 1 6 Writing Pseudocode What is pseudocode Adding up a list of prices Tum on calculator Clear calculator Repeat the following insttuctions Key in collar amount Key in decinal point Key in certs amount Press addition key Until all prices have been entered Vite down total price Tum off calculator 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 26 1 6 Writing Pseudocode What is pseudocode gt Pseuciocode is a way to wite an algorithm recipe v v 8 29 2005 flowcharts are another popular way of reoresenting algonthns pseudocode is easier to read and wite and allows the prograntrer to concentrate on the logic of the problem pseudocode is really structured English Staterrerts are witten in sinple English each instruction is witten on a separate line each set of instructions is witten fromtop to bottom with only one entry and one exit groups of staterrents may be fonred into nodules and that group given a nane CS 135 Computer
10. puter Science 1 Introduction to Programming 9 1 a How to Develop a Program Steps in programdevelopnerrt L Define the problem processing steps 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 1 a How to Develop a Program Steps in programdevelopnerrt gt Banple find the average of three numbers VY whatare the Inputs and outputs number 1 nurmber2 numbers 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 11 1 a How to Develop a Program Steps in programdevelopnerrt 2 Cradline the solution v decon pose the problemin smaller dements and produce a rough draft of the solution the msjor processing steps involved the mejor subtasks if any the mejor contro structures the mejor vanables and record structures the nainNine logic 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 12 1 a How to Develop a Program Steps in programdevelopnerrt gt Beane find the average of three nunbers Y whatare the processing steps e obtain three nunbers nundberl nundoer2 e calculate the average nunber3 e show the result 8 29 2005 CS 135 Computer Science 1 Introduction to Programming average 1 a How to Develop a Program Steps in programdevelopnerrt 3 Develop the ouine into an algorithm V the solution outine of Step 2 is expanded into an algorithm Prompt for three nurrbers Get three numbers H Add numbers tog
11. ries of instructions that will produce the desired results v generally programming is the construction of an algorithm 8 29 2005 CS 135 Computer Science 1 Introduction to Programming 6 1 a How to Develop a Program A programis like a recipe gt Whatis an aigorithne v V 8 29 2005 informally a general method for solving a problem such as a recipe formally a set of precise steps that describe exactly the tasks to be perfomed and in which order an algonthmimust be precise and unambiguous give the correct solution in all cases evertually end an algonthmfrequently involves repetition of an operation CS 135 Computer Science 1 Introduction to Programming 7 1 a How to Develop a Program Steps in programdevelopnrrt gt Seven basic steps in the development of a program L 2 6 7 8 29 2005 define the problem outline the solution develop the outline into an algorithm test the algonthmfor correctness code the algonthminto a specific prog language run the programon the computer Cocurrent and maintain the program CS 135 Computer Science 1 Introduction to Programming 1 a How to Develop a Program Steps in programdevelopnerrt L Define the problem V to help with initial analysis the problemshould be divided into three separate components the inputs the outputs the processing steps to produce the required outputs from the inputs 8 29 2005 CS 135 Com

Download Pdf Manuals

image

Related Search

Related Contents

User Manual  Test Tools Catalog  Samsung C107AT-5/XEF Manuel de l'utilisateur  OWNER`S MANUAL - HighFidelityReview  取扱説明書 - CASIO  Sylvie Considère, Madeleine Griselin  Pitco Frialator SF14 UFM User's Manual  

Copyright © All rights reserved.
Failed to retrieve file