A-level Computing/AQA/Problem Solving, Programming, Data Representation and Practical Exercise/Skeleton code/2012 Exam/Section B
Contents |
Section B Introduction [edit]
This section will ask you questions that you will have to find programming solutions to. There will be more than one way of answering each question, so the answers below are only indicative of what we are looking for. As long as you get the same answers it doesn't matter how you do it. You may be given pseudeocode to help you program the problem.
Batting Averages [edit]
Write a program to enter batting scores until the number -1 is input. And then output the total and average score.
Mirayde's One
Answer :
Dim Score As Integer Dim Ave As Integer = 0 Dim Total As Integer = 0 Dim C As Integer = 0 Do Console.Write("Enter Score: ") Score = Console.ReadLine If (Score <> -1) Then Total = Total + Score End If C = C + 1 Loop Until Score = -1 Ave = Total / C Console.Write(" Your Total Is: " & Total) Console.WriteLine() Console.Write(" Your Average Is: " & Ave) Console.ReadLine()
Password Cracking [edit]
Write code to keep asking for login, only accepting: username= PSN Password = easy. Otherwise it should say. “Not hacked yet”:
Answer :
Dim username As String Dim password As String Do Console.WriteLine("Enter username: ") username = Console.ReadLine Console.WriteLine("Enter password: ") password = Console.ReadLine If username = "PSN" And password = "easy" Then Console.WriteLine("Hacked!") Else Console.WriteLine("Not Hacked yet") End If Loop Until username = "PSN" And password = "easy" Console.ReadLine()
Christmas Trees [edit]
Write code to print out a Christmas tree of a user defined size: even rows = *, odd = #. For example for the number 4 it should output:
Answer :
Dim number As Integer Console.WriteLine("Please enter a number: ") number = Console.ReadLine For count = 1 To number If count Mod 2 = 0 Then For x = 1 To count Console.Write("*") Next Console.WriteLine() Else For x = 1 To count Console.Write("#") Next Console.WriteLine() End If Next Console.ReadLine()