Student Name: (in Capital Letters) CSE 1311 Introduction to Programming for Engineers and Scientists Final Exam Fall 2013 1
1. If count is a properly defined integer variable, the following piece of code: (3 Points) count = 3 ; while (count--) printf ("Looping...\n"); will print "Looping..." (a) Once. (b) Twice. (c) Three times. (d) Four times. (e) Five times. (f) It will keep printing it forever. (g) It will not print anything. 2. Which of the following is a legal statement in C: (3 Points) (a) x < y = z = (u = v); (b) a = b = c = (d > e); (c) m - n - k *= (4 / j); (d) a int b double c; 3. A side effect occurs in programming when (2 Points) a. A global variable is misused, and the error goes throughout the program b. A parameter is passed to the wrong data type. c. A function is called in the wrong order d. All of the above 2
4. An Exit statement causes (3 Points) An Exit statement causes a. The loop to terminate b. The program to terminate c. Returns the control back to the loop d. To skip the next statement only 5. Formal parameters to a function: (3 Points) (a) Must match the actual parameters in number, types and names. (b) Must match the actual parameters in number and names, but not necessarily in types. (c) Must match the actual parameters in number and types, but not necessarily in names. (d) Must not match the actual parameters in their names. 6. The do while loop will (3 points) a. Always be executed at least once b. Be executed only once c. Always be executed until the condition remains true d. None of the above 7. In order to pass a two-dimensional array to a function (3 Points) a. The name of the array in the called function must be exactly the same as the name in the calling function. b. The size of the first dimension must be included in the parameter declaration c. The sizeof command must be called each time. d. All of the above 3
8. Complete the following program segment that will print the value of the counter from 20 to 1. (3 points) int Counter; for( ) { } 9. If a, b, c, d and e are all integer variables, and a is 15, b is 72, c is 31, d is -4, and e is 19, the value of expression e + d / c * b - a / c will be: (4 Points) (a) 15 (b) -8 (c) 19 (d) 7 (e) -2 4
10. Given that the following array, (4 Points) double Dim[4][4]={ {3.65, 8.2, 2.67,7.64}, {51.9, 6.79, 9.8, 91.7}, {5.16, 5.79, 3.84, 2.07}, {4.11, 56.8, 92.7, 13.1} }; What are the values for Dim[0][0], Dim[2][1],Dim[1][2],Dim[3][3]? a. 3.65, 51.9, 6.2, 3.84 b. 3.65, 5.79, 9.8, 13.1 c. 2.07, 3.65, 2.67, 4.11 d. 3.65, 9.8, 5.79, 13.1 11. The typedef function is used to (3 Points) a. Rename a function b. Rename a variable c. Rename a datatype d. All of the above 12. If (a < b) && ((b < 5) (c > b)) && (b > 3) && (!(c > a)) && (c >= b - 1) evaluates to 1, then a must be: (3 Points) 5
13. Given : (4 points) struct Dam { int height; int width; int depth; float spillway; } struct Pipeline { int length; int width; int radius; float valve; } Which of the two structures uses more bytes, or is larger with a sizeof? a. Dam is larger than Pipeline b. Pipeline is larger than Dam c. Dam and Pipeline are the same size 14. In order to dynamically allocate memory in C, use to allocate the memory and to de-allocate the memory. (4 Points) a. memget, memdel b. malloc, falloc c. malloc, free d. free, malloc e. none of the above 15. In order to perform recursion, a function (4 points) a. Has to call itself b. Has to end when the initial conditions are met. c. Has to have the continue statement. d. Both a and c e. Both a and b 6
16. With the following definitions: (4 Points) int first (int a, int b); int second (int c); and the following variable declarations: int my, your, their; the following assignment: my = second ( first (your, their)); (a) is legal in C. (b) is not legal in C. (c) is not legal as is, but it would be legal without the parentheses. (d) is not legal in C, but it would have been legal if it were written in two lines instead of one. 17. Consider the following piece of code (a and b are properly declared integer variables): if (1 >= (a == b)) (4 Points) printf ("Cookoo\n"); (a) This piece of code will always print "Cookoo". (b) This piece of code will not print anything. (c) This piece of code will print "Cookoo" only if values of a and b are same. (d) This piece of code will print "Cookoo" only if values of a and b are different. 18. The case statements of a switch statement can be used with an enumerated type. (4 Points) This is because a. Enumerated types are declared at the beginning of a program. b. Enumerated types act as constant integer values c. Enumerated types are in ascending order d. Case statements continue until a break is found 19. Upon which of the following sets of numbers will a Binary Search work? (4 points) a. 37, 24, 42, 53, 68 b. -29, -35, 43, 55, 63 c. -34, -26, 47, 47, 62 d. All of the above 7
20. Write a short program that will take in from standard input a series of words, and then duplicate each word as in the following: (12 Points) I am happy to be here becomes II amam happyhappy toto bebe herehere Use the strcpy command and the strcat command. The words should be processed inside of a loop. Use strcmp for the word quit, which will make the loop end. (write your program on the following page). 8
9
21. Create a structure that represents a student. The student should have a name, address, and the day, month, and year of birth, and grade point average. Then, use this structure in a short program. Show how to load the structure member by member using the correct notation and library functions. Do not initialize using {}. Then, print out the contents of the structure to screen. (10 Points) 22. What is the following binary number as a hexadecimal? (4 Points) a. A b. 9 c. 72 d. 100 e. A1 1001 10
23. Write a function that takes the addresses of two characters, and swaps the value stored at those integers such that the change remains in effect when the function returns. (pass by reference). (9 Points) 11