Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

0806C220 Introduction to Programming – Midterm Exam

May 2022

True/False Questions [3 points each]:

1.       _____       A control unit is not a part of a CPU.

2.       _____       A microprocessor and a central processing unit are two different components in a computer.

3.       _____       Assembly language is a low-level programming language.

4.       _____       A compiler is a program that translates a source code from a high-level programming language to a low-level programming language

5.       _____       A diamond-shaped block in a flow chart represents a terminal (start or end of algorithm).

6.       _____       A magic number is a variable that changes its value throughout the program.

7.       _____       ALL-TYPE_1 is an invalid identifier for a variable.

8.        _____       When a > b and c < 0 is False, the expression a <= b or c >= 0 must be False.

9.       _____       In Python, the multiplication operator ‘*’ has the same order of precedence as the remainder %’.

10.     _____       A pseudocode can be directly run by a CPU.

 

Multiple Choice Questions [4 points each]: choose the most appropriate answer for each question. If the question contains an expression, it is assumed to be in Python.

11. _____          Which of the following identifiers is not valid?

A. _isyear  B.  is-2-year C.  IsYear_  D.  is_year

12. _____          What is the decimal value of the binary number 100112?

A.   18      B.  19      C.   20      D.  21

13. _____          What will be the value in the variable greater after executing the following code?

word1 = ‘pencil’

word2 = ‘pencils’

greater = word1 > word2

A.  0                          B.  True

C.  1                          D.  False

14. _____          What will be the value in x after the following statement is executed?

x = 2 * 3 ** 2 % 10

A.   6       B.  8       C.   18      D.  2


A.  a > 10 or a / b == 1       B.  a >= 10 or b == 0

C.  a < 10 and a**b > 1        D.  1 < b < 10


Programming questions:

16.  [20 points] Write a program to convert between pound (P) and kilogram (K) weights. The conversion formula is pounds = 2.2*kg.

Requirements:

-     The program must first ask the user to choose the source units pounds (enter P) or kilograms (enter K)

-      If the source unit is not P or K, the program will display a message  ‘Incorrect weight type!’ and terminate.

-      If the input unit is valid, the program will prompt the user to enter the weight value

-      The program will output the converted weight with only one decimal place.

Your program needs to match the following test cases; make sure your program produces the   prompts/messages to the user in the same format as shown below (only displaying result value without matching the messages and formatting as below will result in reduced points) :

Test Case 1:

Please enter K for kilograms or P for pounds: K

Please enter the weight: 73.5

The converted weight is: 161.7 pounds.

Test Case 2:

Please enter K for kilograms or P for pounds: P

Please enter the weight: 147.8

The converted weight is: 67.2 kilograms.

Test Case 3:

Please enter K for kilograms or P for pounds: A

Incorrect weight type!

17.  [10 points] Draw a flow chart for the above program.

18.  [20 points] Write a program that will sequentially prompt the user to enter 3 integer numbers (use separate program statements to read each value, do not use for/while loops). The program will:

1)   find the minimum and maximum values;

2)    calculate the average of all entered values;

3)   display the minimum and maximum value and the average (a floating point with two decimal places).

Your program needs to match the following test cases (including the prompts displayed to the user and the formatting) :

Test Case 1:

Please enter the 1st number: 1

Please enter the 2nd number: 2

Please enter the 3rd number: 3

The minimum value is 1

The maximum value is 3

The average of all inputs is 2.00

Test Case 2:

Please enter the 1st number: 2

Please enter the 2nd number: 4

Please enter the 3rd number: 1

The minimum value is 1

The maximum value is 4

The average of all inputs is 2.33