exam 3: review (part 1)

53
Exam 3: Review (part 1) 1

Upload: miles

Post on 18-Jan-2016

26 views

Category:

Documents


1 download

DESCRIPTION

Exam 3: Review (part 1). Test 1 - Outcomes. Computers & Solutions Understand the basic concepts of a computer: the hardware, the software, the different languages. List and follow the steps to solving a problem Apply problem solving approach - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Exam 3: Review (part 1)

Exam 3: Review (part 1)

1

Page 2: Exam 3: Review (part 1)

2

Test 1 - Outcomes

• Computers & Solutions1) Understand the basic concepts of a computer: the hardware, the

software, the different languages.2) List and follow the steps to solving a problem3) Apply problem solving approach4) Identify different strategies to frame problems

• Variables & Data Types1) Identify the different windows in MATLAB2) Create and assign values to variables in MATLAB3) Utilize variables for basic calculations

Page 3: Exam 3: Review (part 1)

3

Test 1 - Outcomes

• Inputs & Outputs1) Give the user the ability to enter words2) Show results to the screen:

a) for the purpose of debugging (i.e. finding errors in the code)b) to show values onlyc) to format a sentence that shows result

• Operators & Conditionals1) Understand 0 and 1. False and True2) Write conditional statements using appropriate operator syntax3) Know and apply the syntax of an if and switch statement:

a) what keywords are mandatoryb) what keywords are optionalc) what order do the keywords go in?

Page 4: Exam 3: Review (part 1)

Review Questions

CPU stands for _______________________.

a. Counter productive unitsb. Central processing unitc. Copper Part Unitd. None of the answers are valid

4

Page 5: Exam 3: Review (part 1)

• A TYPICAL keyboard is considered to be:

a. Input deviceb. Output devicec. Input/output deviced. None of the above

5

www.wikipedia.com

Review Questions

Page 6: Exam 3: Review (part 1)

Review Questions

Which command creates a variable named age, assigns the value 29, and suppresses the output?

a. Age = 29b. age =29c. 29 = age;d. None of the options are valid

6

Page 7: Exam 3: Review (part 1)

Review Questions

Which of the following is NOT a valid variable name?

a. $_moneyb. 2TypesOfRocketsc. Inputd. ie. jf. Name 1

7

Page 8: Exam 3: Review (part 1)

Review Questions

Which of the following are Boolean Operators?How about relational operators?

a. +-*/b. <= >= < > == ~=c. || && ~d. None of the above are valid

8

Page 9: Exam 3: Review (part 1)

Review Questions

Will the following script file allow the user to enter her/his name properly?

clcclearname = input(‘Enter your name’);fprintf(‘Welcome %s!\n’, name);

a. Yesb. No

9

Page 10: Exam 3: Review (part 1)

Review Questions

Will the following script file allow the user to enter her/his name properly?

clcclearname =input(‘Enter your name’,’s’);fprintf(‘Welcome %s!\n’,name);

a. Yesb. No

10

Page 11: Exam 3: Review (part 1)

• What will appear in the command window after executing this code:

z=5;fprintf('The answer is z')

a. The answer is 5b. The answer is zc. The answer is 5.00d. Will return an error.

11

Review Questions

Page 12: Exam 3: Review (part 1)

Review Questions

• What are some methods to display results?• Which method allows to print results with a specific format?• What are the 4 common placeholders?• What is the purpose of placeholders?• Which function actually uses placeholders?• What are format modifiers? • Which placeholder can have a format modifier that controls

the number of decimal places?• If there are 3 placeholders in the control string, how many

variables can be printed to the screen?

12

Page 13: Exam 3: Review (part 1)

Review Questions

• What are the two conditionals shown that allow to skip code?

• Regardless whether it is if or switch, which keyword is always associated with both?

• What other keywords are associated with if?

• What other keywords are associated with switch?13

Page 14: Exam 3: Review (part 1)

