25.07.2013 Views

CMPT 111 Mock Final - Homepage Usask

CMPT 111 Mock Final - Homepage Usask

CMPT 111 Mock Final - Homepage Usask

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>CMPT</strong> <strong>111</strong><br />

<strong>Mock</strong> <strong>Final</strong><br />

2010-2011 Term 1<br />

This practice exam was<br />

prepared for you by your SSS<br />

coach (not your professor!).<br />

It is designed to help you test<br />

yourself on the topics covered<br />

in class and should not be<br />

considered as a preview of the<br />

actual midterm.


<strong>CMPT</strong> <strong>111</strong> <strong>Mock</strong> <strong>Final</strong> 2010-2011 University Learning Centre<br />

Section 1: Multiple Choice<br />

Circle the correct answer to the following questions. (only on topics after midterm)<br />

1. How many numerals are used in the binary system?<br />

a. 1<br />

b. 2<br />

c. 3<br />

2. What is the common name for 8 binary numbers in a computer?<br />

a. Bit<br />

b. Chomp<br />

c. Byte<br />

d. Word<br />

3. Which of the following definitions best describes a structure?<br />

a. Contains values of the same type<br />

b. Contains values of different types<br />

4. How are records passed to functions?<br />

a. Pass-by-value<br />

b. Pass-by-reference<br />

5. Is it possible to have structures within a structure in C++?<br />

a. Yes, it is possible<br />

b. No, it is not possible<br />

6. Which is NOT a type of search task?<br />

a. Membership task<br />

b. Look-up task<br />

c. Response task<br />

d. Identification task<br />

7. Which search algorithm should be used on an unsorted array of integers?<br />

a. Linear search<br />

b. Binary search<br />

8. Is binary search always faster than linear search?<br />

a. Yes, it is always faster<br />

b. No, sometimes it is slower<br />

9. Which is NOT a type of sorting algorithm?<br />

a. Bubble Sort<br />

b. Selection Sort<br />

c. Insertion Sort<br />

d. Quicksort<br />

e. Mergesort<br />

f. Radix Sort<br />

g. None of the above<br />

10. Is computer science fun?<br />

a. Yes<br />

b. No<br />

c. All of the above<br />

2


<strong>CMPT</strong> <strong>111</strong> <strong>Mock</strong> <strong>Final</strong> 2010-2011 University Learning Centre<br />

Section 2: Short Answer<br />

Answer the following short answer questions on another sheet of paper.<br />

1. Using the following conditional: (b < (a-c)) AND (NOT(c > b))<br />

Determine values for a, b, c that make it true, and values that make it false.<br />

2. What is the difference between while loops, for loops, and do-while loops?<br />

Give examples of each.<br />

3. Why do array indices start at the number 0 instead of 1?<br />

Consider how you use loops to access the array elements.<br />

4. What is the difference between pass-by-value and pass-by-reference?<br />

Give examples of both.<br />

5. Why do we use functions in computer science?<br />

What are the advantages of using recursion in our functions?<br />

6. Give two real life examples of structures.<br />

What types of data are needed in these structures?<br />

7. Why would you want to use a linear search instead of a binary search?<br />

Why would you want to use a binary search instead of a linear search?<br />

8. Using the following array of integers: { 14, 7, 6, 9, 88 }<br />

Write out what the array looks like after each step of a bubble sort.<br />

9. Using the following array of characters: { ‘d’, ‘t’, ‘f’, ‘s’, ‘h’ }<br />

Write out what the array looks like after each step of a selection sort.<br />

10. Convert the following signed binary numbers to decimals:<br />

0b00101101<br />

0b<strong>111</strong>00011<br />

0b01010101<br />

0b10101010<br />

3


<strong>CMPT</strong> <strong>111</strong> <strong>Mock</strong> <strong>Final</strong> 2010-2011 University Learning Centre<br />

Section 3: Algorithm Creation<br />

Create algorithms on another sheet of paper to accomplish the following things.<br />

1. Using the table below, write a program that first asks the user to select a country (using<br />

numbered options) and then enter their age. After this, it should tell them whether or not they<br />

can legally drink, drive, or vote.<br />

Country Drinking Age Driving Age Voting Age<br />

Canada 19 * 16 18<br />

United States 21 16 18<br />

Mexico 18 15 18<br />

* If the user selects Canada then ask them for their province, and if it is Alberta, Manitoba, or<br />

Quebec then the drinking age is only 18.<br />

2. Write a function named outputRomanNumeral which takes one integer parameter. This<br />

function should output the equivalent roman numeral for that number to the screen.<br />

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<br />

where the smaller symbol comes beforehand, just use IIII for instance.<br />

Write two versions of this function, one that uses iteration, and one that uses recursion.<br />

3. Create a record which represents a football (or curling, it doesn’t really matter) game. It should<br />

have the names of the two teams that played each other and integers representing the score of<br />

each team. For simplicity, the team names are just letters, like team ‘A’ and team ‘R’.<br />

(For instance, one record would state that team ‘A’ scored 21 and beat team ‘R’ with 18 points)<br />

Next, create a function which takes an array of games as a parameter and ranks the teams based<br />

on the number of games they won. A tie counts as a win for both teams. The function should<br />

output the teams in order of wins to the screen. You may wish to create another type of record<br />

to accomplish this. Use bubble sort to rank the teams.<br />

4. Write a selectionSort function for an array of integers using recursion.<br />

It should have a parameter for the array of integers and at least one more parameter as<br />

necessary.<br />

Now that the array is sorted, you can use binary search to quickly determine whether or not an<br />

integer is in the array.<br />

Write a binarySearch function for an array of integers.<br />

It should have a parameter for the array of integers and return either true or false.<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!