SAMPLE FINAL EXAM

1 (40 points) The following structure:

struct
{
int b [3200];
} button;

is used to store one 64 pixel wide by 50 pixel tall button image. The values in the array represent color numbers for display. The 3200 pixels which represent a button image are stored in row order (i.e., the first 64 values are the color numbers for the first row of pixels; the next 64 numbers are the pixel color numbers for the second row, etc.). Ten button images are stored in the file c:\butttons.img. Write the C program to read the ten button images from the file and display them on the screen. The ten buttons should be placed side-by-side across the top the screen. The button images should be placed left to right on the screen in the same order as they are read from the file. Assume a 640x480 screen. Omit the initgraph components of the program. Use fopen ("c:\buttons.img", "r"), fclose(file), and fread(file,length,number,struct-name).

2 (30 points) Given:

int alice [1000] = { 5, 11, 33, 14, .... 992 more here..., 21, 34, 15, 2};

No numbers occur in alice more than once (i.e, all values in alice a unique). Write the C program to display the smallest 10 values in the array. The do not have to be displayed in any particular order.

3 (30 points) Given:

Using ONLY the putpixel(hor,vert, color_num) command, create the character “E” on the screen. The letter should be 70 pixels tall and 50 pixels wide. The wide and height of the character elements should be 10 pixels. The letter should be blue (color_num=1) on a yellow (color_num=15) background. Write the C program which: (1) gets from the user the screen location for ther top of the letter (between 0 and 400); (2) gets from the user the screen location for the left side of the image (between 0 and 500); then (3) displays the letter at the locations provided by the user.


Return to syllabus