7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:

Slides:



Advertisements
Similar presentations
March R. Smith - University of St Thomas - Minnesota Today’s Class Quiz RecapQuiz Recap Exam ReviewExam Review C MaterialC Material Matlab MaterialMatlab.
Advertisements

March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab Status?Lab Status? Stuff from the readingStuff from the reading.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab 16Lab 16 Filling in an arrayFilling in an array Searching for a.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class More about FunctionsMore about Functions RecursionRecursion.
March R. Smith - University of St Thomas - Minnesota Today’s Class Recap of a simple programRecap of a simple program A “history” of CA “history”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class IF StatementIF Statement Revisiting assignment statementsRevisiting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam TopicsExam Topics.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The project assignment, againThe project assignment, again Arrays.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Functions and Array ArgumentsFunctions and Array Arguments ExamExam.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Today: covering through P. 83 of textToday: covering through P. 83 of.
March R. Smith - University of St Thomas - Minnesota Today’s Class Course StuffCourse Stuff –Classroom change TOMORROW –Assignment; Lab While LoopsWhile.
March R. Smith - University of St Thomas - Minnesota Today’s Class Program LayoutProgram Layout Problem SolvingProblem Solving Reading InputReading.
March R. Smith - University of St Thomas - Minnesota Today’s Class RecapRecap More course thingsMore course things Work on labs/projectsWork on labs/projects.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class GradingGrading The examThe exam Sorting arraysSorting arrays Pointers,
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Where we areWhere we are Strings and TextStrings and Text ConditionalsConditionals.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam ReviewFinal Exam Review –Assessment –Exam Format –C –Matlab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class I/O ObjectsI/O Objects Lab 12Lab 12.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Young Scholars GrantsYoung Scholars Grants Exam Next TuesdayExam Next.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Today’s LabToday’s Lab SortingSorting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The ProjectThe Project PointersPointers.
March R. Smith - University of St Thomas - Minnesota CISC Class Today Return Homework; grading recapReturn Homework; grading recap “Enigma”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Class projectsClass projects Lab 13: Use the method documentation.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Getting Homework BackGetting Homework Back DecimalFormat class.
6/22/2015 1R. Smith - University of St Thomas - Minnesota QMCS Class Today St. Lukes Case StudySt. Lukes Case Study.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Return HomeworkReturn Homework Class ScheduleClass Schedule Functions:
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam Hierarchy of FunctionsHierarchy of Functions Solving.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Cryptography – introductory termsCryptography – introductory terms “Enigma”
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Rest of semesterRest of semester –More on strings (Chapter 10) –More.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class RecapRecap Functions and CFunctions and C Using FunctionsUsing Functions.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class MethodsMethods Problem solving by decompositionProblem solving by.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Authorizing OvertimeAuthorizing Overtime Weird Java stuff: conditionals,
March R. Smith - University of St Thomas - Minnesota Today’s Class Classroom ChangeClassroom Change Flow ChartsFlow Charts For LoopsFor Loops Light.
March R. Smith - University of St Thomas - Minnesota Today’s Class Lab 1 commentsLab 1 comments Data Types in Chapter 4Data Types in Chapter 4 Lab.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Nested IFNested IF “Boolean” Logical Operations“Boolean” Logical.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Lab Status, Paper StatusLab Status, Paper Status Comments on Ints vs.
6/28/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper recapHistory Paper recap Finish the movieFinish the movie.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class StatusStatus –Survey –Returning homework ArraysArrays –What are they?
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Finish up Lab 13Finish up Lab 13 Lab 14 – DetailsLab 14 – Details.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam –Open book, no notes, like last time Exam TopicsExam.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Administrative: do you want another lab?Administrative: do you want.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Revised Lab 14/15Revised Lab 14/15 Counting WordsCounting Words Moving.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class About HomeworkAbout Homework Increment/DecrementIncrement/Decrement.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Homework & GradesHomework & Grades Multiple DimensionsMultiple Dimensions.
March R. Smith - University of St Thomas - Minnesota Today’s Class Homework NotesHomework Notes –Always try to match the printed output if I give.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class More LoopsMore Loops Do While – a ‘trailing decision’ loopDo While.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The ExamThe Exam Homework NotesHomework Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Peek at Lab 16Peek at Lab 16 Side effects and arraysSide effects and.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class AssignmentsAssignments Logical operationsLogical operations Summations.
9/21/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Files, writing filesFiles, writing files 1D Array Recap1D.
5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class A note on methodsA note on methods ObjectsObjects Creating your.
1/28/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Assignments 7 and 8Assignments 7 and 8 ExamExam History Paper AssignmentHistory.
1/31/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Problem 11Problem 11 Problem 12Problem 12.
2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class What’s on the Exam Next Week?What’s on the Exam Next Week? Lab 8Lab.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Computer HardwareComputer Hardware Recap: next programRecap: next program.
7/7/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Project ProposalProject Proposal Problem 12Problem 12 Final.
Presentation transcript:

7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review: Function DeclarationReview: Function Declaration Arrays and Side EffectsArrays and Side Effects –Example: counting digits typed

Recap Computer HardwareComputer Hardware Scanning for Words FunctionScanning for Words Function Working on Assignment 10Working on Assignment 10

Zeroes We have three zeroes:We have three zeroes:0‘0’ and ‘\0’ Two are ‘characters’ one is a literal numberTwo are ‘characters’ one is a literal number 0 == ‘\0’ && ‘0’ == 48 7/6/2016 3R. Smith - University of St Thomas - Minnesota

How to Declare a Function There is a ‘function description’There is a ‘function description’ –Function’s name, return type, arguments Use the description to create the functionUse the description to create the function Function Header: All on one line:Function Header: All on one line: –Function type –Function name –First open parenthesis For each argument:For each argument: –Argument type –Argument name –Array description, if it’s an array –Comma, if there’s another argument 7/6/2016 4R. Smith - University of St Thomas - Minnesota

Variables in a Function The ‘arguments’ are ‘fill in the blanks’The ‘arguments’ are ‘fill in the blanks’ –When we say sqrt(4), we want sqrt to calculate the answer –When we say printf(“Hello”), we want printf to print “Hello” We declare the argumentsWe declare the arguments –And they’re filled in when we call the function We declare local variables after the headerWe declare local variables after the header –Just like in main() –Note: main() is a function with ZERO arguments, like getint() 7/6/2016 5R. Smith - University of St Thomas - Minnesota

How do we count digits in text? A function with ‘side effects’A function with ‘side effects’ –We can change an array passed as an argument Let’s produce a digit counting functionLet’s produce a digit counting function –Input arguments: Character array (string) to count digits inCharacter array (string) to count digits in Array of integers, one per digit being countedArray of integers, one per digit being counted Length of the array of integersLength of the array of integers –Result type: void since answer is in array of integers The big picture: this is an exampleThe big picture: this is an example –This is NOT part of Assignment 10 –It will help you figure out Assignment 10 –How do they compare? ……. 7/6/2016 6R. Smith - University of St Thomas - Minnesota

Counting digits in text What parts are the same? what parts differ?What parts are the same? what parts differ? Both have roughly the same main()Both have roughly the same main() –Local variables: an array to count, maybe some loop indices –Step 1: initialize the array to count –Step 2: loop to read lines of text till a blank line is typed Inside the loop, read the line of textInside the loop, read the line of text Pass the line of text to the counting function (either one)Pass the line of text to the counting function (either one) –Step 3: call function to print out the results Short term: print array valuesShort term: print array values Long term: print a histogramLong term: print a histogram 7/6/2016 7R. Smith - University of St Thomas - Minnesota

Counting digits in text: the function Similar but simpler than word length countSimilar but simpler than word length count Big loop to step through chars in the stringBig loop to step through chars in the string –If the char is a digit (and ONLY if) Then increment the corresponding count in the arrayThen increment the corresponding count in the array –Go to the next char Returns nothing; answers are in the arrayReturns nothing; answers are in the array –Subsequent function calls add results from other lines Let’s write itLet’s write it 7/6/2016 8R. Smith - University of St Thomas - Minnesota

7/6/2016 9R. Smith - University of St Thomas - Minnesota How do we count word length? When we start a word, it’s 1 char longWhen we start a word, it’s 1 char long When we’re inside a word,When we’re inside a word, –we add another char to the length When we end a word,When we end a word, –we don’t add another char –we save the result Input = White Space Input = other character State = IN Next State = OUT Next State = IN State = OUT Next State = OUT Next State = IN

7/6/ R. Smith - University of St Thomas - Minnesota How do we count word length? When we start a word, it’s 1 char longWhen we start a word, it’s 1 char long When we’re inside a word,When we’re inside a word, –we add another char to the length When we end a word,When we end a word, –we don’t add another char –we save the result Input = White Space Input = other character State = IN Next State = OUT Print the count Next State = IN Increment count State = OUT Next State = OUT do nothing Next State = IN count = 1

7/6/ R. Smith - University of St Thomas - Minnesota

Sample “drawing” function Draw right triangles with nested for loopsDraw right triangles with nested for loops 7/6/ R. Smith - University of St Thomas - Minnesota

7/6/ R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.