1 / 16

Introduction to Computers 第三次考試

Introduction to Computers 第三次考試. 授課教授 : 李錫智. 第一題. [15] Suppose random( x,y ) returns an integer randomly between x and y inclusively. Consider the following program: <html> <head> <title> Just for Fun</title> <script type="text/ javascript "> function GetResponse () { var response;

starbuck
Download Presentation

Introduction to Computers 第三次考試

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computers第三次考試 授課教授:李錫智

  2. 第一題 [15] Suppose random(x,y) returns an integer randomly between x and y inclusively. Consider the following program: <html> <head> <title> Just for Fun</title> <script type="text/javascript"> function GetResponse() { var response; if (document.getElementById('inputArea').value == "") { alert("What is your question?"); } else { response = random(1,5); document.getElementById('outputBox').value = response; } } </script> </head>

  3. <body> <div style="text-align:center"> <h2>Have a Fun</h2> <p>Enter your question in the text area below: </p> <p> <textarea id="inputArea" rows="5" cols="40"></textarea> </p> <p> <input type="button" value="Play the Game" onclick="GetResponse()" /> </p> <p> The page says: <input type="text" name="outputBox" size="30" value="" /> </p> </div> </body> </html>

  4. (a) [5] What is the content of the “outputBox” without any user’s input? (b) [5] What happens if the user hits the button without any other input? (c) [5] What happens if the user hits the button after entering “How are you?” in the text area? (a)空白 (b)跳出警告視窗,警告視窗上的字為 What is your question? (c)OutputBox會顯示一個1~5之間的隨機亂數 Ans:

  5. 第二題 [20] Consider the following program: <html><head> <title> Another Fun </title> <script type="text/javascript"> function XXX() { var goal, redPos, bluePos; goal = parseFloat(document.getElementById('len').value); redPos = parseFloat(document.getElementById('redDot').value); bluePos = parseFloat(document.getElementById('blueDot').value); if (redPos < goal && bluePos < goal) { redPos = redPos + 3; bluePos = bluePos + 5; document.getElementById('redDot').value = redPos; document.getElementById(‘blueDot’).value = bluePos;}

  6. if (redPos >= goal && bluePos >= goal) { alert(“It‘s a tie!”);} else if (redPos >= goal) { alert(“Red Dot wins!”);} else if (bluePos >= goal) { alert(“Blue Dot wins!”);}} </script></head> <body> <div style="text-align:center"> <h2>Dave's Online Dot Race</h2> <p> Race length: <input type="text" id="len" size=3 value="20" /> </p><hr /><p> <span style="color:red">Red Dot :</span> <input type="text" id="redDot" size="3" value="0" /> &nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="blueDot" size="3" value="0" /> <span style="color:blue">: Blue Dot</span> </p><p> <input type="button" value="Try One" onclick="XXX();" /> </p></div></body></html>

  7. (a) [10] What is the output of the program if the user types 10 in the “len” box, 7 in the “redDot” box, 9 in the “blueDot” box, and hits the button? (b) [10] What is the output of the program if the user types 20 in the “len” box, 27 in the “redDot” box, 19 in the “blueDot” box, and hits the button? (a)跳出警告視窗,警告視窗上的字為It’s a tie ! (b)跳出警告視窗,警告視窗上的字為Red Dot wins ! Ans:

  8. 第三題 [15] A grayscale image is one in which each pixel can be white, or black, or various shades of gray in between. On the other hand, a color image is one in which each pixel contains three components, red, green, and blue. Assuming that there are 256 discernable shades of gray. Also, assume that there are 256 different values for red, green, and blue, respectively. Suppose you are given an image of 1024×1024 pixels.

  9. (a) [2] How many Mega bits are required for the image if it is a grayscale one? (b) [3] How many Mega bits are required for the image if it is a color one? (c) [5] How many Mega bits are required for a video of 2 hours? Suppose a video requires 30 images per second? (d) [5] How many Mega bits are required for the video if you compress the video using Mpeg which has a compression ratio 100:1? Note that when an image file of size K is compressed with a compression ratio of a:1, the resulting image file would be of size K/a (a)1024*1024*8=8Mbits (b)1024*1024*8*3=24Mbits (c)1024*1024*8*3*30*3600*2=5184000Mbits (d)5184000/100=51840Mbits Ans:

  10. 第四題 [10] Assume that random(x,y) returns an integer between x and y inclusively. Please write a program to record the number of occurrences of 5 when random(1,6) is called 1,000 times. Please show the number in a text box. Also, the user has to hit the button in order to start the counting.

  11. Ans: <html><head><script> function count() { varnum=1000,temp,count_five=0; while(num>=1) { temp=Math.floor(Math.random()*6+1); num=num-1; if(temp==5) { count_five=count_five+1; } } document.getElementById('text').value=count_five; } </script></head><body> <input type="button" value="counting" onclick="count();" /> <input type="box" id="text" size="2" /> </body></html>

  12. 第五題 [10] Predict the output sequences that would be produced by each of the following while loops. (a) [5] num = 1; while (num >= 5 && num <= 30) { document.write(num + "<br />"); num = 3*num + 1; } document.write("DONE WITH FIRST!"); DONE WITH FIRST ! Ans:

  13. (b) [5] x = 1; y = 30; while (x < y) { document.write(x + " " + y + "<br />"); x =2* x + 1; y = y – 2; } document.write("DONE WITH SECOND!"); 1 30 3 28 7 26 15 24 DONE WITH SECOND ! Ans:

  14. 第六題 [12] Consider the following code segment: If (x > y) { y = x; } else if (x < y) { x = 100; } else { y = -50; } document.write(“x = “ + x + “, y = “ + y); Given the following assignments, predict the output that the preceding code would produce: (a) x = -7, y = 8; (b) x = 15, y = 3; (c) x = -8, y = -8; (d) x = 0, y = -9. (a)x=100,y=8 (b)x=15,y=15 (c)x=-8,y=-50 (d)x=0,y=0 Ans:

  15. 第七題 [18] Using the IEEE Single-Precision Floating-Point Representation (32 bits), please answer the following questions: (a) What is the bit string for the decimal number 0.00000018125? (b) What is the decimal number for the bit string 10101010110100000000000000000000? (c) How many bytes for sending the following sequence in ASCII codes?“Hello, I am John. How are you doing? Have fun!?#” (d) What is the smallest positive single-precision value denoted in bit string? (e) What is the largest positive single-precision value denoted in bit string? (f) What is the smallest negative single-precision value denoted in bit string? Hint: The case of all zeros in the EXPONENT field is reserved for representing 0.0 (real zero).

  16. Ans: (a)001101000100001010011101100111101 (b) 1=>-1 01010101=>85 85-127=-42 10100000000000000000000=>0.5+0.125=0.625 Ans: (c)48Bytes (d)00000000100000000000000000000000=> (e)01111111011111111111111111111111=> (f)11111111011111111111111111111111=>

More Related