Review Questions

Why does the following script result in an error?

clcclearX = input(‘Enter a value: ’);if X = 2

disp(‘2’)else

disp(‘error’)end

14

Page 15: Exam 3: Review (part 1)

Review Questions

• Is each statement valid? Which will create a string?

x = “EGR 115” □ Valid □ Invalid □ String □ Not a string

x = ‘EGR 115’ □ Valid □ Invalid □ String □ Not a string

x = sprintf(‘ %s %d’,class_name,class_num) □ Valid □ Invalid □ String □ Not a string

x = str2num(‘115’) □ Valid □ Invalid □ String □ Not a string

x=num2str(‘115’) □ Valid □ Invalid □ String □ Not a string

X=double(‘EGR’) □ Valid □ Invalid □ String □ Not a string

15

Page 16: Exam 3: Review (part 1)

16

Test 2 - Outcomes

• Library Functions1) Recognize function vocabulary words

a) variable collections, function call, arguments

2) Understand how a function works overall3) Know and apply the functions that can round up/down/w.r.t 0.54) Generate a random value between two specific limits5) Know the syntax of and purposes of the mod() function

• Loops1) Recognize when a loop is useful2) Write and apply the syntax of a for loop and a while loop

appropriately3) Develop an algorithm to solve a problem using a for and while loops4) Understand and apply running totals

Page 17: Exam 3: Review (part 1)

17

Test 2 - Outcomes

• Numerical Methods1) Know when numerical methods are used2) What loops are used and how

• Arrays1) Recognize when an array is useful2) Create scalars, vectors, matrices, transpose3) Use functions on arrays 4) Augment, concatenate, and diminute arrays

Page 18: Exam 3: Review (part 1)

• What are the possible outcomes of the following code

Rand_num= round((rand*4)+6)

a. 6,7,8,9b. 7,8,9,10c. 7,8,9d. 6,7,8,9,10e. None of these

18

Review Questions

Page 19: Exam 3: Review (part 1)

19

Review Questions

Which loop form is best for this client’s demand:“Add up all of the values the user provides, stopping when they’ve entered the known number of values”

a. forb. whilec. ifd. None of these answers are valid

Page 20: Exam 3: Review (part 1)

Review Questions

• What is the running total?sum=0;for k=1:5 sum=sum+k*2;end

• What is the running total?sum=0;for k=1:5 sum=k+k;end

20

Page 21: Exam 3: Review (part 1)

Review Questions

• MATCH:

A. ( ) 1. Access content of a cell in a cell-array

B. [ ] 2. array referencingC. { } 3. creating normal arrays, and

concatenating

21

Page 22: Exam 3: Review (part 1)

Review Questions

• What is a vector( row vector or column vector)?• How to create a vector?• What is a matrix ?• How to create a matrix?• How to refer/replace the element(s) in a vector/matrix?• How to define new columns?• How to define new rows?

22

Page 23: Exam 3: Review (part 1)

Given 1 5 6dataM = 8 9 0

4 3 2

• How do we access/reference element 0?

• How do we extract vector ?

• How do extract vector

• How do we extract matrix ?

• How do we extract matrix ?

[ ]Review Questions

23

Page 24: Exam 3: Review (part 1)

Review Questions

• Will the following operations work? What is the size of the final result?

[1 2 3].*[2 3 4]

[1 2 3]*[3 4 5]

[1 2 3]*[1;2;3]

[1 2;3 4; 5 6]*[5 6; 7 8; 9 0]

[1 2;3 4; 5 6]*[1 2 3;3 4 5]

[1 2;3 4; 5 6].*[5 6; 7 8; 9 0]

24

Page 25: Exam 3: Review (part 1)

25

Test 3 - Outcomes

• File I/O1) Utilize and apply files appropriately2) Know when and how to use dlmread() or xlsread()3) Apply logical operations on arrays

