Final Exam Name:_______________________________ CIS 67, Spring 95 True/False 1. A stream has a fixed size. 2. Assuming ch is declared as a character variable, cin.get (ch) skips any leading white space when reading into ch. 3. When reading from a data file, the external file name and the internal file name must be the same. 4. External data files saved on a secondary storage device are considered permanent files. 5. Although a program can write its output to a file, no other programs can use this file as input. 6. Once a field width has been set using the setw manipulator or the width function, it remains in effect for the remainder of the program. 7.cin >> ch and cin.get (ch) handle input data in exactly the same manner. Multiple Choice 8. A letter detected during numeric input ____________. a. is ignored b. terminates the reading of the current numeric input value c. causes the program to skip to the next line of code d. causes the program to skip to the next line of data e. causes the program to crash 2. Files usually reside in a computer's ____________. a. arithmetic unit b. control unit c. data display d. secondary storage unit e. printer 10. A(n) ____________ file consists of a stream of character codes. a. binary b. executable c. object d. pointer e. data Refer to the following program segment and data for Questions 11 and 12. data: k k 0j j 1 char a, b; int m, n; for (m = 0; m < 2; m++) { cin >> a >> b >> n; // process the information read ... } 11. Changing the character in the data above to a blank would cause ____________. a. a blank to be read into variable a b. a blank to be read into variable b c. an error message to be generated during execution d. an error message to be generated during compilation e. no change in the processing 12. Removing all blanks from the data above would cause ____________. a. a character to be read into variable a the second time through the loop b. a character to be read into variable b the first time through the loop c. an error message to be generated during execution d. an error message to be generated during compilation e. no change in the processing True/False 13. If A is an array of integer elements, then the statement A = A + 1; adds 1 to each element of A. 14. If A is an array of integer elements, then the statement A[3] = A[3] + 1; adds 1 to the third element in the array storage area. 15. The null character following the last character stored in a string is always stored in the data area allocated to the string. 16. If A and B are arrays of the same data type, then the statement A = B; copies each element of B to the corresponding element of A. 17. If b is an array of integer elements, then the statement b[3] *= 2; doubles the value of b[3]. 18. A component of a structure can be another structure or an ar-ray, as well as a simple data type. For questions 19 and 20, assume that blob is a user- defined struct type and blob_fun has the prototype: void blob_fun (blob, int); 19. If my_blob is type blob, the fol-lowing call to blob_fun passes the struct my_blob as an input argument. blob_fun (my_blob, num); 20. The call to blob_fun (shown in Question 19) causes the address of structure my_blob to be passed to function blob_fun. 21. To reference a component of a structured variable, one uses the variable name followed by a period followed by the component name. Multiple Choice 22. Which of the following types cannot be the subscript type of an array? a. int b. float c. enum d. char e. None of the above. 23. Which of the following types cannot be the base-element type of an array? a. int b. float c. enum d. char e. None of the above. 24. What value is returned by the following function? int result (const a[], int n) { int k = 0; for (int i = 1; i < n; i++) if (a[i] > a[k]) k = i; return k; } // end result a. Index of the largest element in the first n elements in a. b. Value of the largest element in the first n elements of a. c. Index of the smallest element in the first n elements of a. d. Value of the smallest element in the first n elements of a. e. Number of elements in a. 25. What is the effect of the following program segment? for (int i = 0; i < max / 2; i++) { temp = a[i]; a[i] = a[max - i - 1]; a[max - i - 1] = temp; } a. Reverses the numbers stored in the array. b. Puts the largest value in the last array position. c. Counts the number of elements of array a that are greater than its first element. d. Arranges the elements of the array in increasing order. e. None of the above. 26. What does the following function do? int fun (const char a[]) { char blank = ' '; int looking = 1; int k; k = strlen(a) - 1; while (k >= 0 && looking) if (a[k] == blank) --k; else looking = 0; if (looking) return -1; else return k; } a. Finds the subscript of the first nonblank character in ar-ray a. b. Finds the subscript of the last nonblank character in array a. c. Counts the number of nonblank characters in array a. d. Finds the subscript of the first blank in array a. e. Finds the subscript of the last blank in array a. Refer to the following declarations when answering Questions 27 through 33. struct emprec { char name[20]; int id; float salary; }; emprec emp1, emp2; char ch1; int num, flag; 27. Which of the following could not be a valid statement? a. emprec.id = 12345; b. emp1.salary *= 1.05; c. ch1 = emp2.name[0]; d. cout << emp1.salary; e. cin >> emp2.name[3]; 28. What is the data type of the reference emp1.name[0]? a. float b. int c. char d. emprec e. double 29. If emp_change is a void function that has one output argument of type emprec, the prototype would be: a. void emp_change (emp1 emprec&); b. void emp_change (const emprec&); c. void emp_change (emprec); d. void emp_change (emprec&); e. void emp_change (); 30. Which of the following would be a valid call to function emp_change? a. emp_change (emp1.emprec); b. emp_change (const emprec& emp1); c. emp_change (emp2); d. emp_change (emprec& emp2); e. emp1 = emp_change (emp1); 30. How would one assign the value of num to the id component of variable emp2? a. emprec.id = num; b. emp2.num = id; c. emp2.id = num; d. &emp2.id = num; e. emprec.emp1.id = num; 31.Which of the following could not be a valid use of the variables shown? (You may assume that print_emp is a user- defined function.) a. emp2 = emp1; b. flag = (emp1.id == emp2.id); c. print_emp (emp1); d. flag = (emp1 == emp2); e. All of the above are valid. True-False 32. Items declared in the public part of a class may only be ac-cessed within the class itself. 34. Class attributes may appear in the public or private section of a class. 35. Both the class and the struct define a data type that is a col-lection of related data elements which may be of different types. 36. The constructor for class counter is automatically executed each time an object of type counter is declared. 37. All member functions of a class must be public. 38. If Y is a private attribute object X, you can use X.Y to access attribute Y outside the class. 39. There are at most 5 operations that can be performed on the ob-ject of a class. Multiple Choice 40. The variables declared in a class are its ____________. a. functions b. procedures c. attributes d. methods e. definitions 41. The declaration of the object abc of the counter class would appear as: a. counter abc; b. counter.abc; c. abc counter; d. abc = counter; e. counter = abc; 42. Which of the following is the header for function print_it as it would appear in the file counter.cpp. Assume the prototype for the function is void print_it (int); a. void print_it (int what) b. void function print_it (int what) c. void counter::print_it (int what) d. counter::void print_it (int what) e. void public print_it (int what) 43. Assuming function read_day () is a public function of class day and today is an object of this class, how would the function be accessed from outside the class? a. today::read_day (); b. today.read_day (); c. today = read_day; d. read_day (today); e. read_day.today; 44. The class constructor for class grades can be named _________. a. initialize b. counter c. grades d. grades::initialize e. any valid function name 45. The declaration for an array of 50 objects of class u_s_states would appear as: a. u_s_states[50]; b. u_s_states state_arr[50]; c. state_arr u_s_states[50]; d. state_arr[50]; e. Cannot declare an array of objects. True-False 46. The "index expression out of bounds" error message is automati-cally generated by the C++ runtime system whenever an index-out-of-range error occurs. 47. Initialization of class attributes is possible inside a con-structor and other class member functions.