Docsity

Solved Problems for Exam 3 - Computing for Engineers | CS 1371, Exams of Computer Science

Toggle sidebar
bg1
CS1371 - Computing for Engineers Test 3 Version A July 18th, 2007
1Georgia Institute of Technology
College of Computing
CS 1371 Computing for Engineers
Test 3 Version A - Summer Semester 2007
Page 1 of 16
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 35
2 20
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 Solved Problems for Exam 3 - 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 3 Version A - 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 35 2 20 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

B. Multiple Choice ( Circle all that apply )

  1. Which of the following will raise the pitch of a sound when it is played? A. Increasing the sampling frequency B. Decreasing the sampling frequency C. Increasing the number of samples D. Decreasing the number of samples E. None of the above
  2. Given the following MATLAB code: dt = 1/400; pts = 10000; f = 8; t = (1:pts)dt; x = sin(2pift); Y = abs(fft(x)); f = (1:pts)2(1/t(end)/2); plot(f,Y) What’s the result of the above code? A. A plot of Power vs Frequency B. A sine wave. C. One peak D. Two peaks with the same magnitude. E. Four peaks with the same magnitude.
  3. Given an image file guess.jpg and the following code. Img = imread(‘guess.jpg’) Which of the following will maximize the blue color in the image? A. Img(:,:,1) = 255; B. Img(:,:,2) = 255; C. Img(:,:,3) = 255; D. Img(:,:,2) = 0; E. Img(:,:,3) = 0;
  1. Which of the following lines of code will produce an error when trying to change the color of an image? x = imread(‘picture.jpg’) A. x(:,:,1) = []; B. x(:,:,4) = 185; C. x(10:20,10:20,3) =0; D. x(10:20,10:20,1:2) = 34 E. None of the above
  2. What is the core concept that enables a recursive function to operate? A. Processing Queue B. Activation Stack C. Building Blocks D. Operation Database E. Calls Itself

Problem 3 – Tracing [2 5 Points]

You are given an image img.jpg. The following is a piece of MATLAB code which modifies the image. img.jpg looks like… pic=imread('img.jpg'); [r,c,l]=size(pic); rmid=r/2; cmid=c/2; temp1=pic(1:rmid,1:cmid,:); pic(1:rmid,1:cmid,:)=pic(rmid+1:end,cmid+1:end,:); pic(rmid+1:end,cmid+1:end,:) = temp1; temp2=pic(1:rmid,cmid+1:end,:); pic(1:rmid,cmid+1:end,:) = pic(rmid+1:end,1:cmid,:); pic(rmid+1:end,1:cmid,:) = temp2; pic(rmid+1:end,:,:) = pic(rmid+1:end,end:-1:1,:); pic(rmid,:,:) = 0; pic(:,cmid,:) = 0; imwrite(pic,'newimg.jpg') Draw the image newimg.jpg in the following box.

Problem 4 – Coding [2 0 Points]

You are to write a function called playSong that will take in a cell array of notes and return a sound vector of the notes with a 1/10 second pause between each note. Assume a sampling frequency of 8000 Hz. You must use recursion. To help, you are given the notemaker function (analogous to the homework question). Below is the help documentation for that function: % NOTEMAKER Produces a sound vector of the note given a string % % Usage: ret = notemaker(str) % str = Input string representing note (i.e. ‘C#’) % ret = Sound vector of note Ex. ret = playSong({‘F’ ‘G’ ‘A’ ‘A#’ ‘C’ ‘D’ ‘E’ ‘F’}) ret will be a sound vector of the F Major scale. function ret = playSong(ca) % Use the function header given above. Your code goes here.

Q18 Write a function grade that calculates a student’s final average for a course based upon the following information:

  • Homework average
  • Homework percentage (e.g., homework counts for 25% of the total score for the course)
  • Lab average
  • Lab percentage
  • Exam average
  • Exam percentage Also, write the function call that you would use in your program to calculate the final grade in this class, where homeworks count for 15% of the final average, labs count for 5% of the final average, and exams count for 80% of the final average. (You do not need to provide your actual grades for homework, labs, and exams. Feel free to provide sample data for a typical student.) Q19 Given the function definition: function nums = multiply(nums, n) for i = 1 : length(nums) nums(i) = nums(i) * n; end And the following code statements: list1 = [1, 2, 3, 4, 5]; multiply (list1, 2); In your own words, explain what the computer does when it executes the code above.

Q20 Given the function definition: function song = sing(name, event) song = ['Happy ', event, ' to ', name]; return; fprintf ('%s\n', song); And the following code statements: banner = 'Happy Birthday'; sing ('Katie', 'Birthday'); fprintf ('%s\n', banner); What is the output of this code? Q21 function abbr = acronym(s) % missing code end Complete the function acronym so that it returns an acronym, a string formed by taking the capital of the first letter of the words in the input string. Return ‘Error’ if the input string is only one word.

Q23 array1 = [1, 3, 5, 7, 9]; array2 = [0, 2, 4, 6, 8]; j = length(array1); array2(1) = array1(j); array1(j) = array1(3); array1(3) = array2(3) - 1; array1(j - 1) = array2(j - 2); array1(2) = array2(j) / array2(3); array2(3) = array1(3); array2(2) = array1(3) + 9; What are the values of array1 and array2 after the code above is executed? Q countOdd = 1; countEven = 1; for i = 1 : length(numList) if 1 2 ; countOdd = countOdd + 1; else 3 ; countEven = countEven + 1; end end Write code fragments to fill in blanks 1, 2, and 3 to complete the code above such that it separates an array of integers numList into two arrays, odd, containing the odd integers, and even, containing the even integers.

Q25 function ans = power(x, n) if n == 1 ans = x; else ans = x * power(x, n - 1); In your own words, explain what the computer does when it executes the following function call: power (2, 4); Q26 function ans = tryMe(s, c, value) if length(s) == 0 ans = value; elseif s(1) == c value = value * 2; ans = tryMe(s(2:end), c, value); else value = value + 1; ans = tryMe(s(2:end), c, value); end What is the value returned by the function call below? tryMe('mississippi', 'i' , 1);

This page intentionally left blank for any extra work.