Docsity

CS1371 - Computing for Engineers Test 1 - Prof. David Smith, Exams of Computer Science

Toggle sidebar
bg1
CS1371 – Computing for Engineers Test 1 Version C1 February 4, 2009
Georgia Institute of Technology
College of Computing
CS 1371 Computing for Engineers
Test 1 Version C - Spring Semester 2009
A A A A A A A A A Print your T-Square username in the spaces
provided, and shade the boxes of the
corresponding letters.
I hereby signify that this examination paper
contains my own work exclusively, and I have
neither given nor received inappropriate help
during the taking of this examination, in
compliance with the letter and spirit of the
Academic Honor Code of Georgia Tech.
Name (print):
Signature:
TA / Section: ____________________________
Coding problem (circle which problem you
completed) :
A B
Part Poss.
Pts
Earned
Pts
Lost
Pts Grader
(cover) - -
1 15
2 25
3 40
4 20
TOTAL 100
Please Note: Failure to complete this front sheet correctly
will cost you 5% of your grade.
B B B B B B B B B
C C C C C C C C C
D D D D D D D D D
E E E E E E E E E
F FFFFFFFF
G G G G G G G G G
H H H H H H H H H
I I I I I I I I I
J J J J J J J J J
K K K K K K K K K
L L L L L L L L L
M M M M M M M M M
N N N N N N N N N
O O O O O O O O O
P P P P P P P P P
Q Q Q Q Q Q Q Q Q
R R R R R R R R R
S S S S S S S S S
T TTTTTTTT
U U U U U U U U U
V V V V V V V V V
W W W W W W W W W
X X X X X X X X X
Y Y Y Y Y Y Y Y Y
Z ZZZZZZZZ
Regrade Request:
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CS1371 - Computing for Engineers Test 1 - Prof. David Smith and more Exams Computer Science in PDF only on Docsity!

CS1371 – Computing for Engineers Test 1 Version C1 February 4, 2009

Georgia Institute of Technology

College of Computing

CS 1371 Computing for Engineers

Test 1 Version C - Spring Semester 2009

A A A A A A A A A (^)  Print your T-Square username in the spaces provided, and shade the boxes of the corresponding letters. I hereby signify that this examination paper contains my own work exclusively, and I have neither given nor received inappropriate help during the taking of this examination, in compliance with the letter and spirit of the Academic Honor Code of Georgia Tech. Name (print): Signature: TA / Section: ____________________________ Coding problem (circle which problem you completed) :

A B

Part Poss. Pts Earned Pts Lost Pts Grader (cover) - - 1 15 2 25 3 40 4 20 TOTAL 100 Please Note: Failure to complete this front sheet correctly will cost you 5% of your grade. B B B B B B B B B C C C C C C C C C D D D D D D D D D E E E E E E E E E F F F F F F F F F G G G G G G G G G H H H H H H H H H I I I I I I I I I J J J J J J J J J K K K K K K K K K L L L L L L L L L M M M M M M M M M N N N N N N N N N O O O O O O O O O P P P P P P P P P Q Q Q Q Q Q Q Q Q R R R R R R R R R S S S S S S S S S T T T T T T T T T U U U U U U U U U V V V V V V V V V W W W W W W W W W X X X X X X X X X Y Y Y Y Y Y Y Y Y Z Z Z Z Z Z Z Z Z Regrade Request:

