I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

Introduction to Computers -3 rd exam-

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

[10] Suppose we have the following lines of code: if (grade < 60) { alert(“Sorry! You failed.”); } else { alert(“Congratulations! You passed.”); } alert(“Execution ends!”); • [3] What will the response be if grade is set to 65 before the first line of the code? ANS: Congratulations! You passed. Execution ends!

[7] Please rewrite the code without using “else” or ”elseif”. Note that the execution result should be totally identical to that of the original code. ANS: if (grade < 60) { alert(“Sorry! You failed.”); } if (grade >= 60) { alert(“Congratulations! You passed.”); } alert(“Execution ends!”);

[10] Suppose we have the following lines of code: if (temperature <= 50) { if(windSpeed<= 3) { windChill= temperature; } else { windChill= 20 + temperature + 0.5*windSpeed; } } else { windChill= temperature; } alert(“Execution ends with “ + windChill + “!”); • [3] What will the response be if temperature and windSpeed are set to 40 and 10, respectively, before the first line of the code? ANS: Execution ends with 65 !

[15] Please write a program in assembly language to • [5] Double the content of R0 and store the result in R2. ANS: ADD R2 R0 R0 HALT • [5] Triple the content of R0 and store the result in R2. ANS: ADD R2 R0 R0 ADD R2 R2R0 HALT • [5] Double the content of the location of memory address 7 and store the result in the location of memory address 8. ANS: LOAD R0 7 ADD R2 R0 R0 STORE 8 R2 HALT

[10] You want to calculate 3x-2y. You write a program in assembly language to do it. Suppose the x value is stored in the location of memory address 30, the y value is stored in the location of memory address 31, and the result is going to be stored in the location of memory address 32. Please show your program. ANS: LOAD R0 30 LOAD R1 31 ADD R2 R0 R0 ADD R2 R2 R0 SUB R2 R2 R1 SUB R2 R2 R1 STORE 32 R2 HALT