• Dialog Boxes1) Select and apply the appropriate dialog box2) Know how to format dialog boxes3) Know what data type is returned by a dialog box input

• Strings1) Know how to harcode strings2) Know how to prompt the user for strings3) Recognize and apply functions used specifically for strings 4) Know how to compare strings together5) Augment, concatenate, diminute strings

Page 26: Exam 3: Review (part 1)

26

Test 3 - Outcomes

• Functions1) Recognize when and how to apply functions2) Know the syntax of creating and calling functions3) Understand the unique way that data flows in and out of a function4) Create and call functions with multiple inputs and return values5) Know how to ignore return values

• Plotting1) Create arrays to plot data2) Know and apply functions to plot data

• Low Level Files1) Recognize when to use low-level functions 2) Know and apply the commands needed to open, read, write, append, and

close a file

Page 27: Exam 3: Review (part 1)

• Consider the following MATLAB code, and decide which type of data you are collecting

R = xlsread('myFile.xlsx');

a. numericalb. stringsc. Cell arrayd. Choice a & c are correct.

27

Review Questions

Page 28: Exam 3: Review (part 1)

28

Review Questions

Assume the file is the following: What will be the result of this command:>> [x1, x2] = xlsread(‘data.xlsx’)

A?B?

Page 29: Exam 3: Review (part 1)

Review Questions

• inputdlg() accepts its input arguments as ____________

and return a __________ of ___________.

• msgbox() accepts _____________ as its input arguments

29

(data type)

(data type)

(data type)

(data type)

Page 30: Exam 3: Review (part 1)

• What value will be in the variable len after executing this MATLAB code?

a. 10b. 11c. 12d. 13

30

Review Questions

Page 31: Exam 3: Review (part 1)

• After running this MATLAB code, what value will be saved in the variable str_edit

a. Hello Wob. lo Wc. lo Wod. loWo

31

Review Questions

Page 32: Exam 3: Review (part 1)

32

• After running this MATLAB code, what value will be saved in the variable str

a. Hello Worldb. HelloWorldc. [ ]d. Will return an error message

Review Questions

Page 33: Exam 3: Review (part 1)

33

• After running this MATLAB code, what values will be saved in the variable str1 and str2

a. str1: ‘Hello ’, str2: ‘ World’b. str1: ‘Hello’, str2: ‘World’c. str1: ‘Gdkkn’, str2: ‘Vnpkc’d. None of these

Review Questions

Page 34: Exam 3: Review (part 1)

34

What is the value stored in the variable chk chk=strcmp(‘yes’,’Yes’)

a. 0

b. 1

c. [0 1 1]

d. [1 1 1]

e. It cannot be determided

Review Questions

Page 35: Exam 3: Review (part 1)

• What is the value stored in the variable chk chk=strcmpi(‘yes’,’Yes’)

a. 0b. 1c. [0 1 1]d. [1 1 1]

35

Review Questions

Page 36: Exam 3: Review (part 1)

36

What is the value stored in the variable chk chk=strcmp(password, ‘hd93yf8’)

a. 0

b. 1

c. [0 1 1]

d. [1 1 1]

e. It cannot be determined

Review Questions

Page 37: Exam 3: Review (part 1)

• What is the value stored in the variable chk chk= (‘Mark’ == ‘mark’)

a. 0b. 1c. [1 1 1 1]d. [0 1 1 1]

37

Review Questions

Page 38: Exam 3: Review (part 1)

38

• The part that is circled is called:

function W = M (A,B)

a. functionb. Return variablesc. Function named. Parameters

Review Questions

Page 39: Exam 3: Review (part 1)

• The part that is circled is called:

function W = M (A,B)

a. functionb. Return variablesc. Function named. Parameters

39

Review Questions

Page 40: Exam 3: Review (part 1)

40

• The part that is circled is called:

W = MyFun (A,B)

a. Function callb. Return valuesc. Argumentsd. Parameters

Review Questions