Academic misconduct (including - but not limited to - examples on the list below) could result in a zero score on this examination, an “F” final grade in the course, and/or other disciplinary action:  Failure to cooperate with or follow directions given by a proctor.  Failure to stop writing when the allotted time is up (as reported by a proctor).  Communication with anyone other than a proctor for ANY reason in ANY language in ANY manner.  Sharing of ANYTHING (e.g. pencils, erasers, paper).  Writing on paper that is not given to you by a proctor.  Using cell phones, beepers, personal radios or music players, etc. during the exam.  Using calculators (unless explicitly permitted) or hand-held computers during the exam.  Using books or other reference material during the exam.  Disruption of the exam setting. Reference Section: all(x) – checks if all of the elements of x are true any(x) – checks if any of the elements of x are true char(a) – converts a to class char class(a) – returns the class of a diag(m) – returns the diagonal elements of the matrix m double(a) – converts a to class double (numeric) factorial(n) – returns n! find(m) – returns the indices of the true elements of m image(x) - display the image from the matrix x. imread(filename) - returns a matrix representation of an image newy = interp1(x,y,newx) - Interpolates to find newy, the values of the underlying function Y at the points in newx. isa(a, b) – checks if a is of class b iscell(a) – checks if a is of class cell (a cell array) ischar(a) – checks if a is of class char (a string) isempty(here) – checks if here is null (usually represented by [], the empty vector islogical(a) – checks if a is of class logical (a Boolean) isnumeric(a) – checks if a is of class double (numeric value) length(a) – largest dimension of a magic(n) – builds a n * n magic square max(a) – value and index of the max value in a mean(v) – returns the average value of v [xx, yy] = meshgrid(x, y) – compute the plaid from the x and y vectors min(a) – value and index of the min value in a mod(a, b) – the remainder when a is divided by b num2str(x) – converts numbers to a string ones(rows, cols) – generate a matrix filled with 1 prod(v) – compute the product of all the elements in a vector v rand(n, m) – produces an n by m array of random numbers between 0 and 1 sin(th) – sin of the angle in radians size(a) – all the dimensions of a sqrt(a) – gives the square root of a sort(v) – arranges v in ascending numerical order newy = spline(x,y,newx) - Performs cubic spline interpolation to find newy, the values of the underlying function Y at the points in newx. strcmp(a, b) – Compare strings a and b strcmpi(a, b) – Compare strings a and b ignoring case sprintf - Write formatted data to string sum(v) – total all the elements in the vector v zeros(rows, cols) – generate a matrix filled with 0

Part 2 – Tracing Problems [25 points]

Given: a = [1 5 3 9 8 2 6 7 4] b = sum(mod(a,2)) c = double((a>2)&(a<7)) d = max(a)/length(a) e = (a(1) .* rand(1,1)) > 1 arr = {‘cs1371’,47,[4 3 2], 432, true, [false false]} f = length(arr) g = class(arr(3)) a(2) = [] After the above code is run, what are the final values of the following variables? a: b: c: d: e: f: g: If one wants to view information about how to use the linspace command in MATLAB, what should be typed at the Command Window? What symbol should be added to the end of a line to suppress Command Window output of the result?

Part 3 – Coding Problems [40 points]

Complete the following coding questions. Questions 1-4 are short-coding which are not functions. Question 5 does require you to write a function.

  1. Given a vector, nums, write a script which stores how many numbers in the vector are evenly divisible by the number preceding it in the vector (ignoring the first element) in the variable count. Example: if nums = [3 6 30 5 2 8 ] then count would equal 3.
  2. Given a string, str, write a script which counts how many uppercase letters between ‘E’ and ‘S’ inclusive are contained in the string. Store the answer in a variable called count. You may not use the isUpper or isLower functions.
  1. Write a function, myColon, which takes in a starting value (double), an increment (double), and a maximum value (double). The function should output the same vector which would be created by the colon operator (i.e., vec = start:increment:maxvalue should be the same as vec = myColon(start,increment,maxvalue) ). Note: you may not use the colon operator or linspace command. Example: vec = myColon(3,4,16)  vec: [3,7,11,15]

Part 4 – Debugging [20 pts]

For each line of the following code, if the line will produce an ERROR in MATLAB, mark “Error” and write a corrected version of the line in the space provided. Otherwise, mark “No Error” and leave the line blank. Consider each line individually (errors in earlier lines do not affect errors in later lines). NOTE: Only mistakes which will cause RED error messages in the command window should be considered Errors! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function out1, out2 = cell2str(ca) out1 = 10:1; for index=1:(length(ca)-1) switch class(ca[index]) case ‘char’ out1 = [out1 ca{index}]; case ‘double’ out1 = [out1 num2str(ca{index})]; case logical out1 = [out1 char(double(ca{index}) + double(‘0’))] else out1 = [out1 “???”]; end end out2 = length(out1);

  1. No Error Error
  2. No Error Error
  3. No Error Error
  4. No Error Error
  5. No Error Error
  6. No Error Error
  7. No Error Error
  8. No Error Error
  9. No Error Error
  10. No Error Error
  11. No Error Error
  12. No Error Error
  13. No Error Error
  14. No Error Error
  15. No Error Error

Prob. Solution 1 count = 0 for ind=2:length(nums) if mod(nums(ind),nums(ind-1))== count = count + 1 end end 2 count = sum(str(str>=’E’&str<=’S’)) 3 count = 0 for index=1:length(ca) if islogical(ca{index}) count = count + 1; end end 4 switch var case ‘green’ a = 1; case {‘yellow’,’orange’} a = 2; case 3 a = 3; motherwise a = 4; end 5 function v = myColon(s,inc,f) v = [ ] while s < f v = [v s]; s = s + inc; end