Docsity

Test 1 with Answers | Structured Problem Solving Using the Computer | ITK 168.00, Exams of Information Technology

Partial preview of the text

Download Test 1 with Answers | Structured Problem Solving Using the Computer | ITK 168.00 and more Exams Information Technology in PDF only on Docsity!

ACS 168

Fall 2001

Test 1

Please circle your lecture section:

Sect. 1 Califf MWF 9: Sect. 4 White MWF 10: Sect. 7 Rendon TR 11: Sect. 10 Fulton MWF 1: Sect. 13 Goodwin MWF 2: Sect. 16 Rendon TR 5: Name _________________________________________ Section _________ Part 1: __________ (60) Part 2: __________ (40) Score: __________

Part 1 - Multiple Choice – 60 points ( 2 points each).

For each of the questions in this section mark the one best answer on your answer sheet.

  1. Assume that the current environment shows Jessica facing east anywhere on the island and that there are no nets between her and the beach. Which one of the following pieces of code makes Jessica go to the east beach? a) while (! water_ahead) { stop; } b) while (!water_ahead) { hop; } c) while (water_ahead) { hop; } d) if (water_ahead) { stop; } e) None of the above
  2. Each of the operators in the following statement is numbered on the line below. In what order would the operations be executed? Answer = 4 * 3 + 7 % 2 * 3 – 6 / 3 1 2 3 4 5 6 7 a) 2, 4, 5, 7, 3, 6, 1 b) 2, 5, 7, 4, 3, 6, 1 c) 1, 2, 5, 7, 3, 4, 6 d) 2, 3, 4, 5, 6, 7, 1 e) None of the above
  1. What is the output from the following program? #include int petCount(int cat, int dog); int main() { using namespace std; int cat, dog, total; dog = 6; cat = 5; cout << cat << “ ”; total = petCount(cat, dog); cout << cat << “ ” << total << endl; return 0; } int petCount(int cat, int dog) { using namespace std; int kittens = 3; int sum; cat = cat + kittens; cout << cat << “ ”; sum = cat + dog; return (sum); } a) 5 5 5 11 b) 5 8 5 14 c) 5 8 5 11 d) 5 8 8 14 e) None of the above
  2. In the program above, total is a) A local variable in main b) A local variable in petCount c) A global variable d) A global constant e) None of the above
  1. Which of the following are legal variable names in C++? I) num_items II) double III) y2k IV) 3_item V) last-one a) I and III only b) I and V only c) I, III and V only d) I, II, and III only e) I, III, IV only
  2. What is the output of running the following snippet of C++ code? Assume number is a variable that was declared as an integer. number = (1/2) * 2; cout << “(1/2) * 2 = ” << number; a) << “(1/2) * 2 = ” << 0 b) 0 = (1/2) * 2 c) (1/2) * 2 = 0 d) (1/2) * 2 = 1 e) None of the above
  3. In the state of Illinois, a person must be at least 16 years old to obtain a drivers license. If a person is under the legal drinking age of 21, the license is a different color. Which one of the following conditions checks to see if a person is old enough to be issued a driver’s license but is not old enough to drink? a) ((Age >= 16) || (Age < 21)) b) (Age ( >= 16 && < 21)) c) ((Age >=16) && (Age<21)) d) (16<=Age<21) e) None of the above

