Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
ICS3M1Exam Review What is a computer? Draw a computer What is ergonomics? Draw and label a picture of how you should sit at a computer. What are the three main constructs used to make a computer program? How many different kinds of looping statements does Visual Basic support? How many different Do statements does Visual Basic support? Sum the odd numbers from 51 to 100. Sum numbers from 50 to 30. Compute the factorial of 5! (5x4x3x2x1) Cerate program that will allow input form a file “EXAM_Jan08.txt” Calculate the Average, and output the numbers that are larger than the average to the File “YourName_Jan08.txt” 1. Find the Error: Rewite the whole program. Include the line numbers and add any lines that you need. Indent properly 1. 2. 3. 1. 2. 3. 4. 5. 6. 7. 8. 9. 1. 2. 3. 4. 5. For 1 – 10 Print “Hello” End CNT Dim A = real MyAge = messageBox(“Enter your Name”) If MyAge > 22 Print “Old” Else MyAge >14 Print “Teen-Monster” Otherwise Print just a kid Next Cnt Dim Mme = integer For TheName = 1 to 10 Inputbox(“enter Your Name”) = Mme Print Mme End for 2. Fill in the Blanks Rewrite the whole program This program should output the names of people that are Under 16 1. Dim Age _________ 2. Dim Name ________ 3. 4. For cnt = 1 to 10 5. Name = _____________________ 6. Age = ______________________ 7. If __________> 16 then 8. Print Name 9. ____________ 10. ____________ 3. Write the Code Create a program that will allow the user to enter the AGE of people and output “Average Under 16” Or output “Average Age is 16 ” OR output “Average Age is Over 16”. The average will be calculated and the repeation end when the age of 0 (zero) is entered. Write the code for a Picture PIC1 to move across the screen. Write the code that will make a PIC1 stop if it hits PIC2. Write the code that will average 5 marks between 0 and 100 Write the program that will output the highest number of 6 enteries Write the code that will allow the user to Write the code that will allow the user 3 guesses at a password (password is JUMP) Bubble Sorting What is the output of the following Do a Full Walkthrough Test Data: 10,11,1,99,21,2,12, 10, 100, 10000, 10101 1. ‘ Bubble Sort. 2. 'declare variables 3. Dim i, cnt, sample(7), temp, ABC As Integer 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 'counted loop repetition to input an array of numbers For i = 0 To 7 'collect data from input box into sample sample(i) = Val(InputBox("Enter Number")) Next i 'counted loop from 0 to 6 (ubound-1) Why 6??? For Outter = 0 To 6 ' counted loop from 1 past Outter to 7 (ubound) For Inner = (Outter + 1) To 7 'compare which number is greater to put highest on top If sample(Outter) < sample(Inner) Then 'swap the numbers temp = sample(Outter) sample(Outter) = sample(Inner) sample(Inner) = temp End If Next Inner Next Outter 'print in new order For i = 0 To 7 Print sample(i) Next i 1. Do a walkthrough with the data given above 2. Rewrite the line and line number so that the following changes can be made. a. sort in the opposite direction (ascending vs descending) b. the array Sample size is 100 elements c. Sort only elements 25 to 75 Random Numbers: Dim MyValue MyValueA = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6. MyValueB = Int((1000 * Rnd) ) ' Generate random value between 0 and 1000. MyValueC = Int((200 * Rnd) –100) ' Generate random value between -100 and 100. What is the code to create a random number between…. a) 50 and 100 b) 1 to 21 c) 1000 to 2000 d) –10 to +10 Repetition: Rewrite each of the following program so that they work 1 Output # 1 thourgh 10 on the screen For ___________ Print ___________ Next _______________ 2 Output # from 1 to 30 on the screen ______________________________ Print CNT Next __________________ 3 Output # from 50 random numbers that are between –100 and +100 For CNT _________________ Print ______________ Next ________________ 4 Sum Of numbers 1- 15: _________________________’initalize to zero For ______________________ MySum = ________________________ Next _____________ Print “The Sum from 1 to 15 is:” & MySum 5. Fill and array called MYDATA that is size 201 with random numbers between 0 and 100 ___________________ For _____________________ _____________________________ _____________________________ _______________________ Next CNT 6. Write the code that will sum (add together) all the numbers in the array MYDATA (in number 5) For ______________________ _____________________ Next Print MyDataTotal 5 What is the following code going to do??? Give detail for 3 Marks For CNT = 1 to 10 Picture1.Top = Picture1.Top + CNT Picture1.Left = Picture1.Left +CNT Next CNT 8. Conditional Loop : Repeat until Input is “HELLO” Do __________________________________________________ MyWord = inputbox(“Enter a password”) _____________________________ 9. Conditional Loop : Repeat while Total is less than 1000 OR 10 numbers have been entered Output the total at the end of the repatition. _________________ _________________ Do __________________________________________________ MyNum = VAL( inputbox (“Enter a password”) ) Total ______________________________ ‘Sum of MyNum MyCount ____________________________ _____________________ _____________________ Read and Write Files Private Sub Command1_Click() 1. Open "c:\MyDataFile.txt" For Input As #1 2. Open "c:\MySolutionFile.txt" For Output As #2 3. 4. Do Until EOF(1) 5. 6. Input #1, TheData 7. 8. NewData = StrConv(TheData, 3) Write #2, NewData 9. 10. Print NewData 11. Loop Close #1 12. Close #2 13. End Sub 14. 15. 16. Private Sub Command2_Click() 17. Open "c:\MySolutionFile.txt" For Input As #1 18. 19. Do Until EOF(1) 20. 21. Input #1, Somedata 22. List1.AddItem Somedata 23. 24. Loop 25. 26. Close #1 27. End Sub 28. Q: What does each part of this command do? Open "c:\MySolutionFile.txt" For Output As #2 Q: Why do you need to close files Q: What does EOF(1) mean? What is the digit 1 used for? Selection 1. Input an Income for 5 people that work in a companyn (Use an array). Calculate the tax for each of them and output the Tax and the Take-Home based on on the following Scale: a. 0 - $16,500 0% b. 16,501 – 21,000 7% c. 21001 – 25,000 10% d. 25,001 - 33000 12% e. 33,001-70,000 17% f. 70,001 – 90,000 22% g. 90,001 – 100,000 29% h. 100,000 up 37% Store the tax that each person pays into a second array Output the total tax and the average tax paid by the employees Use control array to create a game of connect 3. The game 3. When are the following statements executed? a) the statements underneath the If line? b) the statements underneath the Else line? c) the statements underneath the Else line? 4. Find mistakes in the following (Rewrite all the code correctly ON PAPER then try it out on the computer): a) If m_number >= 0 And m_Number <= 100 Then Print “Valid mark” Else If Debug.Window “Invalid entry” EndIf b) If Age >17 Print “ A major" Print “ Age of Majority" End If c) If Mark <= 0 And Mark >= 100 Then Debug.Print “Not a mark” End If Z=inputbox(“This is a test Mark”) X = inputox(“This is the grade”) If z>x then If z>10 Print x Else Print “too small” Else Print “z is bigger than x” End if 6. State what happens in the following program: Write on paper what you think it will do then test the code on the computer and see if you are correct. i. Dim Large As Integer, Small As Integer, Y As Integer Large = 20 Y = 21 If Large < Y Then Large = Y Else Small = Y End If String Manipulation 1. What is the result of each of the following commands: [6 marks] a) print Mid(“This is a test”,1 , 1) b) print mid(“this is a test”, 2, 2) c) print Ltrim (“ this is a test “) d) print LEN(“This is a test”) e) print Ucase (“This is a test”) f) print instr ( 1, “This is a test”, “is”) 3 Create the following code.] a) Input a word and output it in reverse ie) Hello => olleH b) Input a sentence and output the number of words in the sentence. 4 What is the output of: a) print asc(“A”) b) print acs (“a”) c) print asc (“d”) Walkthroughs of the following: What is the output of the following 1. Dim Age(4), ShoeSize(4) as Integer 1. Dim THIS as string 2. TotalAge=0 2. THIS = “Exam Preep” 3. For cnt = 0 to 4 3. For A = 0 to len( THIS) 4. Age(cnt) = InputBox(“Enter Age”) 4. x=mid(THIS,A,1) 5. ShoeSize(cnt) = InputBox(“Shoe Size”) 5. if x = “E” or x = “e” then 6. Total Age = TotalAge + Age 6. E_count=E_count+1 7. Next cnt 7. endif 8. AverageAge = TotalAge / 5 8. Next A 9. For ZZ = 4 to 0 step -1 9. Print E_Count 10. If AverageAge > ShoeSize(ZZ) then 11. Print “act your age” 12. Else 13. Print “Good” 14. End if 15. Next ZZ Test Data 11,21, 23, 12, -32,22, 0,0, 32, -4 1. For A = 1 to 40 Step 8 Do until MyMark=-99 2. XY =Inputbox (“Enter a Value”) MyMark=val(inputbox(“Enter a mark”) 3. If XY > A or XY<0 then Total = total + MyMark 4. Print XY Count = count+1 5. Else Loop 6. Print A Average = total/count Testdata: 76,75,74 ,-99 7. Endif 8. Next A Is there a problem with this program that should Test Data: 5,8,17,0,-31 calculate the average. Rewrite a correct program.