MECH 415 Exam Review Questions #1
Question #1
Write a function (a regular function not a member function) called mix_buffers(buffer1,buffer2,buffer3) that combines two equal size Buffer objects buffer1 and buffer2 (from review1, lecture #23) into a larger object buffer3 randomly alternating/shuffling the elements (using the ran() function from the random numbers example, lecture #23). For example, A1[] = "abcde", A2[] = "12345" would give A3[]="a12b3cd45e".
Question #2
Write a function called re-mix(buffer1,buffer2,buffer3) that equally divides buffer3 into two equal buffers buffer1 and buffer2. It then mixes them using the function from question #2. Note that buffer1 should be composed of the first half of buffer3 and buffer2 the 2nd half.
Question #3
Write a main function that demonstrates your functions from Questions #1 and #2.
Question #4
Write a function called file_compare(file_name1,file_name2) that compares two binary files (the names of the files are given by the string variable arguments). It returns one if the two files are the same (i.e. each byte of the two files are equal) and zero otherwise. When writing the function use dynamic memory and buffers of size 100. Write a main function that illustrates/tests the function. Try not to cut and paste from the lecture examples when solving this problem (you can look at the formula sheet though).
Question #5
Write a class called car based on the model from graphics example #6 (project organization) from lecture #19. This class is an object oriented re-organization of example #6, similar to your project (a basic organization). It has the following public member variables:
dt – the simulation time step (s)
N – the number of state variables (i.e. the size of X)
X – a dynamic 1D array used to store the state vector of the system
t – simulation time (s)
P_mesh – a pointer to a mesh object used to draw the car.
Px, Py, Pz – the translation of the mesh object (used when drawing it)
yaw, pitch, roll – the rotation of the mesh object (used when drawing it)
The class also has the following public member functions:
A constructor with the arguments P_mesh and file_name. The member variables (except for P_mesh) are read from a text file in the order they are listed above.
A destructor.
void sim_step() – a function with no arguments that simulates the car for one time step of dt.
void draw() – a function with no arguments that draws the car using the mesh object.
Question #6
Illustrate the use of the car class by writing an appropriate draw_3D_graphics() function (just modify the graphics example #6 project organization example) to use the car class and its member functions (instead of the other variables and functions).