9----------3-----key1[1]

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
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 = 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. Illegal because p does not point to a block, so the value 42.1 has nowhere to go: double *p = new double d.) int a[10] for (int i = 1 a[i] = i*i Arrays start at 0: for (int i=0 e.) double investment = 2000.0 double return = 1.016 * investment v.push_back(x) h
Background image of page 1

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

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

Page1 / 14

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

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

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