Midterm 4 September 2015, questions and answers PDF

Title Midterm 4 September 2015, questions and answers
Course Introduction to Computing
Institution University of Alberta
Pages 8
File Size 270 KB
File Type PDF
Total Downloads 98
Total Views 148

Summary

Download Midterm 4 September 2015, questions and answers PDF


Description

Name:

CMPUT 101 A1: Midterm 1 Instructor: Marianne Morris Percentage: 15% Date: Oct 4, 2018

ID:

SOLUTIONS

Question 1 / 15 Question 2 / 10 Question 3 /8 Question 4 /7 Total / 40

1

Question 1:

(15 marks)

Part I: Circle only one answer among the multiple choices:

(6 marks)

1.

Computing Science studies, develops, and analyzes: a) Software b) Hardware c) Algorithms d) All the above

2.

The ASCII encoding scheme has a total of ______ codes a) 24 b) 28 c) 216 d) None of the above

3.

Inside the computer memory, audio clips are represented in a) Binary format b) Decimal format c) Hexadecimal format d) Analog format

4.

The largest unsigned integer number that can be stored in a 4-bit machine is a) 4 b) 7 c) 15 d) 16

5.

The Unicode encoding scheme represents: a) English characters only b) Punctuation and Emoji characters only c) European languages only d) All the above in addition to other languages

6.

Each Unicode characters occupies _____ bits in the computer memory: a) 4 b) 8 c) 16 d) 32

2

Part II: Binary arithmetic:

(9 marks)

Complete the following binary multiplication.

(5 marks)

1 1 0 1 1 x 1 0 1 ____________ 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 1 1

Convert the following binary number to decimal format:

(2 marks)

(110011)2 = 25 + 24 + 21 + 20 = 32 + 16 + 3 = 51

Convert the following decimal number to binary:

(2 marks)

(28)10 = 11100 28 | 2 => 0 14 0 7 1 3 1 1 1 0

3

Question 2:

(10 marks)

Trace through the following BeeperBot program and answer the questions below. define main { pick_all_beepers restore_pile move_beepers_to_bag2 move pick_all_beepers restore_pile move compute show_result } define pick_all_beepers { while (next_to_a_beeper) { pick_beeper } } define restore_pile { while (has_beeper(0)){ move_beeper(0,1) create_beeper } } define move_beepers_to_bag2 { while (has_beeper(1)) { move_beeper(1,2) } } define compute { while (has_beeper(1)) { move_beeper(1,9) move_beeper(2,9) } } define show_result { while (has_beeper(2)){ move_beeper(2,0) } while (has_beeper(0)) { put_beeper } }

4

What’s the output given the following worlds? Here, show the number of beepers on the floor and their coordinates, and the direction and coordinates of the bot on the final world. Initial world

Final world

robot 1 3 S beepers 1 3 1 beepers 1 2 1

1 beeper in 1,2 1 beeper in 1,3 0 beeper in 1,1

robot 1 3 S beepers 1 3 2 beepers 1 2 1

2 beepers in 1,3 1 beeper in 1,2 1 beeper in 1,1

robot 1 3 S beepers 1 3 5 beepers 1 2 3

5 beepers in 1,3 3 beepers in 1,2 2 beepers in 1,1

In the above program, what arithmetic operation is BB performing? Subtraction

What would happen if the pile of beepers in coordinates (1,2) had more beepers than the pile in coordinates (1,3)? The program doesn’t handle operations with a negative result. There will be a runtime error as the program attempts to move beepers from bag 2 to bag 9 but there wouldn’t be any beepers in bag 2 in the case the bottom pile is bigger than the top pile of beepers on the grid.

5

Question 3:

(10 marks)

Complete the following program by filling in the blanks. Here, BeeperBot is trying to recognize one of four possible shapes in a room defined by walls. The shapes are a triangle, a square, a right trapezoid, or a rectangle. A triangle is always made up of 3 beepers; a square of 4 beepers; a trapezoid of 5 beepers; and a rectangle of 6 beepers (as in the pictures below). The room will have one shape at a time, will never be empty, and the shape can be anywhere in the room. Triangle

Square

Right trapezoid

Rectangle

The initial position and direction of the robot as well as the walls are defined as follow: robot 1 1 E wall 1 2 N wall 2 2 N wall 3 2 N wall 3 1 E wall 3 2 E

In this program, the bot walks around the room, visiting each of the six tiles in the room. It finds out what shape is in the room by checking if a tile has a beeper. It counts the number of tiles that have a beeper. Then, it represents each shape with a decimal number from 1 to 4. This decimal number will be stored in bag 2. If the shape is a triangle, there will be 1 beeper in bag 2. For a square, there will be 2 beepers in bag 2. For a trapezoid, there will be 3 beepers in bag 2; and for a rectangle, 4 beepers in bag 2.

6

define main { read_row turn_left count_current_tile move turn_left read_row count_current_tile place_result_in_bag2 } define read_row { while (front_is_clear) { count_current_tile move } } define count_current_tile { if (next_to_a_beeper) { create_beeper pick_beeper } } define place_result_in_bag2 { move_beeper(0,9) move_beeper(0,9) while (has_beeper(0)) { move_beeper(0,2) } }

7

Question 4:

(7 marks)

Fill in the blanks so that BeeperBot looks for the pattern “110”. If the pattern is there, the bot will go to tile (1,1) but if not, it will go to (1,2). The world settings are the following: robot 2 2 E beepers 2 2 1 beepers 3 2 1 define main { if (next_to_a_beeper){ move if (next_to_a_beeper){ move if (not_next_to_a_beeper){ go_home turn_off } } } move_west } define go_home { move_south move_west } define move_south { while (not_facing_south) { turn_left } while(front_is_clear) { move } } define move_west { while (not_facing_west) { turn_left } while(front_is_clear) { move } }

8...


Similar Free PDFs