PIC10AfinalF08key

PIC10AfinalF08key - Final Exam, 12/7/08 PIC 10A, Fall 2008...

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

View Full Document Right Arrow Icon
Final Exam, 12/7/08 PIC 10A, Fall 2008 KEY Check your TA’s name: _____ Rachel _____ Aleka _____ Paul _____ Ricardo You have 3 hours to complete this exam. You are not allowed to use any books, notes, calculators, or electronic devices. Write your answers carefully. Incomplete, unintelligible, or illegible answers will receive little or no credit. When you are asked to write a program, it is not necessary to comment your code but you are expected to indent appropriately to make your code easier to follow. There are a total of 100 points on this exam. PAGE SCORE POSSIBLE 1 10 2 10 3 12 4 7 5 14 6 12 7 15 8-9 20 TOTAL 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
1 1.) [2 points] Suppose we have a pointer p . Briefly explain the difference between the two cout statements below. cout << p; cout << *p; cout << p; prints the address of the block the pointer p is pointing to (the pointee) cout << *p; prints the value in the block the pointer p is pointing to (dereferencing) 2.) [2 points] C++ sorts strings lexicographically . Explain what lexicographic order means. Then give a specific example that shows lexicographic order is different from alphabetical order. Lexicographic order sorts strings first by number, then with capital letters, then by lower- case letters. For example, "ZEBRA" comes before "aardvark". 3.) [3 points] Write a single cout statement that prints the following text exactly as below, including the quotation marks. The file is in: "C:\My Documents" Need escape characters for the line break, quotes, and the backslash. cout << "The file is in:\n\"C:\\My Documents\""; 4.) [3 points] A cool fact which did not come in lecture is that you can cast between chars and ints. For example the char 'A' has int value 65, 'B' corresponds to 66, 'C' corresponds to 67, and so on in sequential order. cout << (int) 'A'; //Prints the number 65. cout << (char) 68; //Prints the letter D. Using this new information, write a simple for loop that prints the 26 letters A through Z. for (int i=0; i<26; i++) cout << (char) (i+65);
Background image of page 2
2 5.) [6 points] Correct the error(s) in each block of code below. You will get points off for changing code that was not in error. a.) cout << "Enter your first name: "; string name; cin << name; if (name < "Frodo") cout << "Hello!"; Arrows go the wrong way on input pull. cin >> name;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/16/2008 for the course PIC 10A taught by Professor Wittman during the Fall '08 term at UCLA.

Page1 / 10

PIC10AfinalF08key - Final Exam, 12/7/08 PIC 10A, Fall 2008...

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

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