INTRO COMPUTER PROGRMMNG
INTRO COMPUTER PROGRMMNG CS 0004
Popular in Course
Popular in ComputerScienence
This 81 page Class Notes was uploaded by Jonas Bartell on Monday October 26, 2015. The Class Notes belongs to CS 0004 at University of Pittsburgh taught by Staff in Fall. Since its upload, it has received 35 views. For similar materials see /class/229376/cs-0004-university-of-pittsburgh in ComputerScienence at University of Pittsburgh.
Reviews for INTRO COMPUTER PROGRMMNG
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 10/26/15
CS 0004 Introduction to Programming M E n 51109 54 Summer 2009 mature Chapter 43 Seem Cage Statements 6109 CS4 Summer 2009 Lecture 5 Select Case Block 0 A decision making structure that simpli es choosing among several actions 0 Avoids complex nested If constructs 0 If blocks make decisions based on the truth value of a condition Select Case choices are determined by the value of an expression called a selector Example 1 Form 9 Horse Race El Finishing position 1 2 3 lt tXtPosmon Evaluate Position 1 lt txtOutcome 6109 CS4 Summei 2009 Lecture 5 Select Case Example 1 Private Sub btnEvaluateClick Handles btnEvaluateClick Dim position As Integer CInttxtPositionText Select Case position Case 1 txtOutcomeText quotWinquot Case 2 txtOutcomeText quotPlacequot Case 3 txtOutcomeText quotShowquot Case 4 5 txtOutcomeText quotYou almost placed in the moneyquot Case Else txtBoxText quotOut of the moneyquot End Select End Sub 6109 C34 Sa n amea 2009 lemurs Select Case Terminology Each of the possible actions is preceded by a clause of the form Case valueList where valueList itemizes the values of the selector for which the action should be taken Example 1 Output I Horse Race Elm Finishing position 123 Evaluate Position Place 6109 CS4 Summer 2009 Lecture 5 Example 2 Code Private Sub btnEvaluateClick Handles btnEvaluateClick Dim position As Integer CInttxtPositionText Select Case position Case 1 To 3 txtOutcomeText quotIn the money Congratulationsquot Case Is gt 4 txtOutcomeText quotNot in the moneyquot End Select End Sub Skit09 CS4 Sun39imei 2009 Lemme 9 6109 Example 2 Output f IE Horse Race Finishing position 123 Evaluate Posiion In the money Congratulations CS4 Summer 2009 Lecture 5 hll l Select Case Syntax The general form of the Select Case block is Select Case selector Case valueListl actionl Case valueList2 action2 Case Else action of last resort End Select Rules for Select Case Case Else and its action is optional Each value list contains one or more of the following types of items separated by commas a literal a variable an expression an inequality sign preceded by Is and followed by a literal variable or expression 5 a range expressed in the form a To b where a and b are literals variables or expressions 99 F Flow Chart for Select Case Evaluate selector Perfunn action of last resort I LI 139 5 Lq Chapter 41 ANSI Values Relational and Logical Operators Boolean Values 6109 CS4 S lele er 2009 Lecture 5 14 i r 10 ANSI Values C S 4 ANSI Character Set 0 A numeric representation for every key on the keyboard and for other assorted characters 32 space 48 0 66 B 122 z 33 49 1 90 Z 123 34 57 9 97 a 125 35 65 A 98 b 126 ANSI Character Set 0 A numeric representation for every key on the keyboard and for other assorted characters 162 177 i 181 p 190 1A 169 178 2 188 1A 247 176 179 3 189 12 248 o See Appendix A Also known as ASCII ChrFunc on For n between 0 and 255 Chr n is the string consisting of the character with ANSI value n EXAMPLE39Chr65 is quotAquot Chr162 is quot quot Asc Function For a string str Asc str is ANSI value of the rst character of str EXAMPLES39ASC quotAquot is 65 Ascquot 25quot is 162 ANSI Examples txtBoxText Chr65 This will display A in the txtBox 0 Why do I care I could just do txtBoxText quotAquot ANSI Examples Special Characters txtBoxText quot32quot amp Chr176 amp quot Fahrenheit This will display 32 Fahrenheit txtBoxText quotThis is a doublequote amp amp Chr34i This will display This is a double quote quot Relational and Logical Operators ltgt Relational Operators lessthan less than or equal to greaterthan greaterthan or equal to equal to not equal to ANSI values are used to decide order for strings Relational Examples 1 lt 1 1 lt 2 quotcarquot lt quotcatquot quotDogquot lt dog 314 ltgt 227 5 ltgt five 32 5 Conditions A condition is an expression involving relational andor logical operators Result of the condition is Boolean that is True or False Conditional Examples 1 lt 1 1 gt 2 quotcarquot lt quotcatquot quotDogquot lt dog 314 227 Z lt a Z lt a Conditional Examples 1 lt 1 True 1 gt 2 False quotcarquot lt cat True quotDogquot lt dog True 314 227 False z lt a False Z lt a i Vore Conditional Examples a 4 b 3 c quothelloquot d quotbyequot ab lt 2a cLength b a2 c lt quotgood amp d Vore Conditional Examples a 4 b 3 c quothelloquot d quotbyequot ab lt 2a True 43 lt 24 evaluates to 7lt8 cLength b a2 True 53 42 evaluates to 2 2 c lt quotgood amp d False quothelloquot lt quotgoodbyequot because quothquot gt quotgquot Logical Operators Used with Boolean expressions Not makes a False expression True and vice versa And will yield a True if and only if both expressions are True Or will yield a True if at least one of both expressions are True Logical Operator Examples N4 answ Y 2 lt n And n lt 6 2ltnOrn6 Not n lt 6 answ quotYquot Or answ quotyquot answ quotYquot And answ quotyquot Notansw quotyquot 2 lt n And n 7 Or answ quotYquot 2 lt n And n 7 Or answ quotYquot MM M quotA Mw A MN s39 pmm xu A VLxtaw Logical Operator Examples N4 answ Y 2 lt n And n lt 6 True And True means True 2 lt n Or n 6 True Or False means True Not n lt 6 Not True means False answ quotYquot Or answ quoty True answ quotYquot And answ quoty False Notansw quoty True 2 lt n And n 7 Or answ quotYquot True 2 lt n And n 7 Or answ quotYquot False Boolean Expression 0 An expression that evaluates to either True or False is said to have Boolean data type Example The statement txtBoxText CStr23lt6 displays True in the text box Boolean Variable A variable declared with a statement of the form Dim var As Boolean is said to have Boolean data type It can assume just the two values True and False Example Dim boolVar As Boolean boolVar 2 lt 6 txtBox Text CStr boolVar displays True in the text box Syntax Error The following is NOT a valid way to test if n falls between 2 and 5 Qltnlt5 Correction to Syntax Error To test if n falls between 2 and 5 use 2ltnAndnlt5 A complete relational expression must be on either side of the logical operators And and Or Common Error in Boolean Expressions A common error is to replace the condition Not 2 lt3 with the condition 2 gt 3 The correct replacement is 2 gt 3 because gt is the opposite of lt just as lt is the opposite of gt Back to Select Case Rules for Select Case repeat slide Case Else and its action is optional Each value list contains one or more of the following types of items separated by commas a literal a variable an expression an inequality sign preceded by Is and followed by a literal variable or expression 5 a range expressed in the form a To b where a and b are literals variables or expressions 99 F Select Case Example 3 Partial Code Dim x As Integer 2 y As Integer 3 Select Case num Case y x x txtPhraseText quotBuckle my shoequot Case Is lt 4 txtPhraseText quotShut the doorquot Case x y To x y txtPhraseText quotPick up sticksquot Case 7 8 txtPhraseText quotLay them straightquot Case Else txtPhraseText quotStart all over agalnquot End Select 6109 CS4 Sun39imei 2009 Lecture Select Case Example 4 395 Quiz What was President Wilson39s first name Imelpret Answer IE quot39 t xtReply 6109 CS4 SLm39imei 2009 Lecture 5 Select Case Example 4 Partial Code Select Case firstName Case quotTHOMASquot txtReplyText quotCorrectquot Case quotWOODROWquot txtReplyText quotSorry his namequot amp quot was Thomas Woodrow Wilsonquot Case quotPRESIDENTquot txtReplyText quotAre you for realquot Case Else txtReplyText End Select quotNice tryquot 6109 CS4 Sam39imei 2009 lemme 132 Select Case Example 4 Output 19 Quiz Lcugi What was President W d Wilson39s first name 0 row Intelpret Answer Sorry his full name was Thomas Woodrow Wilson 6109 CS4 Summer 2009 Lecture 5 Select Case Comments In a Case clause of the form Case b To c the value of b should be less than or equal to the value of c The word Is should precede an inequality sign in a value list 0 If the word Isis accidentally omitted where required the editor will automatically insert it when checking the line CS 0004 Introduction to Programming M E n 51309 54 Summer 2009 mature 2 Software Development Lifecycle 51309 54 Sasmmea 2009 mature 2 Software Development Lifecycle 0 Depending on where you work software development may follow different models 0 Different methodologies Waterfall Iterative Sometimes the same company can use both depending on the particular goal or a hybrid Waterfall Model Requirements speci cation De gn Implementation Coding Veri cation Deployment and Maintenance Waterfall Model Requirements Design J Implementation Veri cation Deployment and Maintenance 133032 24 ulnrper ZiiiOQ a lelttare Z Waterfall Model Requirements Requirements J Analyze De ne the problem Determine what the goals of the program isare Determine inputs and outputs Written record of what the nal product should do 51309 C34 Summer 2009 Lecture 2 Waterfall Model De gn Plan the solution to the J problem D998 Find the logical sequence of steps that solve the problem algorithm Details including the obvious Flowchartsetc Interface design 51309 C34 Summer 2009 Lecture 2 Waterfall Model Implementation Coding programming development The software developer 39 J uses the design as a Implementation basis 51309 C34 Summer 2009 Lecture 2 Waterfall Model Veri cation Testing Software bugs may be found Does the program do what you wanted it to do in the requirements Veri cation L J Does the program look like you want it to look 51309 C34 Summer 2009 Lecture 2 9 Waterfall Model Deployment Installation of the program Maintenance Minor changes Correct software bugs found Updates Deployment and Maintenance 51309 C34 Summer 2009 Lecture 2 10 Waterfall Model Requirements 0 Business Analyst Design 0 Software Architect Implementation 0 Developers Veri cation 0 Quality Assurance Deployment and Maintenance 0 Change Management 0 IT Support andor Developers 351535505 24 Summer 2809 7 Lecture 2 Waterfall Model Next phase begins after previous phase ends Often a quotgatequot between each phase Management review Ask Are we ready to go to the next phase Ask Is it worth it to go to the next phase Iterative Model Planning amp Requirements Analysis amp Design Implementation Deployment Veri cation amp Evaluation Repeat Iterative Model Potentially quicker than waterfall Many successive versions of software A quotgatequot after each version Management review Ask Does this version do what we want Ask Do we want anything more Spiral Model Iterative 1 Determine objectives n Cumulahve Cos Progress 1 i gt 2 Identify and resolve risks mskana ysws R s ans 5 39 Requ mr W Review 3 mewswan Ommllnnm pmmmupmwz Pmmlypn Connema Cancepla 39Requureg Dpemnan riyqul rer men s pm quot5 Detaxled i desugn r ummm Ven canun r cm svam n x V 7 Code 79 m mamquot v MW Integratlan quotquot r esl 4 Plan the next on itera I 51309 53 Summe 203539 Release Immememaunn 7 3 Development and Test LECUJI e 2 US Documentation Documentation intended for The programmer Design documents Comments in the code The software development team Requirements Design Documents Instruction manual The user Instruction manual The support staff Support documents Documentation Describes the program Should be developed Before programming begins Requirements Design During programming Code comments Before program is installed anywhere Instruction manual Support documents 51309 Chapter 1314 Problem Solving 54 Summea 2009 Lecture 2 Flowcharts Graphically depict the logical steps to carry out a task Shows how steps relate to each other Shapes connected by arrows Each shape indicates a different activity Flowcharts Terminal Start C Start End 1 Flowlines Arrows l Connect one shape to others C End SJLBJGQ C34 Summer 7009 7 Lecture 2 Flowcharts InputOutput Use when interacting with the user Get number Getting information from Of players the user Getting information from an outside source such as a le Display nal score r M m r v c D39rAllrsjhljfj L Jll LEl uIilll L li 40939 Lemme Z Flowcharts Processing Arithmetic operations Data Manipulation Total points for each player Territories player owns 100 r M m r v t Dlngjljgj L Jll LEl uIilll L li 40939 Lemme Z Flowcharts Decision Use for yesno decisions One entry arrow Yes Two exit arrows quotYesquot path quotNoquot path No 513g 09 CS4 Summer 2009 7 Lecture 2 24 Flowcharts Connector Connect two or more owlines Offpage Connector 5313109 CS4 Summea39 2009 7 Lecture 2 Flowcharts Prede ned Process Represents a group of statements that perform a single task This process is de ned elsewhere maybe in its own owchart Could be implemented as separate software module Calculate bonus points quotm m quot139 W 2 J lumen Ll3 l 539 91in Flowcharts Annotation Provides additional information about another owchart symbol Display nal score 53399 CS4 SL n lmea 2009 lecture 2 Print both teams names and list total number of points for each team next to their name Flowcharts 0 Example on board Determine how many pizzas to order for a party 5 1309 Flowcharts nputguests Jr I Divide guests by 4 I l Round up to nearest whole number 1 Display pizzas needed CS4 Summer 2009 Lecture 2 Hierarchy Charts Shows the overall program structure 0 Also called Structure charts HIPO Hierarchy plus InputProcessOutput charts Topdown charts VTOC Visual Table of Contents charts Hierarchy Charts Show organization of program Describe how modules part of a program relate to each other Details are omitted Hierarchy Charts Helpful in initial planning 0 Divide and conquer Start at the top split it into pieces For each piece that is still ambiguous split it into more pieces Hierarchy Charts 0 Example on board Determine how many pizzas to order for a party Pseudocode Pre x quotpseudo is from Greek meaning quotfalsequot Not quite computer programming language not quite plain English Focuses on the steps needed to solve the problem Pseudocode 0 Example on board Determine how many pizzas to order for a party Pseudocode Pizza ordering example Get number of guests Set the number of pizzas to number of guests 4 Round the number of pizzas up to the next whole number Display the number of pizzas Waterfall Model For Class Projects Requirements 0 AssignmentProject sheet from class G Design 0 Flowchart Hierarchy Chart Pseudocode G Implementation 0 Programming Q Veri cation 0 Testing Deployment and Maintenance 0 Submitturn in your program and any written reports 13569 C24 til li r i EEOC a tectrre Z Vocabulary words Computer program Input Collection of instructions Data that goes into a Software Program Also called Output PrOJect Data that comes out of a Application program Solution Includes images on the screen the look of the application window etc Vocabulary words Flowchart Graphically depict the logical steps to carry out a task and show how the steps relate to each other Pseudocode Uses Englishlike phrases along with some programming terms to outline a task Hierarchy chart Shows how the different parts of a program relate to each other Module A part of a program with a speci c processing task Documentation Material that describes the program