27S-CS106X-Midterm-Key - CS106X Autumn 2010 Handout 27S...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS106X Handout 27S Autumn 2010 November 8 th , 2010 CS106X Midterm Examination Thanks to the herculean efforts of your friendly CS106X staff, the midterms have been graded and are available for pickup. We’ll bring the exams to Monday’s lecture, and those remaining will be stacked outside my door for the rest of the quarter. SCPD students: you should get your exam sometime on Tuesday or Wednesday. The height of each bar in the graph is the score that some student got on the exam, and should give you a sense as to how you did relative to everyone else. The average was a 31.6 out of 40, with a standard deviation of 5.1 or so. The exam is a only a small portion of your grade, but if you did poorly and you want to protect against a similar experience come final exam time, then feel free to come by my office hours to discuss a strategy for doing better. I don’t curve individual exams, but rather I curve the final distributions at the end of the quarter. If you notice a grading error, then you need to submit your exam back to me (Jerry) some time in the next week so I can take a look at it. All regrade requests must go through Jerry.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Solution 1: Superwords [8 points] bool IsSuperWord(string word, Lexicon& english) { for (int i = 1; i < word.size(); i++) { if (!english.containsWord(word.substr(0, i))) { return false; } } for (int i = 1; i < word.size(); i++) { if (!english.containsWord(word.substr(i))) { return false; } } return true; } Vector<string> CollectLongestSuperwords(Lexicon& english) { int length = 0; Vector<string> longestSuperwords; foreach (string word in english) { if (IsSuperWord(word, english) && word.size() >= length) { if (word.size() > length) { longestSuperwords.clear(); length = word.size(); } longestSuperwords.add(word); } } return longestSuperwords; } Criteria for Problem 1: 8 points Constructs an empty Vector<string> and eventually returns whatever that vector ultimately contains: 1 point Correctly iterates over all words in the Lexicon : 1 point Properly implements the logic for IsSuperWord [ideally a function, but technically not necessary]: 4 points o Properly examines all prefixes with the correct substr call: 1 point o Properly examines all suffixes with the correct substr call: 1 point o Bounds for the two for loops are correct and examine all prefixes and suffixes: 1 point o Properly returns false as soon as a non-word is found, and returns true
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2011 for the course CS 106X taught by Professor Cain,g during the Fall '08 term at Stanford.

Page1 / 7

27S-CS106X-Midterm-Key - CS106X Autumn 2010 Handout 27S...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online