March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures Lab 13Lab 13
March R. Smith - University of St Thomas - Minnesota Grades etc Class average a B+Class average a B+ –Lower grade = missing homeworks –Test score also a factor Lab 12Lab 12 –Formatting is generally OK –Pay attention to commenting! –Function organization in this assignment 0-1 loop per function0-1 loop per function Which one has 0 loops?Which one has 0 loops? What arguments to the average?What arguments to the average?
March R. Smith - University of St Thomas - Minnesota Upcoming Exam It’s coming up too soonIt’s coming up too soon Any objection to delaying it?Any objection to delaying it? –I prefer Tuesdays (review on Monday) – April 8 or 15 Then it coversThen it covers –Functions –Structs –Strings
March R. Smith - University of St Thomas - Minnesota “Structs” Defines a grouping of variablesDefines a grouping of variables Textbook example: dateTextbook example: date If we use an array to specify the date, how would we do it?If we use an array to specify the date, how would we do it? –Order? –Remembering the Order
March R. Smith - University of St Thomas - Minnesota Defining a struct struct date {struct date { –... list of variable declarations } foo1;} foo1; –Defines the format; creates a ‘date’ variable named ‘foo1’ –The variable name is optional – only if you need one right then. After that, declare additional struct variables by just saying:After that, declare additional struct variables by just saying: struct date foo2, foo3;struct date foo2, foo3; –Declares two “name” variables: foo2, foo3 –You don’t have to repeat the declarations “inside” the struct
March R. Smith - University of St Thomas - Minnesota Incrementing from Today to Tomorrow Start with the easy wayStart with the easy way Incorporating the hard parts incrementallyIncorporating the hard parts incrementally Thinking aheadThinking ahead –What are the hard parts? Solving the problem step by stepSolving the problem step by step
March R. Smith - University of St Thomas - Minnesota Structs with other C elements ArraysArrays –You can define arrays of structs –You index as usual and add the “.” suffix at the end FunctionsFunctions –Structs can be parameters –Structs can’t normally be results –Arguments and results must be standard sized data items I.e. size of long long at most;I.e. size of long long at most; –There’s a trick: pass the address of the struct; –Return the address of the struct if necessary
March R. Smith - University of St Thomas - Minnesota Lab 13 Use a ‘struct’ to validate numeric datesUse a ‘struct’ to validate numeric dates Convert the date into a ‘text’ dateConvert the date into a ‘text’ date
March R. Smith - University of St Thomas - Minnesota The “months” struct Each element containsEach element contains –Integer with days in the month –Array of 3 chars for the month abbreviation
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.