70 likes | 226 Views
Coding Review for Exam1. Quick Theory review 1/4. Script files are written in the ____________ window Script files allow lines of instructions to be ________. The file extension of a script file in MATLAB is _____. Comments are color-coded in ______.
E N D
Quick Theory review 1/4 • Script files are written in the ____________ window • Script files allow lines of instructions to be ________. • The file extension of a script file in MATLAB is _____. • Comments are color-coded in ______. • Symbols for comment-blocks are __________. • Symbol for single line comment is ___________. • ____ clears the workspace • ____ clears the command window
Quick Theory review 2/4 • Variables are ___________________________________. • What does the variable f contain? • What does the variable i contain? • What does the variable j contain? • Definition of hard-coding? • The programmer HAS values. gravity=9.81; • User input: • The programmer does NOT have values, so the programmer asks the USER for values. variable =input(‘prompt string’); variable =input(‘prompt string’, ‘s’);
Quick Theory review 3/4 • Output to the command window • Omit the ________________. Perfect for checking/degubbing. • Want a formatted output? • Punctuation • Capital/lower case letters • Include units in the result • Use sentences to show results • Specific number of decimals • Spacing, tabbing, alignment, new lines • Use ____________. • Don’t want the “variable name =” to show? Use the function ________.
Quick Theory review 4/4 • Tell the code to skip lines? Use the keywords ____ and ____ for sure, and possibly ______ and _____ if needed. The location of these keywords is extremely important. They tell MATLAB where to skip to when condition(s) are true/false. • NO semi-colons on lines with bluekeywords. Excellent habit for future programming languages you may encounter. • Really think of the algorithm in detail, so you may code less conditions. • Leave the else alone! • The relational operators are: < > <= >= ~= and == • The arithmetic operators are: +-/ \^ • The Boolean operators are: || && All this takes practice…
Find the mistakes A program is provided, along with a description of the intended purpose of the program. However, this program isn’t perfect: There are some number of errors intentionally distributed throughout the program. Identify all errors. Note: Because of the potentially-debatable rules of style, no errors are style-only. Errors are either syntax errors or logic errors, both of which affect the ability of the program to execute as-intended.
Is it safe? 1) Determine if the roof truss is safe? The truss design configuration below is only safe if the vertical height is less than or equal to 1.5 times the horizontal length. Prompt user for the height and the length. Indicate any invalid inputs (negative or zeros) or if unsafe truss. If safe, indicate the dimensions of each piece of wood below. (?) a? h b? c? d=2/3*L=? L