{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


9----------3-----key1[1] - PIC 10A Final Exam Answers Fall...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 PIC 10A Final Exam Answers Fall 2006 Prof. Todd Wittman 1.) [20 points] For each library listed below, give a brief description of the library and its use. Then give an example of a function in the library and what it does. The first one is done for you as an example. <cmath> Contains useful mathematical functions like exponential and trig functions. sqrt(x) --returns the square root of a double x <iostream> Handles input / output for the console window. cout << x --outputs the value of x to the console window <vector> Allows declaration of vector class (dynamic list) and its member functions. <string> Allows use of the string class, which is used for parsing text. s.length( ) --returns the # characters in string s <iomanip> Formats output: control spacing and number of digits reported. setw (w) --outputs data right-justified in column of width w <fstream> Used for input / output from data files. 2.) [10 points] Briefly comment each of the following lines of code. The first line is done for you. Make sure you describe the difference between the last two lines. int x = 2 int *p p = &x *p = 4 cout << p cout << *p 3.) [15 points] Each of the code segments below has a compile error. Correct the compile errors. You will get points off for changing code that was not an error. a.) int hobbit = 3 if 0 < hobbit < 5 ++hobbit if (0 < hobbit && hobbit < 5) b.) vector<string> vec[3] vec[0] = "Hello Frodo.\n" vec[1] = "Hi Gandalf." vec[2] = vec[0] + vec[1] Use parentheses not brackets in first line: vec(3) c.) double *p *p = 42.1 Dangling pointer error.
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}