Docsity

Study Guide for Exam 2 - Computing for Engineers | CS 1371, Exams of Computer Science

Toggle sidebar
bg1
CS1371 - Computing for Engineers Test 2 Version B June 27th, 2007
1Georgia Institute of Technology
College of Computing
CS 1371 Computing for Engineers
Test 2 Version B - Summer Semester 2007
Page 1 of 17
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
A A A A A A A A A
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
↑ Print your Prism username in the spaces
provided, and shade the boxes of the
corresponding numbers and/or 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):
GT ID# 9 0 ___ ___ ___ ___ ___ ___ ___
Signature:
TA / Section: ____________________________
Prob. Poss.
Pts
Earned
Pts
Lost
Pts by
(cover) - -
1 30
2 25
3 25
4 20
TOTAL 100
Please Note: Failure to complete this front sheet correctly
will cost you 5% of your grade.
Please turn off (or silence) and put away any cell
phones, beepers/pagers, personal radios or music
players that you have in your possession
Good Luck!
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Study Guide for Exam 2 - Computing for Engineers | CS 1371 and more Exams Computer Science in PDF only on Docsity!

1 Georgia Institute of Technology

College of Computing

CS 1371 Computing for Engineers

Test 2 Version B - Summer Semester 2007

0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 A A A A A A A A A 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 ↑ Print your Prism username in the spaces provided, and shade the boxes of the corresponding numbers and/or 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): GT ID# 9 0 ___ ___ ___ ___ ___ ___ ___ Signature: TA / Section: ____________________________ Prob. Poss. Pts Earned Pts Lost Pts by (cover) - - 1 30 2 25 3 25 4 20 TOTAL 100 Please Note: Failure to complete this front sheet correctly will cost you 5% of your grade. Please turn off (or silence) and put away any cell phones, beepers/pagers, personal radios or music players that you have in your possession Good Luck!

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: diag(m) – returns the diagonal elements of the matrix m 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. 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 (x/y/z)label(str) – labels the plot axes with the given string 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(a) – returns the average (mean) value of the vector a mesh(x, y, z) – plot the surface defined by the x, y and z arrays with colored lines and white faces [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 mod(a, b) – the remainder when a is divided by b ones(rows, cols) – generate a matrix filled with 1 p = polyfit(x,y,n) - Finds the coefficients of a polynomial P(X) of degree N that fits the data y = polyval(p,x) - Evaluates the polynomial p, at all points in x prod(v) – compute the product of all the elements in a vector v sin(th) – sin of the angle in radians size(a) – all the dimensions of a sort(v) – arranges the vector 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. sum(v) – total of all the elements in the vector v surf(x, y, z) – plot the surface defined by the x, y and z arrays with colored faces and black lines title(str) – titles the plot with the given string [x, fs] = wavread(file) – gives the waveform and sampling frequency for a .wav file [x, y, z] = xlsread(filename) - Returns the numeric, text and raw data respectively from an .xls file xlswrite(filename, array) - Writes the array to the .xls file
  1. x = -3:.1:3; y = x; [xx yy] = meshgrid(x,y); zz = xx.^2+yy.^2; surf(xx,yy,zz) When the above code is run, what is the result? A. B. C. D.
  2. Given the following MATLAB code A = [3 5 1; 4 1 2;1 12 1]; b = [2; 10; 5]; c= inv(A)b; Which of the following will generate error(s)? A. d = sum(c) B. c(5) = 2 C. c(2) = [ ] D. f = c + [1 2 3] E. A = b . A

Problem 2 – Debugging [2 5 Points]

The following is a piece of MATLAB code produces the rotation about x-axis for the function z(x) = x^2. The function rotates 180 degrees. However, the code below contains errors in five lines. Find all the errors and correct them on the answer sheet. *_ There might be more than one error in a line.

  • You may only correct five lines. Points will be deducted if more than five lines are being marked or corrected._** LN 1- a = 0:.1:5; 2- b = linspace(0,200,2pi); 3- [aa bb] = mesh(a,b); 4- rr = aa^2; 5- xx = aa; 6- yy = rr.sin(bb); 7- zz = rr.*cos(bb); 8- surf(xx,yy,zz) 9- title{'Rotation about x'} 10- shading smooth

Answer Sheet ( circle error if there’s an error )

1- error ____________________________________________________________ 2- error ____________________________________________________________ 3- error ____________________________________________________________ 4- error ____________________________________________________________ 7- error ____________________________________________________________ 8- error ____________________________________________________________ 9- error ____________________________________________________________ 10- error ____________________________________________________________

Problem 4 – Coding [2 0 Points]

You are the manager of a warehouse. The warehouse just had a big sale in the past three days. Your employees gave you an excel spreadsheet that contains the numbers of items sold each day in the format as seen below. You want to know how much each item had been sold in the past three days. Write a MATLAB function which modifies the spreadsheet and creates a new excel file containing only the total amount had been sold for each item. Also, rename your new file with “New” in front of your original file name. For example, if your original file name is “Sale.xls”, the new file name should be “NewSale.xls” _The list may not necessarily contain five items._* function ThreeDaySale(xlsfile) %% Your code goes here... Your original file looks like: Day 1 Day 2 Day Item1 32 12 67 Item2 0 12 3 item3 12 12 76 item4 23 12 56 item5 0 12 0 Your new file looks like: Total Item1 111 Item2 15 item3 100 item4 91 item5 12

The following questions are EXTRA CREDIT!!!

Don’t start this section unless you finish your test.

Q1. Imagine you were responsible for teaching a friend, who knew nothing about programming, about variables.

  • What two things about variables should they understand before they get started?
  • What two common mistakes in using variables would you want to warn them about? Q2 x = 10; y = 15; z = 20; x = y; z = x * z; y = 50; x = x + x; y = z / y; What are the values of x, y, and z after the code above executes?

Q6 if 1 fprintf('Bulldogs drool\n'); else fprintf('Go Jackets!\n'); end if 2 fprintf('Bulldogs drool\n'); else fprintf('Go Jackets!\n'); end Write code fragments to fill in blanks 1 and 2 such that the output is: Bulldogs drool Go Jackets! Each of the code fragments must use both of the values ‘true’ and ‘false’ and must contain two or more of the following logical operators:

  • &&
  • ||
  • ~

Q7. Imagine you were responsible for teaching a friend, who knew nothing about programming, about the if statement.

  • What two things about the if statement should they understand before they get started?
  • What two common mistakes in using the if statement would you want to warn them about? Q8 x = 2; y = 16; if y >= x if x < y x = x * x; else y = x + y; end end if x >= y if x <= y x = x + 1; else y = y + y; end else x = x * x; end if x <= y y = x + y; end fprintf('x = %d\n', x); fprintf('y = %d\n', y); What is the output of this code?

Q10 for i = 1 : 10 fprintf('Number %d\n', i); end In your own words, explain what the computer does when it executes the code above. Q11 n = 5; sum = 0; for i = 1 : n for j = 0 : (i - 1) sum = sum + j; end end What are the values of i, j, and sum after the code above executes?

Q12 n = 4; for 1 for 2 fprintf('%d', 3); end fprintf('!\n'); end Write code fragments to fill in blanks 1, 2, and 3 to complete the code above such that the output is: 1! 22! 333! 4444! Q13 Imagine you were responsible for teaching a friend, who knew nothing about programming, about while loops.

  • What two things about while loops should they understand before they get started?
  • What two common mistakes in using while loops would you want to warn them about?

This page intentionally left blank for any extra work.