



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: C and Software Tools; Subject: Computer Science; University: North Carolina State University; Term: Spring 2006;
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Questions Q1-Q6 carry 3 marks each. Indicate your answer by circling “a”, “b”, etc. Circle all the correct answers, for each question. Q7 carries 14 marks. Q8 carries 8 marks. Q9-Q10 each carry 20 marks. Q carries 25 marks. Although this adds up to 105, a perfect score is 100. If you obtain more than 100, your marks will be added up to 100 and will be considered 100%. It should be possible to answer the questions in the space provided. Use the back of the paper if you absolutely have to. You may not attach extra sheets. 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. All effort has been made to make the test completely unambiguous. However, should you still face a dilemma, you should simply make the assumption that seems most reasonable to you. In your answer, write down briefly and clearly the ambiguity in the question that requires you to make an assumption, what exactly is the assumption you made, and then answer the question correctly based on that assumption. You will be graded on the basis of that assumption. Caution: you are only privileged to make an assumption when the question leaves some pertinent point unstated. You cannot make an assumption that simply goes against a stated condition of the question; that will earn you no score. This is a three hour test.
void func1 (double *p, int max) { int i; double q; #ifndef REVERSE for (i=0; i<max; i++) #else for (i=max-1; i>=0; i--) #endif { q = p + i; / some code utilizing q, etc.... */ } return; }
char *stripTrailingBlanks (char s) { / Given a pointer to a string, modify the original string so that if there were any trailing blanks, they are removed. Return pointer to original string. / char p; p = s + (strlen (s) - 1); / Point to last character / while (p == ' ') { / Scan backward as long as we find trailing blanks / / Insert code here ONLY */
return (s); }
int doesBlockContain (const double p, double x, unsigned int n) { / Given a pointer p to a block of doubles and an integer number n, return 0 if any of the first n doubles pointed to by p are equal to x, 1 if not. / int i; int return_value = 1; for (i=0; i<n; i++,p++) { if (p == x) { return_value = 0; break; } } return (return_value); }
void allocate_and_init_cities (int n) { long *population, area, distance; / Insert code to allocate memory and initialize HERE / if ((population = calloc (n, sizeof (long))) == NULL) { exit (EXIT_FAILURE); } if ((area = calloc (n, sizeof (long))) == NULL) { exit (EXIT_FAILURE); } if ((distance = calloc (nn, sizeof (long))) == NULL) { exit (EXIT_FAILURE); } / Other code, possibly to read in values / / Using values below */ for (i=0; i<n; i++) { printf (“Population of City %d is %d, area is %d\n”, i, population[i], area[i]); for (j=0; j<n; j++) { printf (“Distance from City %d to City %d is %d\n”, i, j, distance[n * i + j] } }