Questions 13 and 14 Consider the following algorithm snippet and answer the questions below. IF x < y THEN print x,y ELSE IF y < x print y,x ELSE print x END IF END IF

  1. Which is true if only x is printed? a) x = 0 b) x > y c) x = y d) y = 0 e) None of the above
  2. If x<y is true, how many times will line 2 (Print x,y) be executed? a) 0 b) 1 c) 2 d) infinite e) unknown
  1. The compiler ignores the indentation in a C++ program. We have removed proper indentation from the following piece of C++ code. if (x < 10) { if (y > 10) { cout << “first line ”; } } else { cout << “second line ”; cout << “third line ”; } Determine the output of the above code segment when x is 9 and y is 11. (Hint: apply the indentation conventions you have learned) a) first line second line third line b) first line third line c) first line d) second line third line e) None of the above
  2. What is the result of executing the following segment of C++ code? cout << “Hello \nworld. “; cout << “How are you?\n”; a) Hello world. How are you? b) Hello \nworld. How are you?\n c) Hello world. How are you? d) Hello world. How are you? e) None of the above
  1. What is the output of the following program? #include int flowers(int tulip, int rose); int main() { using namespace std; int rose, tulip; rose = 3; tulip = 8; cout << tulip << “ ”; tulip = flowers(rose, tulip); cout << tulip << endl; return 0; } int flowers(int tulip, int rose) { using namespace std; cout << tulip << “ ”; tulip = tulip * 2 + rose; return tulip; } a) 8 8 18 b) 8 3 14 c) 8 8 14 d) 8 3 18 e) None of the above

Questions 21- Consider the following piece of C++ code. Assume that Num is an integer variable with an initial value of 10 while ( Num > 0) { cout << Num << “ ”; Num = Num – 3; }

  1. How many times does the body of the loop execute? a) 10 b) 5 c) 4 d) 0 e) None of the above
  2. What is the value of Num AFTER executing the above piece of code? a) - b) - c) 7 d) 1 e) None of the above
  3. What is the output of the above piece of code? a) 7 4 1 b) 7 4 1 - c) 10 7 4 1 - d) 10 7 4 1 e) None of the above

Questions 26 and 27 Consider the following code segment. Assume that it is embedded in a complete correct program. int x = 1; while (x <= 10) { if (x == 5) x = 7; else cout << x << “ “; x++; }

  1. What is the output of the code segment? a) 1 2 3 4 5 6 7 8 9 10 b) 1 2 3 4 7 8 9 10 c) 1 2 3 4 8 9 10 d) 1 2 3 4 5 8 9 10 e) None of the above
  2. What is the value of x at the end? a) 5 b) 7 c) 10 d) 11 e) None of the above
  1. Function prototype, function header, and function calls should all agree in: a) The number of arguments b) The data type of the arguments c) The ordering of the arguments and parameters d) The data type of the return value e) All of the above
  2. A program is to compute the area of a rectangle. When given values of 4 and 10 for the height and width of the rectangle, it prints out the area as 20. Which of the following types of error does this exemplify? a) Syntax error b) Logic error c) Run-time error d) Object error e) None of the above

Name: ________________________________________ Section: ____ Score:________

Part 2 - 40 points

  1. Design a solution to the following problem : You are to ask for and read numbers from the keyboard and count the number of positive and negative numbers (0 is neither positive nor negative). First, ask how many numbers will be entered. That value should not be included in either count. Print the counts out for the user. Give the IPO chart for this problem (4 points): Input Processing Output Give the pseudocode algorithm with action diagram—no modules are required ( points)
  1. Write a C++ function, ExtractHundreds , to extract the 100s digit from an integer. Thus, the function should return the integer value 2 if 3246 is passed to the function. If the argument passed to the function is less than 100, the function should return 0. Give the function prototype, a statement that correctly calls the function, and the complete function definition. (6 points). Prototype: Calling statement: Complete function definition:
  1. Jessica is in the NW corner of her island, facing south. An enclosure has been built around the NE corner of the island. The enclosure has a straight wall on the south side. We do not know what shape the wall is on the enclosure’s west side. Inside the enclosure, there are several flowers along the east beach. There are no nets except those that form the walls of the enclosure. There is also a flower somewhere on the south beach. Jessica is to use the flower from the south beach to make an opening in the south wall of the enclosure, then pick all the flowers along the east beach, go out through the opening she made, return to the NW corner of the island, and face east. See the sample environment below for one possible layout of the island. ....... #....... ......... #..... * ........ #...... * ......... #...... ......... #..... * ......... #..... * ......... # # # # # # # ................ ................ ................ ................ ................ ................ ................ ................ ... *............ Draw a structure chart for this problem using a minimum of three submodules in addition to the main module. One of the three submodules should be called PICK_FLOWERS_EAST_BEACH. (5 points)