Page 41: Exam 3: Review (part 1)

Review Questions

1. The arguments’ names in the function call MUST match the parameters’ name in the function header?

2. In the function header, how many parameter can the function have? How many return values can the function have?

3. Does the number of return values in the function header need to match the number of the collection values in the function call?

41

Page 42: Exam 3: Review (part 1)

• Consider the following MATLAB code, and decide where is the error:

a. The error is in the FIRST line.b. The error is in the SECOND line.c. The error is in the THIRD line.d. The error is in the FOURTH line.

42

Review Questions

Page 43: Exam 3: Review (part 1)

• polyfit() will return the coefficient of the polynomial that best fits the data given.

a. TRUEb. FALSE

43

Review Questions

Page 44: Exam 3: Review (part 1)

• Which of the following built-in function, will CREATE a plot.

a. polyval()b. polyfit()c. xlabel()d. polar()

44

Review Questions

Page 45: Exam 3: Review (part 1)

45

Review Questions

In the following syntax,

__C__= fopen(___A_____, _ B__)

MATCH:_____ The permission string_____ The file’s actual name_____ The file identifier (i.e. cursor position)

Page 46: Exam 3: Review (part 1)

Review Questions

• When using the ‘r’ access-mode (i.e. permission), the initial position of the pointer (i.e. cursor) will be:

A. At the beginning of the fileB. At the end of the fileC. At halfway into the fileD. It will stay where it is (no change from last time the file was

open)

46

Page 47: Exam 3: Review (part 1)

• Assuming that we are reading a text file that includes only one line and we saved it to a variable named str.

• Look at the screenshot below. Can you tell which function was used to read such file:

a. fgetl()b. fgets()c. fget()d. None of the above

47

Review Questions

Page 48: Exam 3: Review (part 1)

• Assuming that we are reading a text file that includes only one line and we saved it to a variable named str.

• Look at the screenshot below. Can you tell which function was used to read such file?

a. fgetl()b. fgets()c. fget()d. None of the above

48

Review Questions

Page 49: Exam 3: Review (part 1)

Review Questions

• Consider the code written below, then answer the following questions:

If a file exists with the same name will it be deleted?

If the files doesn’t exist, will it be created?

49

Page 50: Exam 3: Review (part 1)

50

Review Questions

The file contains the retired hurricanenames, and the year they were retired:

Assume the data has been properly uploaded using textscan() and extracted into Col1, and Col2.Which command(s) would find the year a specific name has been retired? For example: NameUserChose = ‘Lili’;

A. if Col1 == NameUserChosedisp(Col2) end

B. Year = Col2(strcmp(Col1,NameUserChose));

C. Row = find(strcmp(Col1,NameUserChose)); year = Col2(Row);

Page 51: Exam 3: Review (part 1)

51

Review Questions

What code will read this file properly?

Fid = fopen('flightInfo.txt');Headers = fgets(Fid);Numbers = fscanf(Fid,'%d %f %f %f %f',[5, inf])';fclose(Fid);

A. Data = dlmread('flightInfo.txt');

B.

C. [numbers, txt] = xlsread('flightInfo.xlsx');

Page 52: Exam 3: Review (part 1)

52

Review Questions• This data file has 23 columns. Only the 3rd and 9th are needed.

Which command is valid?

A. data = textscan(Fid,'%d %d %d %d %f %d %f %d %f %f %f %f %d %f %f %f %f %f %f %f %f %f %f',[3,Inf]);

B. data = textscan(Fid,'%*d %*d %d %*d %*f %*d %*f %*d %f %*f %*f %*f %*d %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f');

C. data = textscan(Fid,'%*d %*d %d %*d %*f %*d %*f %*d %f');

Page 53: Exam 3: Review (part 1)

53

How to Pass Test 3…

STUDY, STUDY, STUDY

PRACTICE, PRACTICE, PRACTICE

ASK FOR HELP, ASK FOR HELP