41
1

1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Embed Size (px)

Citation preview

Page 1: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

1

Page 2: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Difference between computers and calculators

John creates a new device. It will compute the orbit of all the planets in the solar system simultaneously. Since it won’t do anything else, he hopes to one day make another machine that will compute the orbit of the stars in the Milky Way.

Is John’s current device a computer? a calculator?

2

Page 3: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Software, Hardware, and Media

Provide a simple definition for software.

What classification is a DVD?

3

Page 4: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Software: OS, apps, compilers

Describe the purpose of a compiler.

What differentiates the Operating System (OS) from an application (app)?

4

Page 5: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Language generations

Sort the following languages in order of generation, low to high:

English

MATLAB

Machine

Assembly

5

Page 6: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

What piece of hardware is the basis for modern computers?

Why do say that computers work in "binary"?

Page 7: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

5-step Process:

Identify and describe the five steps for this problem:

I need a computer program that will compute the volume of any right regular prism with 10 sides or less.

7

Page 8: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

8

Exam Topics

Developing SolutionsI/O Diagrams5-Step Process

State the ProblemIdentify inputs & outputsManually solve the problemComputerize: Algorithm & codeTest, test, test!

SyntaxSemantics

Page 9: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

9

Exam Topics

Developing Solutions

Page 10: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

10

Exam Topics

Developing Solutions

Page 11: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

I/O Diagrams

Prepare an I/O diagram for the program desired:

I need a program to compute the time required to get to Mars and how much fuel is needed, assuming I leave six months from the day the program is run.

11

Page 12: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

• Know variable and file naming constraints

• Understand the functions listed in the lecture notes [e.g. sin() , cos() , sind() , cosd() , sqrt() , etc] – know the difference between sin() and sind(), for example.

• What is ans?

• What does clear do?

• What about clc?

• How do you suppress default output? 12

Page 13: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

A data type is a category of information. The data type determines how information is stored in the computer and how it can be used.

• Integerswhole numbers

• Floatsnumbers with fractional portion

• Stringssequences of characters

13

Page 14: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

14

Exam Topics

Starting with MATLAB

Page 15: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

15

Exam Topics

Starting with MATLAB

Page 16: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

16

Exam Topics

I/O

Page 17: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

17

Exam Topics

Input and Output

The input() function

What is a "prompt"?

"Collecting the return value"

Strings vs. Numbers

The disp() function

Page 18: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

The input function:Provide the MATLAB code that will use the input() function to obtain from the user the cost (in dollars) for an item, storing the information in the variable cost_per_item.

Provide the MATLAB code that will use the input() function to obtain from the user the name for an item, storing the information in the variable item_name.

18

Page 19: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Simple output: disp()

Tricky question: Use the disp() function to display the

value of π to four decimal places.

19

Page 20: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

20

Exam Topics

Input and Output

The fprintf() function

The format string

Placeholders

Format modifiers

left justification

width specifier

precision specifier

Escape sequences

Page 21: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Formatted output: fprintf()

fprintf(‘%11s said he made $%-7.2f/year\n’, name, paycheck);

From the MATLAB command above, identify …

All placeholders

All format modifiers

All escape sequences

21

Page 22: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Using fprintf() and the provided variables for the red portions, provide the MATLAB statement that will display this sentence:

_ _ _ _John wants Jill_ _ _ to run up the hill 16 times

(where _ indicates a blank space)

A = ‘John’B = ‘Jill’C = ‘up’D = 4

22

Page 23: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Assuming the variables used are name, age, and income, provide an fprintf() statement that contains no spaces and will align the columns for any line in the table.

Fred Flintstone 47$100000.32

Barney "The Man" Rubble 148 $ 3.25

Page 24: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Unary vs Binary operators&, &&, |, ||, +, -, *, /, ~, <, =, ==

From the set of operators above…

Which one(s) can be used as either unary or binary operators?

Which one(s) are only unary operators?24

Page 25: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Numeric: Identify each of these operatorsMultiplication (scalar)Multiplication (matrix)Division (scalar)Division (matrix)Addition (scalar)Addition (matrix)Subtraction (scalar)Subtraction (matrix)Exponentiation (scalar)Exponentiation (matrix)Assignment

25

Page 26: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Name these operators:

Relational<, >, <=, >=, ==, ~=

Boolean&&, ||,

~

Know the true and false keywords26

Page 27: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

27

Exam Topics

Operators

Page 28: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Functions

name = input(‘Enter a username:\n’, ‘s’);

In the MATLAB statement above, which symbol(s) indicate…

- the arguments

- collecting return values

- the function call

28

Page 29: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

Modulus

How would you determine if a user-provided value (stored in the variable x) is divisible by 17?

29

Page 30: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

30

Exam Topics

Conditionals

The IF statement

What is the purpose of the IF statement?

When should we choose an IF over a SWITCH?

Do IF statements repeat?

What code can go in IF, ELSEIF, and ELSE clauses?

Page 31: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

IF / ELSEIF / ELSE:

Construct an IF statement that will print ‘Yes’ if the shuttle will launch; ‘No’ if the shuttle will not launch; ‘Maybe’ if it is unsure. Use a variable of your own choosing.

31

Page 32: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

32

Exam Topics

ConditionalsBoolean expressions

Using &&, ||, and ~

What is the output of this code?a = true;b = 1;c = -4;if a && ~(b>c)

disp('IF');else

disp('ELSE');end

Page 33: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

33

Exam Topics

Conditionals

Page 34: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

34

Exam Topics

ConditionalsBoolean expressions

Can we do this?if a == 1 || 2 || 3

disp('Yes');else

disp('No');end

How about:if 0 < a < b

Page 35: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

35

Exam Topics

Conditionals

The SWITCH statement

What is the purpose of the SWITCH statement?

When should we choose an SWITCH over an IF?

Do SWITCH statements repeat?

What goes after the word "switch"?

What code can go in the cases?

Page 36: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Exam Topics

SWITCH / CASE:

Provide a SWITCH-CASE statement that will process the menu below. Use a variable of your own choosing.

Press 1 to Jump

Press 2 to Duck

Press anything else to walk forward

36

Page 37: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

37

Exam Topics

Library Functions

What is a function?

Why use functions?

What are library functions?

Page 38: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

38

Exam Topics

Library Functions

What is a function call?

What is an argument?

What is a return value?

Can we have more than one?

What does it mean to "collect" the return value?

Must we provide arguments?

Must we collect the return value?

Page 39: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

39

Exam Topics

Library Functions

Page 40: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

40

Exam Topics

Nesting

What does this mean?

What can we nest?

What syntax issue should we watch?

Page 41: 1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system

Review for Exam 1

End of Presentation