March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class RecapRecap Functions and CFunctions and C Using FunctionsUsing Functions.

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 R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Tomorrow’s ExamTomorrow’s Exam Today’s LabToday’s Lab SortingSorting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting.
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 End of Chapter 2: READ Section 2.15End of Chapter 2: READ Section.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The ProjectThe Project PointersPointers.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Class projectsClass projects Lab 13: Use the method documentation.
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 /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Exam ReviewExam Review Arithmetic - I think everyone gets thisArithmetic.
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 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 /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class MethodsMethods Problem solving by decompositionProblem solving by.
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 230: Today in Class Buttons: Radio and Check BoxButtons: Radio and Check Box Lab 20Lab.
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 /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.
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.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Computer HardwareComputer Hardware Recap: next programRecap: next program.
CPS125.
Presentation transcript:

March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class RecapRecap Functions and CFunctions and C Using FunctionsUsing Functions Defining FunctionsDefining Functions Problem Solving with DecompositionProblem Solving with Decomposition Shelf Example (Lab 7)Shelf Example (Lab 7) Lab 10Lab 10

March R. Smith - University of St Thomas - Minnesota Functions and C All C programs are functionsAll C programs are functions –‘main’ is a function and we always start from there We call functions to do ‘outside’ workWe call functions to do ‘outside’ work –Math library, I/O library (printf, scanf) Functions make the work easierFunctions make the work easier –We can break programs into smaller pieces – easier to write –If a function works, we can reuse it without touching it Each time we touch/change something, we might break itEach time we touch/change something, we might break it

March R. Smith - University of St Thomas - Minnesota Using Functions What are examples of functions we use?What are examples of functions we use? How do we use them?How do we use them? What does ‘main’ mean?What does ‘main’ mean?

March R. Smith - University of St Thomas - Minnesota Using Functions Example functions: printf, scanfExample functions: printf, scanf –Some in class have used “pow” and “ceil” Most functions take a list of “parameters”Most functions take a list of “parameters” –Also called arguments –Tailors the result to specific input parameters Most functions ‘return’ a valueMost functions ‘return’ a value –pow(x,y) returns the result of x raised to the yth power –main returns an int, usually zero (it’s generally ignored) ‘main’ as a function‘main’ as a function –Declared an ‘int’ function and usually returns a 0 –No argument list: “(void)”

March R. Smith - University of St Thomas - Minnesota Defining Functions It’s safest to declare functions BEFORE ‘main’It’s safest to declare functions BEFORE ‘main’ –Not always essential, but it generally works best –Why? Because then the compiler ‘knows’ the function before it has to use the function What’s in the declaration?What’s in the declaration? –Consider ‘main’

March R. Smith - University of St Thomas - Minnesota Defining Functions HeaderHeader –Data type returned “int” –Function’s name “main” –Parameter list in parentheses A list of variable declarations, separated by commasA list of variable declarations, separated by commas Actual contents are in curly bracesActual contents are in curly braces –Just like main –Contents are “invisible” to other functions, –EXCEPT through passing arguments and results Always do a ‘return’ to match the headerAlways do a ‘return’ to match the header

March R. Smith - University of St Thomas - Minnesota How do we pass arrays? What does the function get when we pass an array?What does the function get when we pass an array? How do we signal the size of an array?How do we signal the size of an array? –What did we talk about yesterday?

March R. Smith - University of St Thomas - Minnesota How do we pass arrays? The function gets the array’s location in RAMThe function gets the array’s location in RAM The array must indicate its end somehowThe array must indicate its end somehow –Option: provide second parameter with the array size –Option: put a ‘sentinel’ at the end of the array, like in strings

March R. Smith - University of St Thomas - Minnesota Problem Solving with Decomposition How do you solve a really big problem?How do you solve a really big problem? How can we divide up a programming problem?How can we divide up a programming problem?

March R. Smith - University of St Thomas - Minnesota Decomposing a Problem Make a list of the things we must doMake a list of the things we must do Identify inputsIdentify inputs Identify outputsIdentify outputs Identify calculations to yield those outputsIdentify calculations to yield those outputs Each step above might make a good functionEach step above might make a good function –Or parts of those steps might make good functions –If a job is isolated from other data and likely to be used more than once, then it should probably be a function

March R. Smith - University of St Thomas - Minnesota Decomposition and Functions The ‘tricky part’ is in variablesThe ‘tricky part’ is in variables –It’s easy to send data in (using the parameter list) –It can be hard to get data out “Good” decomposition“Good” decomposition –Minimize the number of variables and results passed back and forth between ‘main’ and the functions –Sometimes we just have to figure out what the ‘right’ functions are to put in their own separate places –To I/O or not to I/O – a major decision for a function Don’t do I/O unless that’s the point of the functionDon’t do I/O unless that’s the point of the function Pass results out via arguments instead – more generally usefulPass results out via arguments instead – more generally useful

March R. Smith - University of St Thomas - Minnesota Decomposition should make things easier Shorter functionsShorter functions Fewer variables in individual functionsFewer variables in individual functions Fewer loops in individual functionsFewer loops in individual functions If a function is simpler, then…If a function is simpler, then… –It’s easier to read and understand –it’s easier to debug

March R. Smith - University of St Thomas - Minnesota Decomposition Hassle Factors Extra typing for separate headers and suchExtra typing for separate headers and such Requires thought and planningRequires thought and planning If you get a parameter list wrong, you may have to fix things in several different placesIf you get a parameter list wrong, you may have to fix things in several different places

March R. Smith - University of St Thomas - Minnesota Shelf Example (Lab 7) Let’s analyze the problemLet’s analyze the problem Let’s identify some proceduresLet’s identify some procedures Putting some procedures in Lab 7Putting some procedures in Lab 7

March R. Smith - University of St Thomas - Minnesota Looking at Lab 10 Example: the minimum functionExample: the minimum function Inputs? Outputs?Inputs? Outputs? Header?Header?

March 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.