Docsity

Final Test Fall 2007 - Software Tools | CSC 230, Exams of Computer Science

Toggle sidebar
bg1
CSC 230 Section 001
Final test
April 30, 2007
Questions 1 – 10 carry 2 marks ea ch. Answer only by entering a check mark in the appropriate box for
each question, and leaving the other one blank.
Questions 11 – 20 carry 2 marks each. Answer on ly by filling in the blank by writing the correct answer.
Questions 21 – 30 carry 2 marks each. Answer on ly by writing the v alue that the variable x will have after
the statements shown are executed.
Questions 31 and 32 each carry 10 marks, and Ques tion 33 carries 20 marks. Answer as directed.
It should be possible to answer the questions in the space provided. Use the back of the paper wher e you
are specifically ask ed to. Otherwise, do not use the back of the paper or attach extra sheets unless you
absolutely have to. You may consult any books, no tes, etc., but no other person. You must not use a
cellphone, comput er, PDA, or any other information processing device.
This is a three hour test.
First Name: _____________________________
Last Name: _____________________________
Student ID: _____________________________
Pledge of Honor: I pledge on my honor that I have answered the questions
in this test purely on my own individual ability, and have neither given help
to nor received help from another person.
Signature: __________________________________________
pf3
pf4
pf5

Partial preview of the text

Download Final Test Fall 2007 - Software Tools | CSC 230 and more Exams Computer Science in PDF only on Docsity!

CSC 230 Section 001

Final test

April 30, 2007

Questions 1 – 10 carry 2 marks each. Answer only by entering a check mark in the appropriate box for each question, and leaving the other one blank. Questions 11 – 20 carry 2 marks each. Answer only by filling in the blank by writing the correct answer. Questions 21 – 30 carry 2 marks each. Answer only by writing the value that the variable x will have after the statements shown are executed. Questions 31 and 32 each carry 10 marks, and Question 33 carries 20 marks. Answer as directed. It should be possible to answer the questions in the space provided. Use the back of the paper where you are specifically asked to. Otherwise, do not use the back of the paper or attach extra sheets unless you absolutely have to. You may consult any books, notes, etc., but no other person. You must not use a cellphone, computer, PDA, or any other information processing device. This is a three hour test.

First Name: _____________________________

Last Name: _____________________________

Student ID: _____________________________

Pledge of Honor: I pledge on my honor that I have answered the questions

in this test purely on my own individual ability, and have neither given help

to nor received help from another person.

Signature: __________________________________________

TRUE FALSE

1. Linker errors can only be caused in programs that are made by

compiling more than one source file.

2. It is possible to compile a C file with a “pre-compile only”

flag, so that the pre-processed output is generated, but no

object code is generated.

3. Global variables invariably have internal linkage.

4. A pointer can point at a structure, but cannot point to an

element which is a member of a structure.

5. The function printf may sometimes have no arguments

following the format string, but the format string must be

presented in the function call.

6. It is not possible to compile two files separately, each without

errors or warnings, if one contains the definition of a function

and the other one contains code calling that function.

7. Any compiler error or warning causes no executable output to

be built.

8. cout << i; is a valid C language statement to print the value

of i.

9. Including a header file for a library (such as the math library)

automatically links in that library at linking time.

10. The following statement copies the string pointed to by s2 into

the string pointed to by s1:

s1 = s2;

X X X X X X X X X X

x equals

21. int^ x^ =^7 %^3 %^9 %^2 %^ (4^ %^ 1);^ 1, or

“impossible

  • illegal”

22. int^ i^ =^ 10,^ j^ =^ 29,^ x^ =^ 30;

x = x+i+++--j;

2 3. int^ w^ =^ 36,^ y^ =^ 7,^ x;

x = (w / y) + (w % y) * y;

24. int^ x;^ char^ a[32],^ *b;

b = &a[10]; x = (a + 19) – b;

25. int^ i^ =^ 5,^ j^ =^ 5,^ x^ =^ 0;

do {x += (i += j);} while (j-- > 0);

26. int^ x^ =^ 0,^ *p^ =^ &x;

*(p++) = 20;

20, or

“program

might crash

27. int^ x;^ int^ y^ =^ 35;

x = y >> 2;

28. int^ x^ =^ 10,^ *p^ =^ &x;

*p = px;

29. int^ w^ =^ 1,^ y^ =^ 7,^ x;

x = (w && y) | y;

30. int^ k[]^ =^ {20,^ 30,^ 40,^ 50,^ 60};

int i = 3, *ip = &i, x; x = *(ip = &k[3]-1);

  1. Consider the following complete program (intended to be treated as a single file and compiled into a binary executable). In the table below, write down the values of the variables and expressions specified after the corresponding line of code has been executed in the spaces provided. (If it is not possible to write down the value, indicate why.) For any question, interpret the variable names the same way that the compiler would interpret it at that point in the code , according to the rules of scope, linkage, etc. For ease of reference, some lines of code have been numbered, these numbers are not part of the actual code. #include <stdio.h> #include <stdlib.h>
  2. #define THRESH 5
  3. int i, j;
  4. unsigned short flip (int *p1, int *p2)
  5. {
  6. if (*p1 > *p2)
  7. {
  8. int i = *p1;
  9. *p1 = *p2;
  10. *p2 = i;
  11. }
  12. return (i<=*p1);
  13. }
  14. int main (int argc, char **argv)
  15. {
  16. int q[] = {6,64,3,5,7,4,43,16,34,9};
  17. int i, j, k;
  18. {
  19. extern int i;
  20. i = THRESH;
  21. }
  22. for (i=0; i<10; i++) {
  23. for (j=i+1; j<10; j++) {
  24. k = flip (q+i,q+j);
  25. }
  26. }
  27. } Just after line 22 finishes executing i^5 Just before line 24 begins executing i^ Indeterminate Just before line 24 begins executing j^ Indeterminate Just before line 7 starts executing, first call of flip *p2^64 Just after line 11 finishes executing, first call of flip *p1^ Does not execu Just before line 10 begins executing, second call of flip i^6 Just before line 10 begins executing, second call of flip *p2^3 Just after line 11 finishes executing, second call of flip *p2^6 Just before line 13 begins executing, third call of flip *p2^5 Just after line 28 finishes executing k^1
  1. A program uses linked lists with the following data structure as a list element. The list is doubly linked, every element points to its previous and next. The previous field of the first element and the next field of the last element are set to NULL. A global variable g_listHead points to the first element. The list is kept sorted by decreasing order of age and then by increasing order of income (i.e. elements tied on age are sorted by income). struct list_data { int age; int income; } typedef struct s_list_element { struct list_data; struct s_list_element *next, *previous; } list_element; Write a function with the following functionality. The function is passed a pointer new to a list_element which is not currently in the list. The given element must be inserted in the list, in the appropriate sorted order, and the list left in correct state. However, if an element already exists in the list with the same age and income as the new one, it must not be inserted; instead the new element should be deallocated. You cannot assume that any other functions already exist to manipulate the list. The grading points on this one were: Major:
  2. Appropriate manipulation of both sets of pointers, forward and reverse – to leave the list consistent
  3. Comparison of age field and income field in correct order, recognizing that the “right place” is past if attempting to avoid scanning entire list Minor:
  4. Deallocating as required
  5. Loop to scan the list upto the right place
  6. Correct typing of argument to function and local variables