Final Exam-2021 حلول
Final Exam-2021 حلول
Cairo University
Final Exam
Department: General
Course Name: Fundamentals of Computer Sciences Date: 26 January 2022
Course Code: CS111 Duration: 2 hours
Examiner(s): Dr. Mohammad El-Ramly Total Marks: 60
1- Read instructions and questions carefully. .اقرأ األسئهخ و انتعهيًبد ثعُبيخ فبئقخ و تأكذ يٍ فهى انًطهىة ثذقخ
2- Calculator is permissible. Mobile is NOT allowed. .يسًخ ثبستخذاو اآلالد انذبسجخ و ال يسًخ ثبنًذًىل
3- Choose the most correct and the most general answer. .اختر أعى و أصخ إجبثخ
4- Exam has 38 questions with 1.6 marks each. . درجخ1.6 سؤاال وزٌ كم يُهب33 ٍيتكىٌ االيتذبٌ ي
5- 6 correct answers earn 1.6 extra marks and 6 wrong answers cause deducting 1.6 marks.
. درجخ1.6 اجبثبد خبطئخ تؤدي نخصى6 درجخ و كم1.6 اجبثبد صذيذخ تذصم عهً ثىَص6 كم
-1-
6- Storage. Assume this sequence of pits and lands on the surface of a CD, what is the
corresponding bit pattern?
(a) Replace steps 2, 3 and 4 with (b) Replace steps 3 and 4 with
for item in data: if data[i] == x
if item == x: return i
return data.index(i) elif: data[i] != x
return -1
(c) Replace steps 3 and 4 with (d) Replace steps 3 and 4 with
if (data [i] == x) if data[i] == x
return i return i
else: elif: data[i] > x
return -1 return -1
10- Data Compression. Which type of data cannot be compressed with lossy compression
methods?
(a) images (b) text (c) audio (d) video (e) Lossy compression works on all data
-2-
11- Image Representation. If we represent a bitmap image in RGB format, using Luminance and
Chrominance components, and we isolate the Luminance component alone, then we get …
(a) A true color image (b) A gray version of the image (c) A vector version of the image
(d) A red-colored version of the image (e) A black and white image
12- Image Representation. Assume that we have two 1024 x 1024 images: Img1.bmp includes
250 colors and Img2.bmp is a gray level image with 256 gray color levels. Both images are in
bitmap format. How do the sizes of both images compare?
(a) Size of Img1.bmp > Size of Img2.bmp (b) Size of Img1.bmp < Size of Img2.bmp
(c) Size of Img1.bmp == Size of Img2.bmp (d) There is not enough information to decide
13- Unicode. Unicode Consortium defines until now 144,697 characters covering 159 modern
and historic languages (including Egyptian Hieroglyphs) as well as symbols and emojis. UTF-8
is the dominant Unicode format, used by 98% of all web pages. If letter has Unicode
130A1, how will it be represented in UTF-8?
(a) F09382A1 (b) 730101 (c) 0103000A01 (d) 130A1 (e) F103A1
14- Audio Representation. What is not true about MP3 audio compression format?
(a) It is a lossy compression technique
(b) It takes advantage of temporal masking, when sounds immediately after loud sounds are
not recognized by the human ear.
(c) It takes advantage of frequency masking, when softer sounds are not recognized by the
human ear.
(d) It takes about 1 MB to store 1 minute of audio.
(e) Compared to wav uncompressed format, MP3 : wav gives 1:2 compression ratio
Main
15- Flowcharts and Algorithms. What does this flowchart do?
Functions: Len calculates the length of a string. String
input
ToInteger converts a character to its integer value and Input input
function Char extracts a character from string. Increment of
Integer i, output
For loop is 1.
(a) It does not do a useful operation output = 0
(a) (b)
(c) (d)
-4-
21- Recursion and Python functions. Given these two functions, what is not true about them?
(a) Both functions will compile correctly and have no syntax errors.
(b) Both functions calculate the same thing.
(c) Both function have the same complexity (take the same number of steps)
(d) Both functions are recursive.
(e) Both functions terminate (do not run for ever) if called with integers >= 0
22- Python Files. Assume having a file with the name data.txt that contains the Ali 5
shown data. Which of these codes will not fill the dictionary with the data as Sami 10
follows: {'Ali': '5', 'Sami': '10', 'Samir': '12'} Amir 12
dictionary = {} #(a)
file = open("data.txt")
i = 0
words = file.read().split() #divide to
while i < len(words): #words
dictionary[words[i]] = words[i+1]
i += 2
print (dictionary)
dictionary = {} #(b)
file = open("data.txt")
dictionary = {line.split()[0] : line.split()[1] for line in file}
print (dictionary)
dictionary = {} #(c) dictionary = {} #(d)
file = open("data.txt") file = open("data.txt")
for line in file: for line in file:
key, value = line.split() key, value = line.split()
dictionary[key] = value dictionary[key] = value
print (dictionary) print (dictionary)
23- Python functions. What will this code print? def power (m = 1, n = 0):
(a) 0 81 2 2 return m ** n
(b) 1 81 1 1
print (power(), end = ' ')
(c) 1 512 0 2 print (power(n = 2, m = 9), end = ' ')
(d) 1 81 2 0 print (power(m = 2), end = ' ')
(e) Will give a compilation error print (power(n = 2), end = ' ')
-5-
24- Python functions. Python supports dynamic typing. Based on the def double (n):
parameter passed, it will decide if function call will work or not. return n * 2
Which of the following function calls will NOT work and give a runtime error?
(a) print (double({1:2, 3:4})) (b) print (double("CS111"))
(c) print (double([1,2])) (d) print (double(1.4))
(e) print (double(12))
25- Python Loops. Which of these loops are equivalent?
1. for i in [:4]:
2. for i in range (1,5):
3. for i in [1,2,3,4]:
4. for i in list(range(1,4)):
(a) First and Second (b) Third and fourth (c) First and third
(d) Second and third (e) Second and fourth
26- Python PEP8. Which of the following codes follow PEP8 coding style correctly?
29- Python Tuples. Given this code that defines 2 points as tuples, which of these statements
will correctly calculate a vector from point 1 to point 2? pnt1 = (1, 2)
(a) vec = pnt2 – pnt1 (b) vec = (pnt2 – pnt1) pnt2 = (3, 4)
(c) vec = [pnt2 – pnt1] (d) vec = (pnt2, -pnt1) vec = ......
(e) vec = (pnt2[0] – pn1[0], pnt2[1] – pnt1[1])
-6-
30- Logic Circuits. What is the function of this logic circuit?
(a) 2-bits full adder
(b) 2-bits equality comparator (compares if A1Ao== B1Bo or !=)
(c) 2-bits half adder (d) 4-bits adder (e) 2-bits multiplier
31- Logic Circuits. Which logic gate is needed to complete thismultiplier
circuit so it implements this truth table? ========> A B X
(a) XOR (b) OR (c) AND (d) NOT (e) NAND 0 0 1
0 1 0
32- Computer Architecture. What is not true about von 1 0 1
Noueman computer model? 1 1 1
(a) Programs are represented as bit patterns
(b) Program instructions are fetched from memory, encoded and then executed
(c) It supports a small set of instructions following RISC processor design.
(d) It is also called "Stored Program Architecture" Address Code|
(e) It is the basis for most modern computers. 00 1120
33- Machine Language. What does this program do? 02 1222
04 2000
(a) It adds contents of 2 memory locations and stores result in a third location.
06 2400
(b) It calculates the sum from one to a given number stored in location 20, and
08 2501
stores the result (1+2+3+ ….) in location 24.
(c) It sums 1 + 1 + 1 + …. 22 times and stores the result in a memory location 24. 0A B214
(d) It compares two numbers taken from memory and stores the maximum in a 0C 5441
third memory location. 0E 5050
(e) It multiplies the content of two memory locations and stores the results in a 10 3424
third memory location. 12 B00A
14 C000
34- Machine Language. Which of these statements will complete this program to
check if number stored in cell A0 is divisible by 4 and print 'D' or 'N' (Divisible or
Not) where ASCII of N = 4Eh and D = 44h.
#A Only this #B Only this #C Only this #D Only this Address Code|
10 11A0
18 B324 18 B320 18 B320 18 B320
12 2203
1A 244E 1A 144E 1A 2444 1A 244E
1C 3400 1C 3400 1C 3400 1C 3400 14 2000
1E C000 1E C000 1E C000 1E C000 16 8312
20 2444 20 1444 20 244E 20 2444 18 ....
22 3400 22 3400 22 3400 22 3400 1A ....
24 C000 24 C000 24 C000 24 C000
35- Machine Language. Which of these programs does not have an infinite loop
(infinite loop means that the program will never stop)?
#A Only this #B Only this #C Only this #D Only this #E All four
10 2002 10 2002 10 2002 10 2002 programs have
12 2104 12 2102 12 2104 12 2104 infinite loops
14 B11C 14 A101 14 A103 14 A100
16 A101 16 B11C 16 B11C 16 B11C
18 A101 18 A101 18 A100 18 A108
1A B014 1A B016 1A B016 1A B016
1C C000 1C C000 1C C000 1C C000
-7-
36- Machine Language. Given the machine language instruction set at the end of this paper,
and assuming that Op-Code takes only 4 bits and this will not increase. If we want to extend
the hardware to support more instructions, how many more new instructions can we add?
(a) 2 (b) 4 (c) 1 (d) 16 (e) 12
37- Computer and Society. An attack that encrypts data on a computer and demands sending
money to the attacker to decrypt is called? .... تسمى، الهجمة التى تشفر البيانات و تطلب ماال لفكها
(a) Ransomware attacks (b) Denial of service attack
(c) Computer virus (d) Social engineering (e) Spyware
38- Computer and Society. Which of the following emails follows Netiquette?
Subject: AFAIK, cm 2mrw early (a) Subject: Ana Raye7 Elgam3a Bukrah (b)
AAWRWB Salam Alikom
HYD? ana raye7 elgam3ah bukrah 3ashan 3andi
AFAIK, u need 2 cm 2morrow early, emta7an, huwa enta raye7?
at 7:00am 2 replace Ali. Salam
B4N
Mohammad
M.
From: [email protected] (c) To: [email protected] (d)
To: [email protected] Subject: Can we meet tomorrow?
Subject: Dear Mohsen,
I did not attend the midterm due to I hope you are better now.
illness. Can you please arrange Can we meet tomorrow 6 pm at FCAI?
another midterm for me? Mina
Machine Language
Op-code Operand Description
1 RXY LOAD the register R with the bit pattern found in the memory cell whose address is XY.
Example: 14A3 would cause the contents of the memory cell located at address A3 to be placed in register 4.
2 RXY LOAD the register R with the bit pattern XY.
Example: 20A3 would cause the value A3 to be placed in register 0.
3 RXY STORE the bit pattern found in register R in the memory cell whose address is XY.
Example: 35B1 would cause the contents of register 5 to be placed in the memory cell whose address is B1.
3 R00 STORE to location 00, which is a memory mapping for the screen. Writing to 00 is writing to screen.
4 0RS MOVE the bit pattern found in register R to register S.
Example: 40A4 would cause the contents of register A to be copied into register 4.
5 RST ADD the bit patterns in registers S and T as though they were two’s complement representations
and leave the result in register R.
Example: 5726 would cause the binary values in registers 2 and 6 to be added and the sum placed in register 7.
6 RST ADD the bit patterns in registers S and T as though they represented values in floating-point
notation and leave the floating-point result in register R.
Example: 634E would cause the values in registers 4 and E to be added as floating-point values
and the result to be placed in register 3.
7 RST OR the bit patterns in registers S and T and place the result in register R.
Example: 7CB4 would cause the result of ORing the contents of registers B and 4 to be placed in register C.
8 RST AND the bit patterns in register S and T and place the result in register R.
Example: 8045 would cause the result of ANDing the contents of registers 4 and 5 to be placed in register 0.
9 RST EXCLUSIVE OR the bit patterns in registers S and T and place the result in register R.
Example: 95F3 would cause the result of EXCLUSIVE ORing the contents of registers F and 3 to
be placed in register 5.
A R0X ROTATE the bit pattern in register R one bit to the right X times. Each time place the bit that
started at the low-order end at the high-order end.
Example: A403 would cause the contents of register 4 to be rotated 3 bits to the right in a circular fashion.
B RXY JUMP to the instruction located in the memory cell at address XY if the bit pattern in register R
is equal to the bit pattern in register number 0. Otherwise, continue with the normal sequence of
execution. (The jump is implemented by copying XY into the program counter during the execute phase.)
Example: B43C would first compare the contents of register 4 with the contents of register 0. If
the two were equal, the pattern 3C would be placed in the program counter so that the next
instruction executed would be the one located at that memory address. Otherwise, nothing would
be done and program execution would continue in its normal sequence.
C 000 HALT execution.
Example: C000 would cause program execution to stop.
-8-
2222 يُبير ًُ انذكتىر دمحم يذًىد فىزي انريهً و انذكتىرح إيًبٌ دس، يع أطيت دعىاتُب ثبنتىفيق و انُجبح