Docsity

CS1371 - Computing for Engineers - Test 2 Version M, October 24th, 2007, Exams of Computer Science

Toggle sidebar
bg1
CS1371 - Computing for Engineers - Test 2 Version M October 24th, 2007
1Georgia Institute of Technology
College of Computing
CS 1371 Computing for Engineers
Test 2 Version M - Fall Semester 2007
Page 1 of 8
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 T-Square 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):
Signature:
TA / Section: ____________________________
Prob. Poss.
Pts
Earned
Pts
Lost
Pts by
(cover) - -
1 50
2 50
3 50
4 50
TOTAL 200
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

Partial preview of the text

Download CS1371 - Computing for Engineers - Test 2 Version M, October 24th, 2007 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 M - Fall 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 T-Square 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):

Signature:

TA / Section: ____________________________

Prob.

Poss.

Pts

Earned

Pts

Lost

Pts

by

(cover) - -

TOTAL 200

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:
char(x) โ€“ converts the numerical vector into it string ASCII value
double(x) โ€“ converts the string x to its ASCII representation
factorial(n) โ€“ returns n!
false(a,b) โ€“ creates a matrix of a rows and b columns of boolean false
find(m) โ€“ returns the indices of the true elements of m
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, str) โ€“ checks if the variable a belongs to the class str
iscell(a) โ€“ checks if a is of class cell (a cell array)
ischar(a) โ€“ checks if a is of class char (a string)
isnumeric(a) โ€“ checks if a is of a numeric data type(a number)
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
ones(rows, cols) โ€“ generate a matrix filled with 1
prod(v) โ€“ compute the product of all the elements in a vector v
rem(a, b) โ€“ the remainder when a is divided by b
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.
strcmp(a, b) โ€“ checks if the string a is identical to string b
strcmpi(a, b) โ€“ checks if the string a is identical to string b ignoring case of a and b
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
true(a,b) โ€“ creates a matrix of a rows and b columns of boolean true
xlswrite(filename, array) - Writes the array to the .xls file
xlsread(filename, array) โ€“ Reads in an .xls file.
zeros(rows, cols) โ€“ generate a matrix filled with 0

Problem 2 โ€“ File I/O [50 Points]

No. Name Age Cuteness Score
1 Bob 8 37
2 Fiona 4 8
3 Jackson 5 33
4 Carol 9 13
5 Gabriel 9 40
6 Ian 7 18
7 Ann 3 26
8 Dave 6 16
9 Earl 8 30
10 Heather 7 34

You have the following Microsoft Excelยฎ^ worksheet saved in a file called

โ€˜Baby_score.xlsโ€™. The following lines of code are executed. What is the value of the

variables when the following code is executed? (8 points each)

[num txt raw] = xlsread('Baby_score.xls');
vec = num(:,end);
[numrows numcols] = size(num);
[txtrows txtcols] = size(txt);
[rawrows rawcols] = size(raw);
varA = txt{numrows-1,2};
varB = raw{5, end};
varC = find(vec == min(vec));
varD = ischar(txt);
varE = (txtrows == rawrows) && (numcols == rawcols);
varF = (txtcols == rawcols) && (numrows == rawrows);

Write your answers in the blanks provided below:

_____ varA = A. 7 B. 6 C. โ€˜Daveโ€™ D. โ€˜Earlโ€™ E. None of the above

_____ varB = A. โ€™Carolโ€™ B.13 C. 40 D. Error E. None of the above

_____ varC = A. 2 B. 8 C. 4 D. 3 E. None of the above

_____ varD = A. 0 B. 1 C. 2 D. 3 E. None of the above

_____ varE = A. 0 B. 1 C. 2 D. 3 E. None of the above

_____ varF = A. 0 B. 1 C. 2 D. 3 E. None of the above

Problem 3 โ€“ Recursion [50 Points]

A. Write a MATLAB function called โ€˜recursive_Spaceโ€™ that takes in a character array and

deletes all blank spaces from it. (20 points)

  • HINT: The space character is represented by ASCII number 32.
  • Note: You must use recursion to solve this question.

For example:

>> ret1 = recursive_Space([โ€˜Hello, how are you doing?โ€™])
=> ret1 = โ€˜Hello,howareyoudoing?โ€™
>> ret2 = recursive_Space(โ€˜cs1371โ€™) => ret2 = โ€˜cs1371โ€™
>> ret3 = recursive_Space(โ€˜โ€™) => ret3 = โ€˜โ€™

C. You are given the following function in MATLAB. What is the output of the function

when the following inputs are passed? (5 points each)

A. Complete the code on the right so as to

display the plot as shown. Write the letter

corresponding to each line of code on the

correct line on the right. (1 point each)

  • You can only use the commands given

below

  • You can use any command more than once

Permitted Commands

A -> x = [0 2*pi];

B -> x = linspace(0, 2*pi,4);

C -> x = linspace(0, 2*pi,8);

D -> x = linspace(0, 2*pi);

E -> y = sin(x);

F -> plot(x,y)

G -> xlabel(โ€˜x-axisโ€™);

H -> ylabel(โ€˜y-axisโ€™);

1 - subplot(2, 2, 1)

7 - subplot(2, 2, 2)

13 - subplot(2, 2, 3)

19 - subplot(2, 2, 4)

u = 0:5;
v = u.^2;
th = linspace(____,____);
[uu tth] = meshgrid(u,th);
[vv tth] = meshgrid(v,th);
rr = ________________________
xx = ________________________
yy = ________________________
zz = ________________________
surf(xx,yy,zz);
xlabel('x-axis')
ylabel('y-axis')

zlabel('z-axis') full rotation about the z-axis

B. Select the answers that when placed into the skeleton code above will generate the

image to the right.(6 points each)

______ th =
A. linspace( 0, 360) B. linspace( 0, pi/2) C. linspace( 0, 2*pi)
D. linspace(0, pi/4) E. None of the above
______ rr =
A. rr.cos(tth) B. vv C. rr.sin(tth) D. uu E. None of the above
______ xx =
A. rr.cos(tth) B. vv C. rr.sin(tth) D. uu E. None of the above
______ yy =
A. rr.cos(tth) B. vv C. rr.sin(tth) D. uu E. None of the above
______ zz =
A. rr.cos(tth) B. vv C. rr.sin(tth) D. uu E. None of the above