Fall 2002 Test #3

CSE1320                                                                                                         Sections 003 and 501

Thursday, October 31, 2002                                                                                             Dr. Tiernan

 

Name:                                                                                             Section:                                             

Student ID:                                                                                     Keyword:                                         

 

Instructions:

 

1.   Fill in your name, student ID, and section above. Choose some keyword for yourself that I can use to anonymously post grade information. If you do not choose a keyword, I will use the last four digits of your student ID to post grade information if needed.

 

2.   This is a closed book, closed notes, NO CALCULATOR test.

 

3.   The test is worth a total of 100 points. The value for each question is given either at the top of that section of questions or in curly braces to the right hand side of the question. There are extra credit questions at the end of the test worth an additional 10 points total.

 

4.   You may not rely on the textbook, your notes, other supporting materials or the contents of someone else’s test.

 

You may fill in the blanks on this page but

DO NOT begin the test until Dr. Tiernan indicates

that you may do so.


Multiple choice questions are worth four {4} points each. Please circle the letter indicating your choice for the answer.

 

1.   The property that defines where a variable can be seen in a program:

A)  storage class

B)  scope

C)  seek

D)  stdio

 

 

 

2.   Which of the following does not refer to an error handling capability in the C library?

A)  perror

B)  errno

C)  flerror

D)  clearerr

 

 

 

3.   Write the name of the storage class that matches each description {12 points total ; 2 each}

i)                      prevents a global variable from being used in another file

ii)                     hides the implementation of a physical or hardware dependent type

iii)                    allows a variable to keep its value through multiple function calls

iv)                   connects a variable declaration to a definition in another file

v)                    is the default storage class for variables

vi)                   suggests a storage location to the for a variable that will be frequently

                        accessed in the program

 


4    This question has four parts.

A)  Create an enumerated type called sport that has six different elements which each represent a sport, for example synchronized_swimming, shuffleboard, soccer, saber, or any others. Assign values to the elements which will indicate whether they are scored in a floating point fashion – like Olympic scoring - (give all of those sports the same value), an integer fashion (give all those sports the same), or some other fashion. Assign separate values (different from the integer and floating point values) for any other methods of recording the results of the sporting event.                                                                       {9}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

B)  Create a union type called score that can record a score for the sports included in your enumerated type above. Make sure your union includes at least a floating point number member (for Olympic style scores) and an integer member (for soccer type scores) and other members as needed for your sports types above.                                                                                                                     {5}

 

 

 

 

 

 

 

 

 

 


C)  Declare a structure that contains the following pieces of data:                                            {6}

a date,

an event title,

a variable of the enumerated type you declared in part A which will hold the enum type value corresponding to the event being stored,

a variable of the union type you defined in part B to hold the event results

the name of the contestant or team participating

the name of the second contestant or team, if appropriate (this member should have the value NULL or 0 if the event is a single person event

a bit field of 6 bits to record a team or bracket number up to 63

a pointer to a structure of this same type

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

D)  Declare three pointers to the structure type defined in part C above that you would use in creating a linked list. Include comments indicating how each pointer would be used. Using one of the pointers, create a new structure. Initialize the link in the new structure to NULL. Initialize the bit field to 31. Assign values to the enumerated type member and the union member.                         {9}

 

 

 


5.   Declare a variable lostangles that is a function with two parameters, a string and an integer, and a return type that is a pointer to a function with three parameters, all float, and a return type of pointer to void.                                                  {8}

 

 

 

 

 

 

 

 

 

6.   Write in words the type of variable foundedges below: (assume NUM is defined)                                                                                                                                         {9}

 

      char *(*(* foundedges[NUM])(struct sport, int, int))(double);

 

 

 

 

 

 

 

 

 

 

 

7.   Write the necessary declarations and statements to attach a file pricelist.dat to a file variable and open the file for reading only.                                                                  {6}

 

 

 

 

 

 

 

 

 

8.   This question has two parts.

A)  Declare a multi-dimensional array to store 100 prices by layer, row, and column. There will be no more than 5 prices in any row and no more than five rows in any layer.                                                                                                                {6}

 

 

 

 

 

 


B)  Write a code fragment to read price data into the array from the file you declared in question 7. All prices should be between the values of 0.01 and 999.99. Any price outside that range should be replaced 0.00. The file will contain floating point numbers in floating point format. Your code fragment should read either 100 prices or until the end of the file, whichever comes first. The prices will be stored in column order from lowest column, lowest row, lowest layer, i.e. so the first price in the file is for item 0,0,0 and the next price in the file is for item 0,0,1 and so on.                                                                            {10}

 

 

 

 

 

 

 

 

 

 


9.   Write a C program that gets two integers and a character input from the command line. You should also define a floating point global variable. The program should then do one of the following: If the character input is ‘a’, the program should add the two integers and print the sum. If the character is ‘m’, the program should multiply the first integer and the global variable and print the product. If the character is ‘s’, the program should subtract the second integer from the global variable and print the difference. Otherwise, the program should print a message which gives the values of the two input integers and the global variable.                                                                                            {12}

 

 

 


Extra Credit questions - Worth two {2} points each.

 

XC1.   If x has the value of 4, which of the following will return 16?

 

A)  x ? x + x : x * x

B)  x == 4 ? x + x : x * x

C)  x == 4 ? x ^ 2 : x + x

D)  x ? x * x : x + x

 

XC2.   The values in an enumerated type are

 

A)  character variables

B)  constants

C)  character strings

D)  integer variables

 

 

XC3.   Which of the following will NOT access the second column and third row of an array?

 

A)  array[2][3]

B)  *(array[2]+1)

C)  *(*(array + 2) + 1)

D)  array[2][1]

 

XC4.   Which of the following is NOT related to random access in a file?

 

A)  ftell

B)  the type of data in the file

C)  the location of the file pointer

D)  fseek

 

 

XC5.   Draw a small picture of a linked list of 6 struct feelings as defined below that expresses your emotions about this test. Make sure to fill in a value for the character array in the structs.                                    [ANY answer will receive 2 points]

 


struct feelings {                                                     Drawing example:

      char word[5];

      struct feelings *more;

}