43-CS107-Final-Exam

43-CS107-Final-Exam - CS107 Spring 2007 Handout 43 June...

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

View Full Document Right Arrow Icon
CS107 Handout 43 Spring 2007 June 8 th , 2007 CS107 Final Exam This is an open-note exam. You can refer to any course handouts, handwritten lecture notes, and printouts of any code relevant to a CS107 assignment. You may not use any laptops, cell phones, or handheld devices of any sort. Those taking the exam remotely should phone in if they have questions. Once you’re done, fax the exam to Stanford, but hold on to the original until you get the graded fax copy back. Cell phone is 415-205-2242, and fax number is 415-358-4911 . leland username: _____________________ Last Name: _____________________ First Name: _____________________ I accept the letter and spirit of the honor code. I’ve neither given nor received aid on this exam. I pledge to write more neatly than I ever have in my entire life. (signed) __________________________________________________________ Score Grader 1. Munchies (10) ______ ______ 2. All Things Scheme (15) ______ ______ 3. C versus Scheme (6) ______ ______ 4. Java Runtime (7) ______ ______ 5. Java Short Answer (7) ______ ______ 6. Conserving Threads (10) ______ ______ Total (55) ______ ______ SCPD students who want their exams sent back through regular mail, check here: ____
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 Problem 1: Munchies (10 points) Given the following C++ class definition, generate code for the munchy::cheeto method. Assume that the parameters have already been set up for you. Be clear about what code pertains to which line. Recall that C++ references are automatically dereferenced pointers, and k-argument methods are really (k + 1)-argument functions, where the address of the receiving object is passed in as the bottommost parameter. The address of the first instruction of the cheeto method is synonymous with <munchy::cheeto> . You have this and the next page for your code. class munchy { public: char& cheeto(munchy& pretzel, char *sunchip); private: short *pringle; short bugle[2]; char dorito[12]; }; { *(munchy **)sunchip += sunchip[8]; return dorito[pretzel.cheeto(*this, sunchip + 1)]; } line 1 line 2
Background image of page 2
3 (more space for Problem 1)
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Problem 2: Scheme (15 points) a) (4 points) A derangement is a permutation of the integers 1 through n such that no number k falls in the k th position. So, (4 1 3 5 2) is certainly a permutation, but it’s not a derangement, because the 3 sits in the 3 rd position. (3 5 1 2 6 4) is a derangement of length 6, and (2 3 7 6 1 5 4) is a derangement of length 7. (1 2 3 4 5 6 7 8) is as far as a permutation can be from a derangement. Write a function called
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

43-CS107-Final-Exam - CS107 Spring 2007 Handout 43 June...

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

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