VIZA 653 -- Computing for Visualization II



DPA 4010/6010Sample Final Exam QuestionsApril 21, 20161.(10 pts) The function push() below is supposed to take a pointer to the first node in a linked list as its first input parameter, and insert its integer parameter into the list at the beginning. push() is supposed to return the updated list. However, it does not work correctly. Supply the fix or fixes necessary to correct it.struct Node{int number;Node *link;};Node *push(Node *first, int n){Node *newnode;newnode->number = n;newnode->link = first;return first;}2.(10 pts) Given the vectors a = , b = compute2832735-715645101001012146935-71564512100121 a) || a || b) unit vector in the direction of a c) a ? (a - b)The cosine of the angle between a and b3.(15 pts) You are given a rectangle with edges of length 1, with a corner at the origin (0, 0), and edges from this corner along the positive x, and y axes. Please write the following transforms expressed as 2x2 matrices: squash and stretch the rectangle into a ramp with dimensions 10 x 0.1 in the x, and y directions respectively,tip the ramp up so that the end at the origin remains at the origin, but the ramp is elevated along its long axis to a 30 degree angle with the ground x-axis, give an equivalent single matrix that will do both operations at once.4.(5 pts) Convert the following dynamic allocation of an array of 10 integers from C to C++:int *a;a = (int *)malloc(10 * sizeof(int));5.(10 pts) Write what the following C++ program will print to the command window. If the program is not doing what you would have expected, please show how to fix it.void swap(int a, int b){int temp;temp = a;a = b;b = temp;cout << “a = “ << a << “, b = “ << b << endl;}int main(){int x, y;x = 3;y = 5;cout << “x = “ << x << “, y = “ << y << endl;swap(x, y);cout << “x = “ << x << “, y = “ << y << endl;}(10 pts) Given the triangle with vertices p1 = (0, 3), p2 = (2, 0), and p3 = (3, 2), compute the distance of vertex p2 from the edge formed by vertices p1 and p3.(10 pts) Given the following C++ object interface for a 2-dimensional point, write an object interface for a triangle. (Note: your code should include only the interface!) Your triangle object should have at least two constructors: a default, and one that accepts three vertices as 2D points. The triangle should also have methods to do the following: 1) uniformly scale the size of the triangle, 2) draw the outline of the triangle with the corners emphasized by dots, and 3) return true or false to indicate whether or not a given point is inside the triangle (you don’t need to know how to do this, since you only need to write the interface).// 2-Dimensional Point classclass Point{public:float x, y;// point coordinatesPoint(float x0 = 0, float y0 = 0);// constructor (x0, y0)void setpoint(float newx, float newy);// set to (newx, newy)void translate(float dx, float dy);// move by (dx, dy)int hit(Point cursor);// returns TRUE if cursor near pointvoid draw();// draw the point as a dot}; // Triangle class(10 pts) Write the implementation of the drawing method for the Triangle class defined in question 7. Assume that the Point class and all of its methods are available to you.(20 pts) C++ Class ConstructionFor this question you are to design a Quarterback object that could be used in a program for Clemson Tiger football coach Dabo Swinney. The program would be used to keep track of quarterback performance. For each quarterback on the team, Dabo needs to know their name and player number. He also needs to be able to keep track of the number of attempted passes, number of completions, number of interceptions, and number of touchdowns. You are not being asked to write the program described below, only to design and write the interface and parts of the implementation of the Quaterback object.Assume that the program that does this is started up at the beginning of the season and keeps running until the end of the season, so there is no need to store anything on disk -- i.e. everything is in memory. When the program starts up everyone starts fresh -- i.e. all statistics are set to zero. Once set, a player's name and number never change. After each game, Dabo enters the statistics for each quarterback that played in that game into the computer. Whenever he desires, he should be able to determine any of the statistics for a quarterback. He also wants to be able to determine the player's completion ratio (ratio of completions to attempts), and it is desireable to be able to easily compare two quarterbacks by comparing their completion ratios. To facilitate this you should provide an overloading for the > operator. It should return true if the first quarterback (the one to the left of the > sign) has a higher completion ratio than the second, and should return false otherwise.Please provide the complete C++ class and interface definition (that would be found in the .h file). Then, only provide implementations for any constructors, a member function to return the quarterback's name, a member function to update statistics (that would be called after each game), a member function to return the completion ratio, and the > operator. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download