CMPT 111 Mock Final 2010-2011 Term 1 This practice exam was prepared for you by your SSS coach (not your professor!). It is designed to help you test yourself on the topics covered in class and should not be considered as a preview of the actual midterm. CMPT 111 Mock Final 2010-2011 University Learning Centre Section 1: Multiple Choice Circle the correct answer to the following questions. (only on topics after midterm) 1. How many numerals are used in the binary system? a. 1 b. 2 c. 3 2. What is the common name for 8 binary numbers in a computer? a. Bit b. Chomp c. Byte d. Word 3. Which of the following definitions best describes a structure? a. Contains values of the same type b. Contains values of different types 4. How are records passed to functions? a. Pass-by-value b. Pass-by-reference 5. Is it possible to have structures within a structure in C++? a. Yes, it is possible b. No, it is not possible 6. Which is NOT a type of search task? a. Membership task b. Look-up task c. Response task d. Identification task 7. Which search algorithm should be used on an unsorted array of integers? a. Linear search b. Binary search 8. Is binary search always faster than linear search? a. Yes, it is always faster b. No, sometimes it is slower 9. Which is NOT a type of sorting algorithm? a. Bubble Sort b. Selection Sort c. Insertion Sort d. Quicksort e. Mergesort f. Radix Sort g. None of the above 10. Is computer science fun? a. Yes b. No c. All of the above 2 CMPT 111 Mock Final 2010-2011 University Learning Centre Section 2: Short Answer Answer the following short answer questions on another sheet of paper. 1. Using the following conditional: (b < (a-c)) AND (NOT(c > b)) Determine values for a, b, c that make it true, and values that make it false. 2. What is the difference between while loops, for loops, and do-while loops? Give examples of each. 3. Why do array indices start at the number 0 instead of 1? Consider how you use loops to access the array elements. 4. What is the difference between pass-by-value and pass-by-reference? Give examples of both. 5. Why do we use functions in computer science? What are the advantages of using recursion in our functions? 6. Give two real life examples of structures. What types of data are needed in these structures? 7. Why would you want to use a linear search instead of a binary search? Why would you want to use a binary search instead of a linear search? 8. Using the following array of integers: { 14, 7, 6, 9, 88 } Write out what the array looks like after each step of a bubble sort. 9. Using the following array of characters: { ‘d’, ‘t’, ‘f’, ‘s’, ‘h’ } Write out what the array looks like after each step of a selection sort. 10. Convert the following signed binary numbers to decimals: 0b00101101 0b11100011 0b01010101 0b10101010 3 CMPT 111 Mock Final 2010-2011 University Learning Centre Section 3: Algorithm Creation 4 Create algorithms on another sheet of paper to accomplish the following things. 1. Using the table below, write a program that first asks the user to select a country (using numbered options) and then enter their age. After this, it should tell them whether or not they can legally drink, drive, or vote. Country Canada United States Mexico Drinking Age 19 * 21 18 Driving Age 16 16 15 Voting Age 18 18 18 * If the user selects Canada then ask them for their province, and if it is Alberta, Manitoba, or Quebec then the drinking age is only 18. 2. Write a function named outputRomanNumeral which takes one integer parameter. This function should output the equivalent roman numeral for that number to the screen. I is I, V is 5, X is 10, L is 50, C is 100, D is 500, and M is 1000. Don't worry about ones like IV where the smaller symbol comes beforehand, just use IIII for instance. Write two versions of this function, one that uses iteration, and one that uses recursion. 3. Create a record which represents a football (or curling, it doesn’t really matter) game. It should have the names of the two teams that played each other and integers representing the score of each team. For simplicity, the team names are just letters, like team ‘A’ and team ‘R’. (For instance, one record would state that team ‘A’ scored 21 and beat team ‘R’ with 18 points) Next, create a function which takes an array of games as a parameter and ranks the teams based on the number of games they won. A tie counts as a win for both teams. The function should output the teams in order of wins to the screen. You may wish to create another type of record to accomplish this. Use bubble sort to rank the teams. 4. Write a selectionSort function for an array of integers using recursion. It should have a parameter for the array of integers and at least one more parameter as necessary. Now that the array is sorted, you can use binary search to quickly determine whether or not an integer is in the array. Write a binarySearch function for an array of integers. It should have a parameter for the array of integers and return either true or false.