CSE1320 Test #2 Section 002

Spring 2007 Test #2

CSE1320 Section 002

Wednesday, April 4, 2007 Dr. Tiernan

Name: Section: 002

Student ID:

Instructions:

1. Fill in your name, ten-digit student ID, and section above.

2. This is a OPEN book, OPEN notes, NO CALCULATOR test. No digital electronics of any sort are allowed to be used during the 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.  If you do not understand a question, raise your hand and I will come over for you to ask me about it. I may or may not answer your question but you should still ask.

5.  In questions where I have given you code to use, if you find typos, assume that the code is SUPPOSED to work and just indicate what assumption you made for your answer. This applies in all cases unless the question is specifically about the syntax of the code - in which case there are errors on purpose.

6.  I will always try to give partial credit so the more of your work that you show, the more I am able to grade for partial credit if the answer is not entirely correct. It is to your benefit to show your work on the test.

NO CHEATING!


Page 4 of 7

CSE1320 Test #2 Section 002

1. Which command allows input of many types of data? {3}

a. fgets

b. getchar

c. scanf

d. fread

2. Answer the following about command line arguments.

a. How many parameters can the operating system pass to a C main routine? {3}

b. How many parameters can be passed to the main on a command line? {3}

c. What is the data type of the first parameter passed by the OS to a C main? {3}

3. Given the diagrams below, name the specific ADTs represented by the diagrams.

{4 each; 8 total}

a.

b.

4. If a program has the following:

#ifdef FRED

printf(“The Flintstones Rock!”);

#endif

and it has no define statement for FRED, what happens to the printf? {8}


5. Create a struct type to represent a book. The struct should contain an author’s last name, an author’s first name, an author’s middle initial, a title, an ISBN number, a publication year, an enumerated type code indicating paperback, softcover, hardcover, or audioCD, a union with a number of pages for paperback, softcover and hardcover or a floating point number indicating the running time in hours and minutes (hh.mm) for the audioCD, a retail price, a wholesale price, and a date indicating when this book became available for sale. Be sure to declare everything you use in the struct. {20}


6. Write a code fragment to read 20 prices from a file into an array of 20 of the book structures that were defined in question 5. Declare the array and the file pointer and any variables you use. {17}

7. Describe in words, pictures, and/or pseudocode the representation and behavior that defines a singly linked list. {8}


8. Define a struct type with three bit fields to represent a person’s age, a person’s weight, and a reasonable maximum number of children a person might have. Use the minimum sizes needed for each of these bit fields. {6}

a. How many bits did you use for age and why? {2}

b. How many bits did you use for weight and why? {2}

c. How many bits did you use for reasonable maximum number of children and why? {2}


9. Given the following fragments of C code answer the questions below.

struct element {

int data;

struct element *another;

};

void funcone( struct element **use, int stuff) {

struct element *have;

have = (struct element *) malloc (sizeof (struct element));

have->data = stuff;

have->another = *use;

*use = have;

}

int functwo( struct element **use) {

struct element *have;

int got;

have = *use;

got = (*use)->data;

use = (*use)->another;

return got;

}

int functhree(struct element *use) {

return (use == NULL);

}

// assume valid C code here

struct element *datastr;

int info = 99;

// assume valid C code here

funcone(&datastr, info);

a. What ADT is being implemented? {3}

b. What physical structure is being used to implement the ADT? {3}

c. Given you answer to part a. above, tell below what names should replace the function names used in the code fragment:

i. funcone should be {3}

ii. functwo should be {3}

iii. functhree should be {3}

Extra Credit

XC1. Name at least two differences between a sequential access file and a random access file. {4}

XC2. Write a macro called ned to print the message “Toodley ooh, neighbor name!” where name is passed as a parameter to the macro ned. {4}

XC3. Name your favorite cartoon and describe some way that the C language relates to this cartoon. {ANY answer will receive 2 points}

Page 4 of 7