Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse.

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse."— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse Statement Lab 7Lab 7

2 March 2005 2R. Smith - University of St Thomas - Minnesota Nested For Loops What makes a For loop work?What makes a For loop work? Mixing two loops togetherMixing two loops together Multiplication table exampleMultiplication table example

3 March 2005 3R. Smith - University of St Thomas - Minnesota IF Statements What’s the idea? Skipping stepsWhat’s the idea? Skipping steps Syntax: if (test) thing-to-do;Syntax: if (test) thing-to-do; –If test fails, thing-to-do is skipped –If it succeeds, it’s executed Relational operatorsRelational operators –== and != – and =

4 March 2005 4R. Smith - University of St Thomas - Minnesota Examples Get ‘absolute value’Get ‘absolute value’ –Eliminate the minus sign –Rectangle length of side regardless of order Collect a value and test for over/underCollect a value and test for over/under –Grade pass/not pass –Overtime calculation (work more than 8 hours)

5 March 2005 5R. Smith - University of St Thomas - Minnesota Boat Problem: Almost Lab 7 Custom boat: collect the length and width, number of seatsCustom boat: collect the length and width, number of seats Length is at least 3x width, fix width if wrongLength is at least 3x width, fix width if wrong Length is no more than 5x width, fix width if wrongLength is no more than 5x width, fix width if wrong Number of seats is no more than 1/3 lengthNumber of seats is no more than 1/3 length Cost per seat is $53Cost per seat is $53 Boat’s cost is L x W x $87 + cost of seatsBoat’s cost is L x W x $87 + cost of seats

6 March 2005 6R. Smith - University of St Thomas - Minnesota IF-Else clause ‘else’ can follow an ‘if’’ clause‘else’ can follow an ‘if’’ clause –Executed if the ‘if’ test fails –Skipped if ‘if’ succeeded ExampleExample –Print ‘number is even’ if even –Print ‘number is odd’ if odd

7 March 2005 7R. Smith - University of St Thomas - Minnesota Overview of Lab 7 Calculating size and cost of custom shelvingCalculating size and cost of custom shelving Collect shelf length and total lengthCollect shelf length and total length Fix the shelf length to meet the constraintsFix the shelf length to meet the constraints Calculate the # parts you needCalculate the # parts you need Use “%” (remainder) to see if you must round the number of shelves upUse “%” (remainder) to see if you must round the number of shelves up

8 March 2005 8R. Smith - University of St Thomas - Minnesota

9 March 2005 9R. 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 http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse."

Similar presentations


Ads by Google