Computer Science 215 Quiz 1 Name ______________________ 1. The number of distinct values that a single byte of computer memory may take on is: a. 2 b. 8 c. 255 d. 256 2. In the C language a variable of type "char" a. is used to hold character, b. holds 8 bit integers but not numeric data c. holds 32 bit integers 3. The C expression 'A' + 0x0b - 3 a. is illegal because of the b. has the decimal value 73 mixed modes in which the constants appear c. has the decimal value 75 d. has none of the above values 4. A statement such as: x <= y + 5; appearing in a C program will a. Cause a compile time syntax b. Cause a segmentation fault error because the <= operator at run time because no place has been entered where = to store the value has been should be. provided c. Compile fine and do nothing to alter the state of the program at run time. 5. Which best characterizes the behavior of the following statements x = y; if (x = 0) printf("%d\n", x); a. the "if" statement will b. The print statement will cause a syntax error. never be executed c. the print statement will d. the print statement will be always be executed executed if the value of "y" is zero. ----- PLEASE ALSO WRITE YOUR NAME OF THE BACK OF THE PAPER ------ ----- PLEASE DO NOT FOLD THE PAPER ------ ----- You may leave when you finish ------ Computer Science 215 Quiz 2 Name ______________________ 1. Suppose the following is executed: int i, j; scanf("%2d %2d", &i, &j); and the input that is typed in is: 1234567 89 0 What values will be assiged to i and j i = j = 2. Which is the correct way to test for end of file when reading in two integers at a time using scanf() a. while (scanf("%d %d", &i, &j)>=0) b. while (scanf("%d %d", &i, &j)==2) c. while (scanf("%d %d", &i, &j) != EOF) 3. Suppose the following code is executed: is: int i, j; scanf("%d %d", &i, &j); 2 Z 4 a. i will be set to 2 b. i will be set to 2 j will be set to 65 j will be set to 4 c. i will be set to 2 d. neither i nor j will j will not be set at all be set 4. Which of the following format codes causes no conversion of the data being read or written with printf or scanf: a. %d b. %x c. %c d. %f 5. Which pair of statements is the proper way to read a numeric value into an integer variable declared as "int n;" and then print it out: a. scanf("%d", n); b. scanf("%d", n); printf("%d\n", n); printf("%d\n", &n); c. scanf("%d", &n); d. scanf("%d", &n); printf("%d\n", n); printf("%d\n", &n); Computer Science 215 Quiz 3 Name ______________________ 1. If a C program is to read from the standard input using fscan(stdin, "%d", &c); a. The program must contain a b. The program must contain a FILE *stdin; FILE stdin; declaration. declaration. c. The program must NOT declare stdin because it must be predeclared in stdio.h 2. Which best characterizes the action taken when reading a file with fscanf() and with fgetc() a. fscanf() may consume multiple b. both fscanf() and fgetc() bytes from the file in a single consume exactly one byte call, but a call to fgetc() will per call. consume at most 1 byte. c. both fscanf() and fgetc() consume multiple bytes per call. 3. The fgets() function a. reads a single byte from b. always reads a specified number a file of bytes from a file c. stops reading when it finds d. stops reading when it finds a a '\n' newline character or null character or fills the fills the specified buffer specified buffer space. space. 4. Consider the following program fragment: unsigned int c; c = fgetc(stdin); fprintf(stdout, "%d\n", c); Now suppose I run the program and type number 3 followed by a ctl-d (EOF). The value printed on my screen will be: (Hint: the ASCII encoding of the character '3' is 0x33 = 51.) a. 3 b. 51 c. c d. \n 5. Suppose the fputs() function is called as follows: fputs(buf, stdout); Which best describes how the function will operate. a. A single byte stored at location b. The value "buf" will be interpreted buf will be sent to stdout as a pointer and whatever byte it points to will be sent to stdout. c. "buf" will be viewed as a pointer d. "buf" will be viewed as a pointer and bytes starting at the location and bytes starting at the location to which it points will be sent to which it points will be sent to stdout until a \n (newline is to stdout until a NULL (byte having found) the value 0 is found) Computer Science 215 Quiz 4 Name ______________________ 1. Fill in the FINAL values in the table below after ALL of the code shown has completed execution: x = 22; name value address y = 9; ------------------------------ p = &x; int x | | 120 r = &y; ------------------------------ *p = *r; int y | | 116 *r = x; ------------------------------ p = r; int *p | | 112 ------------------------------ int *r | | 108 ------------------------------ 2. Suppose the following declarations are made in a program to be run on an Intel x86 computer. char *x; short *y long *z; a. Each of the three pointer b. The three pointer variables consume variables consumes 4 bytes 1, 2, and 4 bytes respectively of space. c. Each of the three pointer variables consumes 1 byte of space. 3. Which best characterizes the behavior of the following program: main() { int* p; *p = 99; printf("The value is %d \n", *p); } a. The program is correct and b. The program is incorrect should be expected to work and will fail in all environments fine in all environments before the printf() is executed c. The program is incorrect, but it may appear to work correctly. 4. The proper way to use fread to copy stdin to stdout until end of file is: a. while (len = (fread(buff, 1, 1024, stdin) != 0)) fwrite(buff, 1, len, stdout); b. while ((len = fread(buff, 1, 1024, stdin)) != 0) fwrite(buff, 1, len, stdout); c. while (len = fread(buff, 1, 1024, stdin) != 0) fwrite(buff, 1, len, stdout); d. All of the above are equivalent and correct. Computer Science 215 Quiz 5 Name ______________________ 1. Which best characterizes the behavior of the following program: main() { int *pi; pi = (int *)malloc(4); scanf("%f", &pi); } a. The program will correctly b. The program is incorrect. read a single floating point The & in the scanf() call must into the malloc'd memory be deleted to fix it. c. The presence of the & is optional.. The program will read the value into the malloc'd memory either way. 2. Which is the proper way to dynamically allocate storage for an array of 100 integers. (For questions 2, 3, 4 assume that the pointer variable pi is declared as: int *pi; a. pi = (int *)malloc(4 * 100); b. pi = (int *)malloc(100); c. pi = (int *)malloc(4 * sizeof(int)); 3. Suppose the values of the 100 integers are to be printed in a for () loop. In each interation through the loop, the proper way to update the pointer used to point to the value to be printed is: a. pi = pi + 4; b. pi = pi + 1; c. pi = pi + sizeof(int); d. pi = pi + 100; 4. The proper way to print the value of the current integer is: a. printf("%d \n", &pi); b. printf("%d \n", pi); c. printf("%d \n", *pi); d. printf("%d \n", **pi); 5. The proper expression that should be used to access a pixel at position (row, col) in a binary encoded grayscale image is: a. *(imageloc + row * numrows + col) b. *(imageloc + col * numrows + col) c. *(imageloc + col * numrows + row) d. *(imageloc + row * numcols + col) Computer Science 215 Quiz 6 Name ______________________ 1. Given the following definitions circle ALL of the following assignments that are syntactically correct: struct pix struct pix p1; { struct pix* p2; unsigned char r; unsigned char g; unsigned char b; }; a. p1->r = 250; b. p2.r = 250; c. (*p1).r = 250; d. p1.r = 250; 2. In a color .ppm image a. three pixels are contained b. one pixel occupies one in a single byte of image byte of image data data c. one pixel occupies three bytes of image data 3. The correct way to access the "green" component of the pixel stored at (row, col) in an image buffer pointed to by unsigned char *buf is: a. *(buf + 3 * row * numcols + 3 * col + 1); b. *(buf + row * numcols + col + 1); c. *(buf + 3 * row * numcols + 3 * col); d. *(buf + 3 * row * numrows + 3 * col); 4. Suppose the following have been defined: struct pixtype struct pixtype *pixp; { unsigned char r; unsigned char g; unsigned char b; }; The correct way to access the "green" component of the pixel stored at (row, col) in an image buffer pointed to by struct pixtype *pixp is: a. *(pixp + 3 * row * numcols + 3 * col + 1); b. (pixp + 3 * row * numcols + 3 * col)->g c. (pixp + row * numcols + col).g d. (pixp + row * numcols + col)->g 5. In the definition: struct pix pixel; a. both pix and pixel are types and b. pix is a type but pixel is not instances of variables an instance c. pixel is a type and pix is an d. both pixel and pix are instances instance of variables. Computer Science 215 Quiz 7 Name ______________________ 1. Given the following structure definition, which of the following is syntactically correct. struct new a. v[1].a = 1; b. v.a[1] = 1; { int a[2]; c. v.b[1] = 1.5; d. v[1].b = 1.5; float b; }; struct new v; 2. Given the following structure definition, which of the following is syntactically correct. struct new a. v[1].a[1] = 1; b. v[0].b[1] = 1; { int a; c. v.b[1] = 1.5; d. v.a[1] = 1.5; float b[2]; }; struct new v[3]; 3. Compute the dot product of (3, 4, 1) dot (2, -1, 3) = 4. Compute the length of the vector (-1, 2, 1) (No calculators are needed -- you may leave the square root symbol in your answer). || (-1, 2, 1) || = 5. Compute the vector difference of: (1, 2, 4) - (2, -1, 3) = Computer Science 215 Quiz 8 Name ______________________ Suppose that a raytracing scene object has been properly typedef'd as an obj_t and a list header structure is defined as follows: typedef struct list_type { obj_t *head; obj_t *tail; } list_t; 1. Which of the following is the correct way to insert a new object pointed to by obj_t *new into an EMPTY list. a. head = new; b. head->next = new; tail = head->next; tail->next = new; c. head = tail; d. head = new; tail = new; tail = new; 2. Which of the following is the correct way to add a new object pointed to by obj_t *new to the tail of a NON-EMPTY list. a. tail = new; b. new->next = tail; tail->next = new; next = new; c. tail->next = new; d. head = tail; tail = new; tail = new; 3. Which of the following is the correct way to INSERT a new object pointed to by obj_t *new at the HEAD of a NON-EMPTY list. a. new->next = head; b. head->next = new; head = new; new->next = head; c. head = new; d. head = new; tail->next = new->next; new->next = head; 4. In the obj_t structure described in class last time the pointer void *priv; was used to point: a. back to the head of the list b. to structures carrying the variables peculiar to derived classes such as c. to the next object in the list. spheres and planes 5. Given the following two structures: struct image struct pix { { int rows; unsigned char r; int cols; unsigned char g; struct pix pixmap[1024][768]; unsigned char b; }; }; the order in which the structure definitions appears in a program must be: a. struct image before b. struct pix before struct pix struct image c. Either way works fine Computer Science 215 Quiz 9 Name ______________________ 1. The type of lighting to be supported in version 1 on the raytracer is: a. ambient b. diffuse c. specular d. emissive 2. Suppose V is the view point and W is the world coordinates of the point on the screen through which the ray passes. A unit vector in the direction of the ray is given by: a. V / || V || b. W / || W || c. (V - W) / || (V - W)|| d. (W - V) / || (V - W) || 3. If the coordinates of the point at which the ray hits the object is H the distance from the viewpoint to the hitpoint is given by: a. H b. (H - V) c. || (H - V) || d. (W - V) 4. The mission of the raytrace function is to determine: a. the color of the first object b. the color of the closest object hit by the ray hit by the ray c. the color of the last object d. the average color of all objects hit by the ray hit by the ray. 5. Colors are represented within the raytrace function itself as: a. unsigned chars in the range b. unsigned chars in the range [0, 1] [0, 255] c. floating point values in the range [0, 1]. Computer Science 215 Quiz A Name ______________________ 1. Suppose a plane in 3 dimensional space has normal vector N and the P and Q are two different points that both lie in the plane. Which of the following will always have the value 0. a. N dot P b. P dot (N - Q) c. P dot Q - N d. N dot (P - Q) 2. Suppose a ray is fired from viewpoint V with unit direction vector D. The ray is parallel to the plane if: a. V dot D = 0 b. V dot N = 0 c. D dot N = 0 d. (N - D) dot V = 0 3. Suppose ray hits the plane at a distance t from V. The coordinates of the hitpoint are: a. P + tN b. V + tP c. D + tV d. V + tD 4. What value will be printed by the following program: int fix(int a) main() { { a = 11; int a = 12; return(13); fix(a); } printf("a = %d \n", a); a = 5. What value will be printed by the following program: int fix(int *a) main() { { *a = 11; int a = 12; return(13); fix(&a); } printf("a = %d \n", a); } a = Computer Science 215 Quiz B Name ______________________ 1. Which of the following best characterizes what happens when a program attempts to invoke a function that is defined in another module but for which no prototype definition is supplied: (suppose main.c invokes function adder() in adder.c and the compile command is: gcc -g main.c adder.c) a. it will cause a syntax error b. it will cause an error at link at compile time because the time because the linker won't function name is not defined be able to find adder() c. it will always work fine d. it will only work if adder() returns int and its parameters are of the correct type 2. Suppose "funptr" is a properly declared pointer to functions having two int parameters and returning int. The correct way to cause it to point to "adder" is: a. funptr = adder; b. funptr = &adder; c. *funptr = adder; d. funptr = adder(); 3. After the pointer is correctly initialized, the proper way to invoke the function adder through the pointer is: a. s = funptr(3, 4); b. s = (*funptr(3, 4)); c. s = (*funptr)(3, 4); d. s = *(funptr)(3,4); Suppose that the viewpoint is on one side of the screen and a sphere is on the other. The distance from the viewpoint to the hitpoint is given by t = (-b +/- sqrt(b^2 - 4ac))/2a 4. The correct root of the equation to use in determining the hitpoint is a. t = (-b - sqrt(b^2 - 4ac))/2a b. t = (-b + sqrt(b^2 - 4ac))/2a 5. The way in which it may be determined that the ray misses the sphere is that a. both values of t are negative b. 2a = 0 c. b^2 < 4ac Computer Science 215 Quiz C Name ______________________ 1. The diffuse intensity the light reflected by an object at the hitpoint is a product of the emissivity of the light, the diffuse reflectivity of the object and the dot product of a. unit vectors pointing b. a unit normal at the object in the direction of the hitpoint and a unit vector light and the direction in the direction of the viewpt of the viewpt from the hit c. a unit normal at the object d. unit vectors pointing from the hitpoint and a unit vector light to the object and the in the direction of the light light to the viewpoint 2. (a continuation of 1) divided by: a. the distance from the light b. the distance from the light to to the viewpt the hitpoint c. the distance from the hitpoint to the object 3. If the dot product in #1 is negative it means that a. the hit object occludes itself b. the hit object is occluded by from the light another object c. the center of the light is visible from the object. 4. What is the result when the matrix and vector shown below are multiplied: | 1 0 -1 | |2| | 1 -1 1 | |1| | 1 -1 -1 | |2| 5. If am creating a function to process an array having 3 rows and 4 colums, circle ALL off the following prototypes that will generate a compiler error if I try to access t[1][1] in the code. a. int fun(int t[][]) b. int fun(int t[3][]) c. int fun(int t[][4]) d. int fun(int t[3][4]) Computer Science 215 Quiz D Name ______________________ 1. Given three points, P, Q, and R, the normal to the plane that three points define is given by: (x means Cross Product) a. P x R b. (P - Q) x R c. (P - Q) x (R - Q) d. Q x (P - R) 2. The cross product of (1, 0, 0) and (0, 1, 0): a. (1, 1, 0) b. (0, 0, 1) c. (0, 0, 0) d. (1, 1, 1,) 3. The projection of a unit vector V on another unit vector N is given by: a. V dot N b. (N dot V) N c. (V dot N) V d. (N x V) N 4. Which of the following is NOT always an attribute of a rotation matrix a. its rows are mutually b. It is the identity matrix orthogonal c. its inverse is its d. Its rows and columns are transpose unit vectors 5. Characterize the following implmentation of vl_unitvec3(): (assume vl_length3() is working correctly) vl_unitvec3(double *v1, double *v2) { *(v2 + 0) = *(v1 + 0) / vl_length3(v1); *(v2 + 1) = *(v1 + 1) / vl_length3(v1); *(v2 + 2) = *(v1 + 2) / vl_length3(v1); } a. it never works correctly b. it always works correctly c. it will never work correctly d. it may or may not work correctly if v1 and v2 point to the if v1 and v2 point to the same vector same vector, depending on the value of the vector Computer Science 215 Quiz E Name ______________________ int y = 52; int q = 23; main() { int y = 34; int r; int s; { int y = 77; printf("%d ", y); } printf("%d \n", y); } 1. In this program the 3 declarations of y will a. cause a syntax error for b. will result in all three duplication of declaration declarations referring to the same memory location. c. will result in there being three separate locations in which a variable named y is stored. 2. The output of the program will be: a. no output at all because b. 77 77 of compile time syntax error c. 77 52 d. 77 34 3. In the above program a. r and q will both reside in b. r and q will both reside on the the heap stack c. q will reside on the stack d. r will reside on the stack and r will reside on the heap and q will reside on the heap Consider the following function: int adder(int a, int b) { int sum; 4. The variable "a" will be accessed as: a. 8(%ebp) b. 12(%esp) c. -8(%ebp) d. -8(%esp) 4. The variable "sum" will be accessed as: a. 4(%ebp) b. 4(%esp) c. -4(%ebp) d. -4(%esp) Computer Science 215 Quiz F Name ______________________ 1. If a C program mallocs an area of memory and fails to free it, a. A garbage collector built b. The OS will reclaim all of the into the C language will memory used by the program including reclaim it unfreed malloc'd areas when the program exits. c. The memory will remain unusable d. The memory will remain permanently until the system is rebooted allocated and the computer will eventually have to be sent back to the factory for memory replacement 2. The correct approach to avoiding memory leaks is to free a malloc'd object a. whenever a function that has b. whenever the LAST pointer to the a local variable that points object is about to be reset or to to it returns go out of active scope. c. both of the above are true. 3. Assuming "lst" points to the head of one of our object lists, which best characterizes the following code fragment: obj_t *temp = malloc(sizeof(obj_t)); temp = lst->head; a. it will cause a memory leak b. it will cause a seg fault c. it is the correct way to set temp to point to the first object in the list. 4. Suppose a new object structure is being created and the object structure is allocated as follows: newobj = malloc(sizeof(obj_t)); After the new object pointer has been safely linked into the object list, before returning the routine that allocated the object a. should free(newobj); b. MUST free(newobj); c. MUST NOT free(newobj); Computer Science 215 Quiz G Name ______________________ 1. A TILED plane object definition DIFFERS from a FINITE plane object definition in that the tiled plane has: a. a second material reflectivity b. a rectangle size specification specification c. an x direction vector d. ALL of the above 2. In the tiled plane object, the "point" field specifies the location of a. any point on the plane b. the lower left corner of a "foreground" tile. c. the center of a "foreground" d. the center of a "background" tile. tile 3. The mission if the "tp_select" function is to a. determine if a ray hits the b. determine whether the hitpoint tiled plane lies in a foreground or background tile c. determine the color of the d. all of the above foreground or background tile in which the hitpoint is found to lie. 4. Calling which of the following routines might result in a call being made to tp_select() Hint: Result in means f1() invokes f2() which invokes f3() which ... invokes tp_select()). a. plane_hits(); b. illum_diffuse(); c. both d. neither one 5. For square tiles the relative tile number in which a hit occured can be determined by a. dividing the hitloc coord b. dividing the tile size by the tile size by the hitloc coord c. multiplying the hitloc coord by the tile size. Computer Science 215 Quiz H Name ______________________ 1. Which of the following is a proper way to declare a C++ class named x_t a. typedef class x_type b. typedef class x_t { { public: public: private: private: int x; int x; }; }; c. typedef class x_type d. class x_t { { public: public: private: private: int x; int x; } x_t; } x_t; 2. Suppose class view_t has a method named load_view() and an instance of the class is created as: view_t v; The proper way to invoke the load_view() method is: a. v->load_view(); b. v.load_view(); c. v::load_view(); d. load_view(); 3. Suppose class view_t has a method named load_view() and an instance of the class is created as: view_t *v new view_t; The proper way to invoke the load_view() method is: a. v->load_view(); b. v.load_view(); c. v::load_view(); d. load_view(); 4. Which of the following ways of overloading load_view() class view_t class view_t { { public: public: int load_view(int); int load_view(int); int load_view(char); void load_view(int); a. The one on the left b. The one on the right c. Both of them are correct 5. Which of the following is the correct way to create an implementation of load_view a. int view_t:load_view(int x) b. int view_t::load_view(int x) c. int view_t.load_view(int x) d. int view_t->load_view(int x) Computer Science 215 Quiz I Name ______________________ 1. In the approach to anti-aliasing that was discussed the number of rays traced per pixel a. is still one ray per pixel b. is some constant number > 1 c. is a random number of rays 2. The x-size (in WORLD COORDINATES) of the "box" on the screen through which the randomized ray used in antialiasing passes is: a. world_x_size b. win_x_size (number of window (pixels in x dimension) c. win_x_size / world_x_size d. world_x_size/win_x_size 3. Suppose class link_t is being defined. The correct way to declare a prototype for its DEFAULT constructor is: a. class link_t b. class link_t { { public: public: link_t link_t(); int link_t(); c. class link_t d. class link_t { { public: public: link_t(); link_t link_t(const link_t); 4. In the add method of the list_t class which of the following is the proper way to add a new link_t named "link" to an non-empty list_t; a. last = link; b. last->set_next(link); last->set_next(link); last = link; c. the order in which the two statements are executed is irrelevant 5. If a class declaration begins as follows: class link_t { public: link_t(void); // constructor link_t(obj_t *); // constructor a. There will be a syntax b. The second constructor will error because of conflicting "override" the first and will constructors definitions always be the one used. c. The constructor that is used will be determined based upon whether or not an obj_t pointer is passed in the call to "new" Computer Science 215 Quiz J Name ______________________ Consider the diagram illustrating ray reflection: Assume that N represents the surface normal and V the direction of the reflected ray. 1. The vector shown as a dashed line is given by: a. N dot U b. N (U dot V) c. N (U dot N) d. 2 N (U dot N) 2. The V vector is a. N (U dot N) b. 2 N (U dot N) - U c. (N dot U) N d. none of the above 3. It is necessary for the raytrace() function to call itself recursively a. only when the object just b. when ANY object in the scene hit has non-zero specular has non-zero specular reflectivity reflectivity c. always 4. When a ray is reflected from the surface as an object, what object(s) should be EXCLUDED as possible next hit objects. a. all objects with specular b. the object that reflected reflectivity the ray c. no objects 5. The recursion ends when the ray has a. traveled a predefined max b. hits an object with zero distance specular reflectivity c. both (a) and (b) d. neither (a) nor (b) Computer Science 215 Quiz K Name ______________________ 1. In the C++ design presented in class: a. obj_t was a base class and b. obj_t was a base class and sphere_t was a derived class sphere_t was a derived class c. both classes were unrelated peer classes 2. The class view_t definition starts as follows: class view_t { friend class pixel_t; the "friend" declaration gives: a. view_t methods access to b. pixel_t methods access to the the private data of a private data of a view_t instance pixel_t instance c. both of the above d. neither of the above because "friend" only provides access to public data. 3. Suppose a tiled plane class, tplane_t, is a derived from class plane_t which is in turn derived from classes obj_t and material_t. The correct way to express this relationship is: a. class tplane_t: public obj_t, public material_t b. class tplane_t: public plane_t c. class tplane_t: public obj_t, public material_t, public plane_t 4. The tplane_t constructor begins as follows tplane_t::tplane_t( FILE *in, FILE *out, int otype, int oid) : plane_t(in, out, otype, oid) if the : plane_t(in, out, otype, oid) text is deleted a. the plane_t constructor will no b. there will be no difference at longer be called when a tplane_t all in the behavior of the is created program c. a plane_t constructor will be called but it will be the default constructor instead of the one with 4 parameters 5. When a new tiled plane is created via the "new" operator, the order in which the body of the constructors will execute is: a. tplane_t, plane_t, material_t, b. obj_t, material_t, plane_t obj_t tplane_t c. plane_t, tplane_t d. only the tplane_t constructor will execute automatically Computer Science 215 Quiz L Name ______________________ 1. Suppose the texplane_t::dump_obj() function contains the following code: void texplane_t::dump_obj( FILE *out) { fplane_t::dump_obj(out); a. The fplane_t:: prefix in the b. the fplane_t:: prefix is serves line shown will create a only to document whats going on. syntax error Removing it will have no effect on program behavior c. Removing the fplane_t:: prefix will cause an infinite recursion loop 2. In C++ the constructors of the superclasses of a derived class a. should always be invoked by the b. will all be automatically invoked derived class using a technique whenever an instance of the such as the one shown above derived class is created. c. must be invoked by the derived class only if parameters are to be based to the constructor 3. The particular superclass constructor to be used when an instance of the derived class is created is specified a. along with the inheritance b. in the class definition of the in the class definition of superclass the derived class. c. in the definition of the d. in the definition of the constructor method of the constructor method of the superclass derived class. 4. Which of the following is NOT loaded by the texplane_t constructor ITSELF. a. name of a texture (.ppm) file b. world coordinate dimensions of the textured plane c. texture mapping mode Computer Science 215 Quiz M Name ______________________ 1. In the C++ raytracer pixmap_t, ray_t and pixel_t are related as follows: (creates means: uses "new" to create an instance of) a. pixel_t creates pixmap_t b. pixmap_t creates ray_t which which creates ray_t creates pixel_t c. ray_t creates pixel_t d. pixmap_t creates pixel_t which which creates pixmap_t creats ray_t 2. Suppose an image of 1000 x 1000 pixels is created with 10 antialised samples per pixel and an average of 4 specular bounces per ray. The total number of ray_t's created and destroyed is closest to: a. 5 b. 50 c. 50,000 d. 50,000,000 3. For the pixel_t class method is able to access elements of the view_t class as in: (circle all that will work). *(world + 0) = (1.0 * x / v->win_x_size) * v->world_x_size; *(world + 1) = (1.0 * y / v->win_y_size) * v->world_y_size; a. world_x_size and friends b. the view_t class can can be declared public declare pixel_t to be a friend c. the pixel_t class can declare view_t to be friend. 4. The "protected" attribute is used to a. permit derived class b. permit superclass methods to methods to access access derived class data elements superclass data elements c. permit methods belonging to friend classes to access data elements of this class. 5. Which of the following is a "safe" way to avoid having to pass a view_t pointer to map_world_to_pix(). a. view_t *view_init( b. view_t *view_init( int argc, int argc, char **argv, char **argv, FILE *in) FILE *in) { { char buf[256]; char buf[256]; view_t *view; static view_t *view; view = malloc(sizeof(view_t)); view = malloc(sizeof(view_t)); : : return(view); return(view); } } c. Neither one of these will work. Computer Science 215 Quiz N Name ______________________ 1. The use of static casts a. is a necessary element of b. can almost always be avoided virtually all C++ programs by proper use of virtual functions and inheritence 2. Suppose light is an instance of light_t which is derived from illum_t. The proper way to construct a pointer to the illum_t is: a. illum_t *illum = static_cast(light); b. illum_t *illum = (illum_t *)(light); c. illum_t *illum = illum_t *(light); d. can't be done because upcasts are not supported. 3. Static casts can be used to cast pointers from: a. only base class to derived class b. only derived class to base class c. either direction 4. Suppose both light_t and plane_t are derived from obj_t. An attempt to cast a pointer from an obj_t which is actually a sphere_t to a light_t pointer a. will cause a syntax error b. will compile correctly at compile time but will produce a pointer that is not useful at run time c. will automatically convert obj_t from being a sphere_t to being a light_t Computer Science 215 Quiz O Name ______________________ 1. How many bytes of storage does an instance of the following union occupy: union u_type { double d; int x; float y; char c; char z[6]; }; 2. Consider the following definition typedef struct obj_type { int objtype; union sub_types { sphere_t s; plane_t p; } subs; } obj_t; obj_t obj; Which of the following is the correct way to access the radius of the sphere: a. obj.s.radius; b. obj.sub_types.s.radius; c. obj.s.subs.radius; d. obj.subs.s.radius; 3. Given the following declarations answer "T" or "F" depending upon whether the assignment statment is syntactically correct obj_t o; obj_t *po; obj_t *ppo; ____ a. po = *ppo; ____ b. po = *o; ____ c. *ppo = po; ____ d. ppo = &po; 4. Suppose ppo is of type obj_t **. The assignment ppo += 1; will cause the true value of ppo to be incremented by a. 1 b. sizeof(obt_t) b. sizeof(obj_t *)