Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computers -3rd exam- 授課教授:李錫智. Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively?

Similar presentations


Presentation on theme: "Introduction to Computers -3rd exam- 授課教授:李錫智. Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively?"— Presentation transcript:

1 Introduction to Computers -3rd exam- 授課教授:李錫智

2 Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively? function Classify(){ num1 = document.getElementById('numberbox1').value; num2 = document.getElementById('numberbox2').value; if (num1 > num2){ document.getElementById('outputDiv').innerHTML="num1 is bigger"; } else if (num1 < num2){ document.getElementById('outputDiv').innerHTML="num2 is bigger"; } else if (num1 == num2){ document.getElementById('outputDiv').innerHTML="equal"; } num1: nmu2:

3 Solution of Q1 Answer : num2 is bigger The value of numberboxs are strings so that the IF condition would compare with each first character. When we type 100 and 20, the condition would compare ‘1’ with ‘2’. In ASCII codes, the value of ‘2’ is bigger than ‘1’, and the result will show “num2 is bigger”.

4 Q2 Please write a program to show a student’s final score. The web page should contain three boxes: mid-exam score box, final-exam score box, and final score box. When the student clicks the button after he/she types the mid-exam score and final-exam score, the web page will show his/her final score in the final score box. If the final score is lower than 60, the web page will alert “This subject may not pass.” (Final score = mid exam score*40% + final exam score*60%)

5 Solution of Q2

6 Q3 A black-and-white bitmap is a way to store an image without colors. In such an image, each pixel has only two values, white and black. Therefore, one bit is enough to represent a pixel, with 1 indicating white and 0 indicating black. Suppose we have a 8×10 black-and-white image represented by a bitmap of 8×10 bits. The content of this bitmap is represented by {8, 62, 28, 42, 93, 4, 8, 62, 8, 24} in decimal from the top row to the bottom row of the image. Please draw the image.

7 Solution of Q3 00001000 00111110 00011100 00101010 01011101 00000100 00001000 00111110 00001000 00011000

8 Q4 The characters of the ASCII codes are less than 2 7.In order to make each code a byte, a bit is added in front for checking certain transmission errors. Please describe what errors are to be detected and how to detect them?

9 Solution of Q4 Answer : The additional bit is that we call “parity bit” or “check bit”. We can detect the one bit may be changed unexpectedly in the transmission. The parity bit for each unit is set so that all bytes have either an odd number or an even number of set bits. In the case of even parity, the number of bits whose value is 1 in a given set are counted. If that total is odd, the parity bit value is set to 1. If the count of ones in a given set of bits is already even, the parity bit's value remains 0. When we receive the byte, the count of ones is odd, we can detect the byte must be wrong.

10 Q5-(a) What is the output produced by each of the following programs? var x = 1; var y = 30; while (x < y) { document.write(x + " " + y + " "); x =2* x + 1; y = y – 2; } document.write("DONE WITH SECOND!");

11 Solution of Q5-a Answer : 1 30 3 28 7 26 15 24 DONE WITH SECOND!

12 Q5-(b) var x = 5; var y = 5; var z = 10; while (x <= y) { document.write(x + " " + y + " "); y = y + 5; while ((x=z) == y) { z = z * 2; y = y + 10; document.write(x + " " + y + " ") } x = x * 4; } document.write("Finish!");

13 Solution of Q5-b Answer : 5 10 20 20 30 Finish!

14 Q6 Please answer the following questions: (a)Convert the following double-precision bit sequence to a real value: 0100000000011110100000000000000000000000000000 000000000000000000 (b)Convert the following real value to a double-precision bit sequence: -16.5 = ?

15 Solution of Q7-a Answer : (1.11101)*2 2  7.625 Sign : 0  Positive Exponent : (10000000001) 2 – 1023 = 2 Fractional part : 1.11101  (1.11101)*2 2 = 111.101 Integer : 111  7 Floating : 0.101  0.625

16 Solution of Q7-b Answer : 11000000 00110000 10000000 00000000 00000000 00000000 00000000 00000000 Sign bit : Negative  1 Integer : 16  (10000) 2 Floating : 0.5  (0.1) 2 1.00001  offset 4bits Fractional part : 1.00001 Exponent : 1023+4 = 1027  10000000011

17 Q7 Suppose we have the following machine instructions for a simulated computer: You want to write a program to calculate 3x-2y where the x value is stored in the location of memory address 20, the y value is stored in the location of memory address 21, and the result is going to be stored in the location of memory address 22. Please show your program.

18 Solution of Q7 LOAD R0 20  100000010 00 10100 LOAD R1 21  100000010 01 10101 ADD R2 R0 R0  1010000100 10 00 00 ADD R2 R2 R0  1010000100 10 10 00 SUB R2 R2 R1  1010001000 10 10 01 STORE 22 R2  100000100 10110 10 HALT  1111111111111111

19 Q8-1 Please answer the following questions: (a)What would happen if you place the number 19 in R0 and the number 21 in R1, and set the knobs so that A bus = R0, B Bus = R1, ALU = A + B, and C Bus = R2? (b)Describe the settings that would cause the value stored in R0 to be cleared, i.e., the content of R0 would be zero, after execution.

20 Solution of Q8-1 (a)Answer : (b)Answer : A bus = R0, B Bus = R0, ALU = A - B, C Bus = R0 R019 R121 R240

21 Q8-2 (c)What task would the following machine- language program perform? 1000000100001010 1010000100000000 1000001000101000 1111111111111111 (d) Write a sequence of machine-language instructions that would add the contents of memory locations 12 and 13 then store the result in memory location 14.

22 Solution of Q8-2 (c)Answer : 100000010 00 01010 load memory 10 into R0 1010000100 00 00 00 add R0 and R0, store result in R0 100000100 01010 00 store R0 in memory 10 1111111111111111 halt (d)Answer : 100000010 00 01100 load memory 12 into R0 100000010 01 01101 load memory 13 into R1 1010000100 10 00 01 add R0 and R1, store result in R2 100000100 01110 10 store R2 in memory 14 1111111111111111 halt

23 Q9 Please just modify the function that counting the loops when the doubles are obtained and show the times of loops in next line. Test 4 <script type="text/javascript" src="http://dave-reed.com/book/random.js"> function twodice() { var d1,d2,count; d1=-1; d2=-2; while(d1 != d2) { d1=RandomInt(1,6); d2=RandomInt(1,6); document.getElementById("OutputBox").value= document.getElementById("OutputBox").value+"Dice1:"+ d1+"; Dice2:"+d2+"\n"; }

24 Solution of Q9 function twodice() { var d1,d2,count; d1=-1; d2=-2; count=0; while(d1 != d2) { count=count+1; d1=RandomInt(1,6); d2=RandomInt(1,6); document.getElementById("OutputBox").value = document.getElementById("OutputBox").value + "Dice1:"+d1+"; Dice2:"+d2+"\n"; } document.getElementById("OutputBox").value = document.getElementById("OutputBox").value + "Run "+ count + " rounds"; } 註:題目原意為將內容與結果一起 print 在 OutputBox 中 若在 function 的最後一行使用 document.write ,會覆蓋 function 原本要輸出的畫面,只剩下 document.write 的訊息。

25 The end of the 3 rd Exam


Download ppt "Introduction to Computers -3rd exam- 授課教授:李錫智. Q1 What will the web page look like if the user type 100 、 20 in the numberbox1 、 numberbox2 respectively?"

Similar presentations


Ads by Google