10AfinalF06key

10AfinalF06key - PIC 10A Final Exam Answers Fall 2006 Prof....

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

View Full Document Right Arrow Icon
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. v.push_back(x) – adds element with value x to the end of the vector v <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. ofstream o – creates an output file stream o for writing to a file -------------------------------------------------------------------------------------------------------------------------------- 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; //Creates integer x and assigns it value 2. int *p; //Creates a pointer p to a integer. p = &x; //Sets p pointing to the address of variable x. *p = 4; //Changes the value that p points to equal to 4. cout << p; //Prints out the address that p points to. cout << *p; //Prints out the value in the block p points to (4). -------------------------------------------------------------------------------------------------------------------------------- 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.)
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.

This note was uploaded on 04/27/2010 for the course PIC 157-050-20 taught by Professor Wittman during the Winter '10 term at UCLA.

Page1 / 4

10AfinalF06key - PIC 10A Final Exam Answers Fall 2006 Prof....

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