1D04ExamQuestions - Engineering 1D04 DAY CLASS DURATION OF...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 1D04 DAY CLASS DURATION OF EXAMINATION: 60 minutes McMaster University Midterm Examination Dr. K. Kreyman and S. Smith February 15, 2001 THIS EXAMINATION PAPER INCLUDES 11 PAGES (INCLUDING THIS PAGE) AND 20 QUESTIONS. YOU ARE RESPONSIBLE FOR ENSURING THAT YOUR COPY OF THE PAPER IS COMPLETE. BRING ANY DISCREPANCY TO THE ATTENTION OF YOUR INVIGILATOR. Special Instructions: Candidates may NOT use calculators, notes or textbooks. Your answers are to be written on the answer sheets. OMR EXAMINATION - INSTRUCTIONS NOTE: IT IS YOUR RESPONSIBILITY TO ENSURE THAT THE ANSWER SHEET IS PROPERLY COMPLETE. YOUR EXAMINATION RESULT DEPENDS UPON PROPER ATTENTION TO THESE INSTRUCTIONS. The scanner, which reads the sheets, senses the shaded areas by their non-reflection of light. A heavy mark must be made, completely filling the circular bubble, with an HB pencil. Marks made with a pen or felt-tip marker will NOT be sensed. Erasures must be thorough or the scanner will still sense a mark. Do NOT put any unnecessary marks or writing on the sheet. 1. Print your name, student number, course name and the date in the space provided at the top of Side 1 (red side) of the form. The sheet MUST be signed in the space marked SIGNATURE. 2. Mark your student number in the space provided on the sheet on Side 1 and fill in the corresponding bubbles underneath. 3. Mark only ONE choice from the alternatives (1,2,3,4,5 or A,B,C,D,E) provided for each question. If there is a True/False question, enter a response of 1 (or A) as True, and 2 (or B) as False. The question number is to the left of the bubbles. Make sure that the number of the question on the scan sheet is the same as the question number on the test paper. 4. Pay particular attention to the Marking Directions on the form. 5. Begin answering questions using the first set of bubbles, marked “1”. Answer all questions. 6. Please pass the exam itself and your answer sheet to one of the TAs at the conclusion of the examination. ANSWERS ARE IN BOLD Continued on Page 2 Engineering 1D04 Midterm examination Page 2 of 11 For the following questions select the ONE answer that is the most correct: Question 1 A computer can be described as a system since A. includes tangible or physical equipment, which is known as hardware. A. it it includes tangible or physical equipment, which is known as hardware. B. it it is designed to solve systems of equations. B. is designed to solve systems of equations. C. computer software is developed as a system of primitive programs. C. computer software is developed as a system of primitive programs. D. it consists of many components that function together to perform an assigned task. D. it consists of many components that function together to perform an assigned task. E. a system concept is used to build computers E. a system concept is used to build computers. Question 2 A Finite State Machine (FSM) is: A. a machine that hashas a finite number parts. A. a machine that a finite number of of parts. B.B. machine that that only only a finite number of observable states. a a machine has has a finite number of observable states. C. a method of program design. C. a method of program design. D. the decomposition of a problem into its individual components, whose behaviour is readily D. the decomposition of a the original its individual components, whose behaviour is readily understood, and then rebuildingproblem intosystem from such components to study the system’s understood, and then rebuilding the original system from such components to study the system’s behaviour. behaviour. E. a device for solving systems of differential equations. E. a device for solving systems of differential equations. Question 3 An algorithmic solution of a problem is the solution that can be reached A. heuristically on the basis of the developer’s experience. A. heuristically on the basis of the developer’s experience. B. due toto analysing field data. B. due analysing field data. C. using advanced computers. C. using advanced computers. D. as a result of the analytical solution of a problem. D. as a result of the analytical E. through a direct set of steps. solution of a problem. E. through a direct set of steps. Question 4 All algorithms, no matter how complex they are, can be described using only basic control structures, which are A. modularization, selection structure and repetition. A. modularization, selection structure and repetition. B. sequence structure, selection structure repetition. B. sequence structure, selection structure and and repetition. C. selection structure, repetition and computations. C. selection structure, repetition and computations. D. pseudo-code, sequence structure and Top-Down design. D. pseudo-code, sequence structure and Top-Down design. Continued on Page 3 Engineering 1D04 Midterm examination Page 3 of 11 Question 5 A pseudo-code is A. an informal language that depends on the programming language that chosen for the development A. an informal language that depends on the programming language that isis chosen for the of the computer program. development of the highly informal language for describing problem solving steps. B. a computer program. B. a one of the high-level programming languages. solving steps. C. highly informal language for describing problem C. one of the high-level programming languages. D. a general procedure for solving complex problems. D. a general procedure for solving complex problems. E. natural machine language. E. a a natural machine language. Question 6 Top-down design is A. a method solving systems of equations. A. a method of of solving systems of equations. B. a systematic approach of of assembling objects from their parts. B. a systematic approach assembling objects from their parts. C. a method for for the developmenta of a computer program allows the joining of theof the efforts of C. a method the development of computer program that that allows the joining efforts of different developers. different developers. D. a systematic procedure for breaking a large problem into smaller, more manageable, D. a systematic procedure for breaking a large problem into smaller, more manageable, subproblems, which can be dealt with separately subproblems, which can be dealt with separately. Question 7 In the following complete pseudo-code algorithm, which line(s) (if any) are incorrect, according to the pseudo-code conventions adopted in Eng 1D04? 1 /* Constants */ 2 MAXN •100 3 begin 4 PRINT “Enter an integer” 5 READ i 6 PRINT “MAXN is equal to: ”, MAXN 7 END A. Lines 22and 77are incorrect. A. Lines and are incorrect. B. Lines and 5 are incorrect. B. Lines 44 and 5 are incorrect. C. Lines and 5 5 are incorrect. C. Lines 3 3 and are incorrect. D. Line 3 is incorrect. D. Line 3 is incorrect. E. All lines are correct. E. All lines are correct. Continued on Page 4 Engineering 1D04 Midterm examination Page 4 of 11 Question 8 Assume two boolean expressions (b1 and b2) have been defined and consider the following loop structure in C: while (!(b1 && b2)) {statement} Which of the following loop structures have equivalent (the same) behaviour as the above loop: A. if (!(b1 && b2)) A. if (!(b1 && b2)) do {statement} while while (!(b1 && b2)); do {statement} (!(b1 && b2)); B. if (b1 && b2) B. if (b1 && b2) do {statement} while (b1 || b2); do {statement} while (b1 || b2); C. for (; b1 ;) {statement} C. for (; b1 ;) {statement} D. do {statement} while (!(b1 && b2)); D. do {statement} while (!(b1 && b2)); E. none of the above E. none of the above Question 9 In the following ANSI C program fragment, indicate which function will be called if a data value of 3 is entered. printf("1: feet to metres, 2: metres to feet\n"); printf("Enter choice: "); scanf("%d", &choice); if (choice == 1) feet_to_metres(); else if (choice == 2) metres_to_feet(); A. Both functions will be called. A. Both functions will be called. B. Neither function will be called. B. Neither function will be called. C. Function feet_to_metres()will be called. D. C. Function feet_to_metres()will be called. Function metres_to_feet()will be called. D. program metres_to_feet()will 1 or 2 E. The Function will wait until a data value ofbe called. is entered. E. The program will wait until a data value of 1 or 2 is entered. Continued on Page 5 Engineering 1D04 Midterm examination Page 5 of 11 Question 10 Hand trace the program that follows: #include <stdio.h> #define MAXI 3 #define MAXJ 3 void main(void) { int i, j; for(i=0; i<MAXI; i=i+1) { for(j=0; j<MAXJ; j=j+1) { if (j%2 == 0) /* j is even */ { printf("*"); } else { printf("^"); } } printf("\n"); } } The output of this program is A. ^*^^*^^*^ A. ^*^^*^^*^ B. *^*^*^*^* B. *^*^*^*^* C. *^* *^* C.*^* *^* *^* D. ^*^ *^* ^*^ ^*^ D.none of the above E. ^*^ ^*^ ^*^ E. none of the above Continued on Page 6 Engineering 1D04 Midterm examination Page 6 of 11 Question 11 According to the order of operations that is used by C, what value will the following integer expression have: 8 + 5*7%2*4 A. 88 A. B. 28 B. 28 C. 12 C. 12 D. 76 D. 76 E. None of the above E. None of the above Question 12 Consider the following three loop structures: 1. for (i=10; i >= 10; i = i + 1) printf("%d", i); 2. i = 0; while (i < 10) printf("%d", i); 3. for (i=10; i>10; i++) printf("%d", i); Which of the above loop structures will terminate without generating an error? A. Loop structure 1 1 A. Loop structure B. Loop structure 2 2 B. Loop structure C. Loop structure 3 C. Loop structure 3 D. Loop structures 1 and 3 D. Loop the above E. None of structures 1 and 3 E. None of the above Question 13 The ANSI in ANSI C stands for A. ASCII Notation Standard Interface A. ASCII Notation Standard Interface B. American Natural Sciences Institution B. American Natural Sciences Institution C. Aaron Nicholson and Stan Inglis C. Aaron Nicholson and Stan Inglis D. Automatic Natural Sciences Interface D. American National Standards Interface E. Automatic Natural Sciences Institute E. American National Standards Institute Continued on Page 7 Engineering 1D04 Midterm examination Page 7 of 11 Question 14 Consider the following declarations: #define NUM_ON_LINE 10 struct worker { char name[80]; int avg_units_per_hour; int avg_errs_per_hour; }; struct asm_line { int product_code; double material_cost; struct worker wkers[NUM_ON_LINE]; } line1, line2; To assign the value of 34 to avg_units_per_hour for the last structure in the array wkers for variable line2, we write A. avg_units_per_hour.wkers[10].line2 = = 34; A. avg_units_per_hour.wkers[10].line2 34; B. line2.wkers[9].avg_units_per_hour = = 34; B. line2.wkers[9].avg_units_per_hour 34; C. avg_units_per_hour.wkers[10].line1 = 34; C. avg_units_per_hour.wkers[10].line1 = 34; D. line2.wkers[10].avg_units_per_hour = 34; D. line2.wkers[10].avg_units_per_hour = 34; E. wkers[10].line2.avg_units_per_hour = 34; E. wkers[10].line2.avg_units_per_hour = 34; Question 15 Which of the following are ALL examples of ordinal types in ANSI C A.A. int, char, enum weekday {mon, tue, wed, thu, fri} int, char, enum weekday {mon, tue, wed, thu, fri} B. B. int, float int, float C. C. int, struct payRecord {long idnum; char name[40]; float rate;} int, struct payRecord {long idnum; char name[40]; float rate;} D.D. float, long int float, long int E. int, char, boolean E. int, char, boolean Continued on Page 8 Engineering 1D04 Midterm examination Page 8 of 11 Question 16 Which line (if any) of the following C program contains an error? 1 #include <stdio.h> 2 void main(void) 3 { 4 int i; float F; 5 printf("Enter the integer value for i: "); 6 scanf("%f", &i); 7 F = i/32.9; 8 printf("\nThe value of F is %f", F); 9 } A. Line 4 4 A. Line B. Line 6 B. Line 6 C. Line 7 C. Line D. Line 8 7 E.D. Line 8 no errors There are E. There are no errors Continued on Page 9 Engineering 1D04 Midterm examination Page 9 of 11 Question 17 For the ANSI C program fragment provided below, indicate the value(s) that will be printed to the screen if the following is typed when the program prompts for input: 10.2 -98.0 0.2 float x, y, z; printf("Enter values for x, y and z: "); scanf("%f%f%f", &x, &y, &z); if ((x>y)&&(x>=z)) { if (y <= z) printf("%.1f ", x); else printf("%.1f ", y); } else { if (y > z) printf("%.1f ", x); else printf("%.1f ", z); } A.A. The value printed to the screen will be 10.2. The value printed to the screen will be 10.2. B.B. The value printed to screen willwill-98.0. The value printed to the the screen be be -98.0. C.C. The value printed to screen willwill0.2. The value printed to the the screen be be 0.2. D.D. The values printedthe the screen will10.2 0.2. The values printed to to screen will be be 10.2 0.2. E. No values will be printed to the screen. E. No values will be printed to the screen. Continued on Page 10 Engineering 1D04 Midterm examination Page 10 of 11 Question 18 Consider the following two C programs that read MAXN floating point numbers from the user and calculate the average: 1. #include <stdio.h> #define MAXN 1000 void main(void) { int i; float sum=0.0, x; for (i=0; i < MAXN; i++) { scanf("%f", &x); sum = sum + x; } printf("\nThe average is %f", sum/MAXN); } 2. #include <stdio.h> #define MAXN 1000 void main(void) { int i; float sum=0.0, x[MAXN]; for (i=0; i < MAXN; i++) scanf("%f", &x[i]); for (i=0; i < MAXN; i++) sum = sum + x[i]; printf("\nThe average is %f", sum/MAXN); } Which of the following statements about the storage efficiency of the programs is correct? A. Program 1 uses lessless computer memory than Program 2. A. Program 1 uses computer memory than Program 2. B. Program 2 uses less computer memory than Program 1. 1. B. Program 2 uses less computer memory than Program C. Both programs require equal amounts of computer memory. C. Both programs require equal amounts of computer memory. D. It is impossible to say in advance of compiling and running the programs which will consume D. more It is impossible to say in advance of compiling and running the programs which will consume more computer memory. computer memory. Continued on Page 11 Engineering 1D04 Midterm examination Page 11 of 11 Question 19 What value will the variable sum hold when the following C code fragment is completed: sum = 0.0; for (i=1; i <= n; i = i + 1) for (j=1; j <= n; j = j + 1) sum = sum + 1; A. sum n A. sum = = n B. sum = = 1 B. sum 1 C. sum = = n*(n-1)*...(2)*(1) C. sum n*(n-1)*...(2)*(1) D. sum = = n*n D. sum n*n E. sum =2*n E. sum =2*n Question 20 Assume three boolean expressions (b1, b2 and b3) have been defined and consider the following C statement: if ((b1 || b2) && !b3) {statement} Which of the following C-code fragments will result in equivalent behaviour with respect to executing the {statement}? 1. if (b1 || b2) if (!b3) {statement} 2. if (!b3) { if (b1) {statement} else if (b2) {statement} } A. Fragment 1.1. A. Fragment B. Fragment 2.2. B. Fragment C. Both fragments. C. Both fragments. D. Neither fragment. D. Neither fragment. End of Examination ...
View Full Document

This note was uploaded on 02/05/2010 for the course ENGINEERIN 1d04 taught by Professor Smith during the Spring '10 term at McMaster University.

Ask a homework question - tutors are online