Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Q1 Academic Integrity

0 Points

This exam is a closed-book, closed-note examination. As the student taking this exam you hereby agree to the following restrictions:

1. You are not allowed to use any other software program other than the browser you are using to take the exam.

2. Your browser will only be used to access the exam and will not have any other tabs or windows open to any other website than the exam.

3. You will only be allowed to use one device during the exam, which is the device you are using to access the exam website.

4. No other outside resources are available to use during this exam.

5. You may not discuss (all or in part) any portion of this exam with any person other than the Instructor and TA's for this course.

6. If it has been determined that you have violated any Academic Integrity Rules set    forth by the class policies or University Policies, you will be reported to SJACS and a recommendation of "F in the course" will be the minimum recommended

sanction.

I agree

I disagree (your exam will receive a score of 0 automatically)

Q2 MATLAB Fundamentals

4 Points

Q2.1

2 Points

Where can we look at all the variables and their values?

Command Window

Current Folder

Command History

Workspace

Q2.2

2 Points

What commands would you include at the top of a script file so that the workspace and command window are empty at the start of your script?

close()

clear

exit

clc

quit()

Q3 Vectors and Arrays

4 Points

Q3.1

3 Points

Write some code that will create a variable named myArr which contains random integers from -10 to 10 inclusive in a 5x5 array. Do this using only a single assignment statement.

myArr = randi([-10,10],5,5);

Q3.2

1 Point

Imagine you have a variable named unknownArray . If you wanted to determine the number of columns of the array, which function(s) would be appropriate to call:

size()

length()

numel()

dimensions()

Q4 Conditionals

9 Points

Q4.1

5 Points

Write code that asks the user for their name and determines if their name has more than 5 characters in it. See sample below for output:

Sample Output 1:

Please enter your name: Raymond

Your name has more than 5 letters in it!

Sample Output 2:

Please enter your name: Jim

Your name has 5 or fewer letters in it!

name = input('Please enter your name: ','s');

if length(name) > 5

fprintf('Your name has more than 5 letters in it!\n')

else

fprintf('Your name has 5 or fewer letters in it!\n')

end

Q4.2

2 Points


Select the correct answer to the following statement:

Every if/elseif/else conditional block can be rewritten as a switch conditional block.

True

False

Q4.3

2 Points

If the following code is executed, what will be shown in the command window?

x = 15

if x > 10 and x < -1

fprintf("One\n")

elseif x < 5 or x ~= 7

fprintf("Two\n")

else

fprintf("Three\n")

end

Two

Q5 Loops

9 Points

Q5.1

2 Points

What is the difference in how a while loop and for loop are controlled?

The for loop requires a specified loop control variable to determine all executions.

The while loop executes until the given condition becomes false.


Q5.2

3 Points

For the Website Login Attempts example that was presented in class, why did we use a while loop instead of a for loop?

Because when an attempt fails, we want to start over rather than finish.

Q5.3

4 Points

Write a while loop that prints all the odd numbers from 1-20

n = 1;

while n <= 20

if rem(n,2) == 1

fprintf('%d\n',n)

end

n = n+1;

end

Q6 Cells and Structures

6 Points

Q6.1

2 Points

What is the data type of the val in the code below:

c = {1, 3, 'char array', "this is my string", [3, -1, 2]};

val = c(3)

cell

Q6.2

2 Points

How does a struct store data?

In an array

  In elds

In cells

In strings

Q6.3

2 Points

Which of the following statements would get the 6th character from the string scalar variable s ?

   s(6)

s{1}(6)

s{6}

s.6

s{1}(5)

Q7 Functions

12 Points

Q7.1

2 Points

What are the fundamental differences between scripts and functions?

Scripts have variables

Functions have a function definition line

Functions have Help Lines

Functions can have inputs

Scripts can be used anywhere

Functions can have outputs

Functions can use the error function

Q7.2

2 Points

Which of the following functions would you use to check if the variable in is a         numeric, scalar, integer value. Select the combination of functions that would validate all the conditions.

isinteger()

isnumeric()

length()

floor()

ischar()

isstruct()

max()

sum()

Q7.3

8 Points

Write a function that adds two values together. The function should be called add and should take in two inputs. Both inputs should be numeric. Both inputs should be        scalars. Both inputs are required. Throw appropriate errors if the inputs are not valid. If the inputs are valid, return the sum of the two values. See sample output:

FUNCTION CALL               RESULT

add('a', 'b')                 ERROR

add([1, 2], 1)            ERROR

add(1, [1, 2])             ERROR

add(1)                       ERROR

add(1, 2)                      3

function c = add(a,b)

if nargin ~= 2

error('ERROR: Must Two inputs!')

end

if ~isnumeric(a) || ~isscalar(a)

error('ERROR: Wrong Input')

end

if ~isnumeric(b) || ~isscalar(b)

error('ERROR: Wrong Input')

end

c = a+b;

end

Midterm Practice                                                  Ungraded

Student

Alice Su

Total Points

- / 44 pts

Question 1

Academic Integrity

Question 2

MATLAB Fundamentals

2.1       (no title)

2.2       (no title)

Question 3

Vectors and Arrays

3.1       (no title)

3.2       (no title)

Question 4

Conditionals

4.1       (no title)

4.2       (no title)

4.3       (no title)

Question 5

Loops

5.1       (no title)

5.2       (no title)

5.3       (no title)

Question 6

Cells and Structures

6.1       (no title)

6.2       (no title)

6.3       (no title)

Question 7

Functions

7.1       (no title)

7.2       (no title)

7.3       (no title)