Question 1: Mark the Following Statements True Or False
Total Page:16
File Type:pdf, Size:1020Kb
Question A: Answer True or False. 10 points
1. The computer uses decimal number system for all False computations
2. Hexadecimal number system is a compact representation of True the binary number system. 3. The ASCII code for upper case and lower case alphabets is False the same. 4. Microsoft Windows is a word processing system. False
5. Computer memory is usually organized in bytes. True
6. Size of the address bus determines the memory capacity of True a computer system. 7. Each Assembly language instruction is equivalent to one True machine code instruction. 8. Visual Basic is a high level language. True
9. MS Word is an operating system. False
10. Complementary arithmetic allows subtraction True through addition.
11. Text boxes, picture boxes and command buttons are True some Visual Basic objects. 12. Visual Basic is an event driven programming True language.
13. The maximum value of a “Byte” type variable is False 16,384.
14. Variable defined as an Integer in Visual Basic True occupies two bytes of memory. 15. Picture box is used for reading (inputting) data. False
16. Picture boxes is a convenient medium for outputting True (displaying) the results. 17. Text boxes can be used for inputting as well as True outputting data.
18. The LTrim instruction splits a string into two sub False strings.
19. The FORMAT instruction works only for fixed width True fonts.
2 20. Data read from text box is in the form of a string. True
3 Question B: Choose the correct answer 20 points
1. Assume that you have to build your own computer. Your budget is limited and therefore you just want to buy the minimum possible hardware. Following list shows various components that you can buy. I. Printer (2 Points) II. Monitor III. Sound Blaster with speakers IV. Keyboard & mouse V. Hard drive with all the software pre-installed VI. CD ROM VII. CPU VIII. Modem IX. All connecting cables and power cables
Which of the following set of choices will you pick? a. I, IV, VI, VII, IX b. II, V, VI, VII, VIII c. II, IV, V, VII, IX d. II, IV, V, VI, VIII e. I, II, IV, VI, IX
2. What would be the result of Y = Mid(“Khush Aamdeed to Karachi”, 6, 4)? Note that Mid and Mid$ perform exactly the same operation. (2 Points)
a. Y=“sh Aam”
b. Y=“Aamd”
c. Y=“ Aam”
d. Y=“shAamd”
e. None of the above. The right answer is .
3. Pick a series that represents the first 7 numbers when counting in base-5 number system. If none of the given series is correct, write your own answer. (2 Points)
a. 1, 2, 3, 4, 5, 10, 11, …
b. 0, 1, 10, 11, 100, 101, 110, 111,…
c. 0, 1, 2, 3, 4, 10, 11, …
d. 1, 2, 3, 4, 5, 6, 10,…
e. 0, 1, 2, 3, 4, 5, 10, …
f. None of the above. The right answer is .
4. If R is a 4-bit unsigned, binary number and T is its 1’s complement, what is S=R+T in hexadecimal. ( 2 Points)
a. (0)16
b. (10)16
c. (F)16
d. (15)16
4 e. None of the above.
5. What is Sum = x + y, if x = 0.450 E 30 and Y = 0.550 E 28? (2 Points)
a. Sum = 1.000 E 28
b. Sum = 1.000 E 30
c. Sum = 4.555 E 29
d. Sum = 4.555 E 30
e. None of the above. The right answer is .
6. Assume that Y = Int ( 2 * X – 5 ). Circle the correct statement. (3 Points)
a. Y = +4 when X = 3.8
b. Y = - 12 when X = -3.8
c. Y = +3 when X = 3.8
d. Y = -13 when X = -3.8
7. While writing a computer program, two students attempt to solve the same issue in two different ways as follows. (3 Points) First-Student Program Second-Student Program If (X < -5) Or (X > 5) Then If Abs(X) > 5 Then ASTRING = “You got it” ASTRING=”You got it” Else Else ASTRING= “Try Again” ASTRING=”Try Again” End If End If Which of the following outcomes is correct? First-Student Program Second-Student Program a X=0 ASTRING=”You got it” ASTRING=”Try Again” b X=5 ASTRING=”You got it” ASTRING=”You got it” c X=4 ASTRING=”Try Again” ASTRING=”You got it” D X = -2 ASTRING=”You got it” ASTRING=”You got it” e None of the above None of the above
8. A computer has exactly 1000 bytes of memory. What is the minimum number of address lines needed to access each memory location? (2 Points)
a. 9 address lines
b. 11 address lines
c. 10 address lines
d. 8 address lines
e. 16 address lines
9. How many bits are there in a byte? (2 Points)
a. 4
b. 8
5 c. 10
d. 16
e. 32
Question C: Write short and to the point answers to the following questions in the respective boxes 30 points
For parts 1 to 3 write down what will be printed in the picture box Picture1 when the command button Command1 is clicked
1. (2 points) Sub Command1_Click( ) Dim a as Single, b as Single Let a=2*3 Let b=1+2^-2 Let a =6 Picture1.Cls Picture1.Print a+b End Sub
7.25
2. (2 points) Sub Command1_Click( ) Dim A As String, B As String, C As String Text1.Text= “Mid” Text1.Text=Text1.Text & “ ” A= “night” Picture1.Cls Picture1.Print Text1.Text & “term” End Sub
Mid term
3. (2 points) Sub Command1_Click( ) Dim cost1 as Single, cost2 as Single Let cost1= 2.3 Let cost2= cost1+ 7 Picture1.Cls Picture1.Print “cost1+cost2+2.3” End Sub
6 cost1 + cost2 + 2.3
4. Identify errors in the following block of code and re-write the corrected code. Assume that the command1 command button referred to in the code exist. (2 points)
Given Code Corrected Code Sub Command1_Click ( ) Sub Command1_Click ( ) Dim num As Single Dim num As Single num=28 num=28 If num >= 25 And < 35 Then If num >= 25 And num< 35 Then Picture1.Print “yes” Picture1.Print “yes” Else Else Picture1.Print “no” Picture1.Print “no” End Sub End if End Sub
5. Simplify (i.e. reduce the number of code lines of ) the following block of code to its least. Note: Left( ) and Left$( ) can be used interchangeably. (2 points)
Given Code Reduced Code If Left(answer, 1) = “N” Then If (Left(Ucase(answer),1)) = “N” Answer = “NO” Then End If Picture1.Print “Wrong” If Left(answer,1)= “n” Then Else Answer = “NO” Picture1.Print “Correct” End If End If If Answer = “NO” Then Picture1.Print “Wrong” Else Picture1.Print “Correct” End If
7 6. Convert the following decimal number to a binary number with the fractional part represented in 5 bits only. (5 points)
(135.23) 10
(135)10 = (10000111)2
0.23 x 2 ------0.46 x 2 ------0.92 x 2 ------1.84 x 2 ------1.68
(0.23)10 = (0.00011)2
(135.23) 10 = (10000111.00011) 2
7. Compute the result of 1110001-1001 using two’s complement method? Also convert your result into the decimal number. Note that both numbers are unsigned binary numbers. (4 points)
Add sign bit to 1110001 = 01110001 Convert 1001 to 8 bit Number = 00001001
I’s Complement of 00001001 = 11110110 Add 1 = + 1 ------2’s Complement of 00001001 = 11110111
Perform Addition : 01110001 11110111
8 ------101101000 ignore over flow bit 3 5 6 Decimal Value = 1*2 + 1*2 +1*2 = (104)10
8. Write a simplified block code using the select-case statement, which will perform the same as the given code: (3 points)
Given Code Equivalent Code If a<6 Then SELECT CASE a If a=3 Then CASE 3 Picture1.Print “yes” Picture1.Print “yes” Else CASE < 6 Picture1.Print “no” Picture1.Print “no” End If End SELECT Else If a=3 Then Picture1.print “maybe” End If End If
9. What is the range of values that could be generated by the given expression? (2 points)
Int(34*Rnd)-2
-2 to 31
10. What is the result of the following expression? Note: Format( ) or Format$( ) notations can be used interchangeably. (2 points)
Format$(2/3, “PERCENT”)
66.66%
9 Provide short answers for parts 12 and 13
11. What is Focus? (2 points)
Focus is the ability of a control to receive input from the keyboard. Only one control can have focus at one time and the control that will have focus will be able receive and respond to keys that are entered from the keyboard. For example if one textbox has the focus out of four textboxes on the form all our typed text will be input to that text box only till the focus is shifted to another one. Focus can be shifted by clicking another control or by using the TAB key.
12. What is the disadvantage of declaring a variable as of a single precision type instead of an integer type if we know that the values assigned to it will always be integer values in the range -100 to +100? (2 points)
Memory consumed by single precision variable is more than that consumed by an integer. If we know that the value assigned will be an integer value then the extra precision is not required.
10 11 Question D: 20 (5+15) points LUMS has hired you to design a fee payment calculation system to automate the quarterly student dues payment process. The Manager Accounts has given the following requirements for calculating the total dues (which is the output of the fee payment systems). Every student must pay the quarter registration charge of Rs 10,000. In addition a tuition fee of Rs 4,000 per unit is charged depending on how many units a student takes. Those students who stay in the hostel also pay a fixed charge of Rs 4,000 per quarter. If a student is late in paying his/her dues then he/she has to pay Rs 500 penalty per day. If the CGPA of the student is above 3.5, his/her tuition fee is completely waived and in addition he/she gets a discount of 50% on the remaining total dues.
a- Identify the inputs of the above payment system (i.e. the information required from the user to compute the dues in a specific case) and state them clearly. b- Draw a flowchart for this problem.
a- Inputs: 1) GPA 2) Boarding status (i.e.hostel) 3) Units 4) Current Date 5) Last day for payment
12 b)
Read Inputs: CGPA, Boarding Status, Units, Current Date and Last Date of Payment
Add Rs 10,000 to Total Dues
Yes Is boarding status Add Rs 4,000 to = Hostel? Total Dues
No
Calculate no. of Yes Is current date > late days last payment date?
No Multiply no. of late days with Yes Is CGPA > 3.5? Rs 500 and add to total dues.
No Divide total dues by 2 Multiply no. of units with Rs 4000 and add to total dues
Display Total Dues End
13 Question E: 20 points a) Write a Visual Basic program that will read an integer 1 through 7, and print out the day of the week, where 1 corresponds to Monday and so on. Use IF-ELSE decision structure to solve this problem. Assume that the input is taken through a text box and displayed using a text box and the program is executed when a command button is clicked. (10 points)
Private Sub Command1_Click()
If Val(Text1.Text) = 1 Then Text2.Text = "Monday" ElseIf Val(Text1.Text) = 2 Then Text2.Text = "Tuesday" ElseIf Val(Text1.Text) = 3 Then Text2.Text = "Wednesday" ElseIf Val(Text1.Text) = 4 Then Text2.Text = "Thursday" ElseIf Val(Text1.Text) = 5 Then Text2.Text = "Friday" ElseIf Val(Text1.Text) = 6 Then Text2.Text = "Saturday" ElseIf Val(Text1.Text) = 7 Then Text2.Text = "Sunday" End If
End Sub
14 b) Friday is a special day. The working hours are reduced due to the prayer break. Write a VB program for Friday that will take in time between 0900 (9:00 a.m.) and 1700 (5:00 p.m.) and print out the activity for the specific time slot. Note that the first two digits represent the hour of the day and the last two digits the minutes of the day. The activities and the time slots are given in the table below. Solve this problem using the SELECT-CASE structure. You may assume that the user always enter a valid time. Moreover, if a user enters a time other than between 9:00 a.m. to 5:00 p.m. the message “Not in office” is printed. The program should be executed when a command button is clicked and the output is printed in a picture box. (10 points)
Time 0900 1100 1200 1300 1400 Any Slot to to to to to other 1059 1159 1259 1359 1659 time Activity Preparing Lecturing Lecturing Prayer Office Not in Lectures CS101 CS 542 Break hrs Office
Solution 1:
Private Sub Command1_Click()
Dim hour As String Dim min As String
hour = Left(Text1.Text, 2) min = Right(Text1.Text, 2)
Select Case hour
Case “09”, “10” Picture1.Print "Preparing Lectures" Case “11” Picture1.Print "Lecturing CS 101" Case “12” Picture1.Print "Lecturing CS 542" Case “13” Picture1.Print "Prayer Break" Case “14”, “15”, “16” Picture1.Print "Office Hours" Case Else Picture1.Print "Not in Office"
End Select
15 End Sub Solution 2:
Private Sub Command1_Click()
Dim time As integer
REM Always valid time is entered time = Val(Text1.Text)
Select Case time
Case 9 To 10 Picture1.Print "Preparing Lectures" Case 11 Picture1.Print "Lecturing CS 101" Case 12 Picture1.Print "Lecturing CS 542" Case 13 Picture1.Print "Prayer Break" Case 14 To 16 Picture1.Print "Office Hours" Case Else Picture1.Print "Not in Office"
End Select
End Sub
16