Upload
katie-cook
View
216
Download
0
Embed Size (px)
Citation preview
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 1/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
1. (QID 1138) 16/20 poin
A
B
C
D
E
Given the following code:
arr= {'Wall Street', [4 7 10], {'Shia', [300 400 100], 'yes'}, 'no'};
A = arr{3}{1}(2);
arr{1} = [];
B = class(arr{2}(1));
arr2 = {arr arr(1)};
C = length(arr2);
D = arr2{1}{3}{1};
E = 4 + arr(2);
After the code is run in MATLAB what would be the value of the following variables? Enter the values as youwould enter them in MATLAB, strings need to be in single quotes, logicals need to be true or false, and vectorsneed to be in square brackets (you do not need to type A= or B= etc.). If the code runs an error type 'error'.Assume the code continues to run after any errors occur. Do not comment your code.
2. (QID 1148) 12/20 poin
There is a file in the current directory called 'yogi.txt'. It contains the following FIVE lines:
Baseball is 90% mental,
and the other half
is physical.
CS1371 Fall 2010 - Test 2
WHITTINGSLOW, DANIEL CORBETT -dwhittingslow3
Correct Answer: 'h''h' (4 points)
Correct Answer: 'double''double' (4 points)
Correct Answer: 22 (4 points)
Correct Answer: 'Shia''error' (4 points)
Correct Answer: 'error''error' (4 points)
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 2/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
A
B
C
D
Is the file closed correctly? Type 'yes' or 'no' (with the single quotes).
3. (QID 1099) 9/10 po
- Yogi Berra
Now consider the following code. Trace the code to determine the values of the variables below.
name = 'yogi.txt';
M = fopen(name,'r');
f = [fgetl(M) fgetl(M)];
y = find(f==' ');
g = fgetl(M);
fgetl(M);
h = fgetl(M);
k = fgetl(M);
A = f(y(4)+1:y(5)-1)
B = length(k)
C = class(g)
D = f(f=='b'|f==',')
fclose(name);
After the code is run in MATLAB what would be the value of the following variables? Enter the values as youwould enter them in MATLAB, strings need to be in single quotes, logicals need to be true or false, and vectorsneed to be in square brackets (you do not need to type A= or B= etc.). If the code runs an error type 'error'.Assume the code continues to run after any errors occur. Do not comment your code.
A:
B:
C:
D:
Is the file closed correctly? Type 'yes' or 'no' (with the single quotes).
Correct Answer: 'the''the other' (4 points)
Correct Answer: 11 (4 points)
Correct Answer: 'char''char' (4 points)
Correct Answer: 'b,'',' (4 points)
Correct Answer: 'no''no' (4 points)
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 3/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
Graded By: JS
Function Name: pickAString
Inputs (2): (char) A string(char) Another string
Outputs (1): (char) the string that has more numbers in it
Function Description:
This function takes in two strings. The output is the string that has more numbers (digits '0' through '9'). If bothstrings have the same amount of numbers, the output is an empty string.* You may NOT use iteration to solve this problem.
Test Cases
A = wordChooser('MATLAB','CS1371');
A => 'CS1371'
B = wordChooser('Beverly Hills 90210','Atlanta, GA 30332');
B => ''
function more_nums=pickAString(str1,str2)
ndx_no1= find(str1 >= '0' & str1 <= '9');
numbers_1= str1(ndx_no1);
ndx_no2= find(str2 >= '0' & str2 <= '9');
numbers_2= str2(ndx_no2);
length1= length(numbers_1);length2=length(numbers_2);
if length1 > length2 more_nums= str1;elseif length2> length1 more_nums= str2;else more_nums=[];endend
TA Comments
-1 | output is empty string if there are same number of digits | Needs Work
4. (QID 1155) 12.5/15 po
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 4/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
Graded By: CJ
Function Name: priceLookup
Inputs (3):(cell) a cell array of items in inventory(cell) a cell array of the items' prices(char) an item to search for
Output (1):
(double or char) the price of the item, or the string 'Item Does Not Exist' if no item is found
Function Description:
This function takes in two cell arrays of equal length. The first contains strings, which are the names of items ininventory. The second contains doubles, which are the prices of those items. The third input is a string which isitem to search for. If the item exists in inventory, then the output is the items price. If the item does not exist ininventory, then the output is the string 'Item Does Not Exist'. See the test cases below for clarification.
When performing comparisons, case is important. There will be no duplicate item names.
Test Cases:
items = {'Milk', 'Eggs', 'Jackhammer', 'Dump Truck'};
prices = {2.49, 1.89, 45.95, 30000};
A = priceLookup(items, prices, 'Jackhammer');
A => 45.95
B = priceLookup(items, prices, 'Flux Capacitor');
B => 'Item Does Not Exist'
function out= priceLookup(items,prices, want)
out='Item Does Not Exist';
things= {items}
for i=1:length(things)
if strcmpi(items{i}, want)out= prices{i};end
end
end
TA Comments
-2.5 | Locates the item name in the cell array of item names | Needs Work
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 5/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
5. (QID 759) 17/20 po
Graded By: KC
Function Name: findHouses
Inputs (2): - (struct) a structure array of house listings- (double) a minimum price
Outputs (1): - (struct) a structure array of the house listings that meet the search criteria
Function Description:The input structure array contains information on house listings with two fields, 'price' and 'zipcode'.
The output is a structure array containing only the listings located in Zip Code '08873' AND that are moreexpensive (greater) than the minimum price given as an input to the function.
Test Case:list = struct('price', {85000, 90000, 75000}, 'zipcode', {'08873' '08844'
'08873'});
A = findHouses(list, 80000);
A -> 1x1 struct (A.price -> 85000 and A.zipcode -> '08873')
function str_final= findHouses(struct, min_price)str_final=
for i=1:length(struct)if struct.zipcode(i)=='08873'if struct.price(i) > min_pricestr_final= [str_final struct(i)]endend
end
end
TA Comments
-3 | Uses strcmp on a cell array of the zipcodes or uses iteration to logically ignore those that aren't
'08873' | Needs Work
6. (QID 1158) 15/15 po
Function Name: countNames
Inputs (2):
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 6/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
Graded By: SS
(char) the filename of a .txt file containing a list of names(char) a last name to search for
Output (1):(double) the number of names in the file that have the specified last name
Function Description:
This function takes in the name of a text file. The text file contains a list of names (firstname lastname). Thesecond input to the function is a last name to search for. The output of the function is the number of names in tfile where the last name matches the second input. Comparisons should be made case-sensitive. If no matcheare found, the output is 0. See the example file and test case below for clarification. Note that the first line of thefile is NOT part of the list of names.
Contents of 'names.txt':
FirstName LastName
Matt Ryan
Ryan Bennett
Nolan RyanSammy Sosa
Test Case:
A = countNames('names.txt','Ryan')
A => 2
function out= countNames(file,last_name)
fh= fopen(file,'r');line='';last_name= [' ',last_name];out=0;
while ischar(line)line=fgetl(fh);
if ischar(line)
[first last]= strtok(line, ' ');
if strcmp(last,last_name)
out=out+1;endendendend
TA Comments
8/3/2019 Test 2 Feedback
http://slidepdf.com/reader/full/test-2-feedback 7/7
3/6/11 3:ttps://t-square.gatech.edu/access/content/attachment/25e84ee8-1178-48ba-aff1-090348188318/feedback.html
Page
Good Job!
Section Your Score Possible Score
Multiple Choice 0.00 0.00
Fill In The Blank 28.00 40.00
Coding 53.50 60.00
Grand Total 81.50 100.00
Overall Exam Scores