Its Computing AQA As level. If some one could please just walk me threw it and exsplain it vaguely. HTe more detail the better but u can be as vuage as you want i dont care how much help you give any would be great.!XxX
Module Module1
' Skeleton Program code for the AQA COMP1 Summer 2009 examination
' this code should be used in conjunction with the Preliminary Materials
' written by the AQA COMP1 Programmer Team
' developed in the Visual Basic 2005 (Console Mode) programming environment
' the DisplayMenu procedure has deliberately omitted a menu choice 3 and 4
Dim NewPhrase As String
Dim PhraseHasBeenSet As Boolean
Dim PhraseGuessed As Boolean
Dim Choice As Integer
Dim IndividualLettersArray(20) As Char
Dim GuessStatusArray(20) As Char
Dim LettersGuessedArray(26) As Char
Dim NextGuessedLetter As Char
Dim Index As Integer
Sub DisplayMenu()
Console.WriteLine("__________________________________")
Console.WriteLine("")
Console.WriteLine("1. SETTER - Makes new word/phrase")
Console.WriteLine("")
Console.WriteLine("2. USER - Next letter guess")
Console.WriteLine("")
Console.WriteLine("5. End")
Console.WriteLine("")
End Sub
Sub Main()
PhraseHasBeenSet = False
Do
Call DisplayMenu()
Console.Write("Choice? ")
Choice = Console.ReadLine
If Choice = 1 Then
NewPhrase = GetNewPhrase()
SetUpGuessStatusArray(NewPhrase, IndividualLettersArray, GuessStatusArray)
PhraseHasBeenSet = True
End If
If Choice = 2 Then
If PhraseHasBeenSet = True Then
DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
NextGuessedLetter = GetNextLetterGuess()
' is this letter present ?
For Index = 1 To Len(NewPhrase)
If NextGuessedLetter = IndividualLettersArray(Index) Then
GuessStatusArray(Index) = NextGuessedLetter
End If
Next
DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
PhraseGuessed = AllLettersGuessedCorrectly(GuessStatusArray, NewPhrase, _
IndividualLettersArray)
If PhraseGuessed = True Then
Console.WriteLine("You have guessed correctly")
End If
Else
Console.WriteLine("The setter has not specified the word/phrase ..")
End If
End If
If Choice = 5 And PhraseGuessed = False Then
Console.WriteLine("You have not completed this word/phrase...Press return to exit")
Console.ReadLine()
End If
Loop Until Choice = 5
End Sub
Function GetNewPhrase() As String
Dim PhraseOK As Boolean
Dim ThisNewPhrase As String
Do
Console.Write("Key in the new phrase .. (letters and any Spaces ") : ThisNewPhrase = Console.ReadLine()
If Len(ThisNewPhrase) < 10 Then
PhraseOK = False
Console.WriteLine("Not enough letters ... ")
' possible futher validation check(s)
Else
PhraseOK = True
GetNewPhrase = ThisNewPhrase
End If
Loop Until PhraseOK = True
End Function
Sub SetUpGuessStatusArray(ByVal NewPhrase As String, ByVal IndividualLettersArray() As Char, _
ByVal GuessStatusArray() As Char)
Dim Position As Integer
For Position = 1 To Len(NewPhrase)
IndividualLettersArray(Position) = Mid(NewPhrase, Position, 1)
If IndividualLettersArray(Position) = " " Then
GuessStatusArray(Position) = " "
Else
GuessStatusArray(Position) = "*"
End If
Next
End Sub
Sub DisplayCurrentStatus(ByVal PhraseLength As Byte, ByVal GuessStatusArray() As Char)
Dim Position As Integer
For Position = 1 To PhraseLength
Console.Write(GuessStatusArray(Position))
Next
Console.WriteLine()
End Sub
Function GetNextLetterGuess() As Char
Dim GuessedLetter As Char
Console.WriteLine()
Console.Write("Next guess ? ") : GuessedLetter = Console.ReadLine()
GetNextLetterGuess = GuessedLetter
End Function
Function AllLettersGuessedCorrectly(ByVal GuessStatusArray() As Char, _
ByVal NewPhrase As String, ByVal IndividualLettersArray() As Char) As Boolean
Dim Position As Integer
Dim MissingLetter As Boolean
MissingLetter = False
Position = 1
Do
If GuessStatusArray(Position) <> IndividualLettersArray(Position) Then
MissingLetter = True
Else
Position = Position + 1
End If
Loop Until MissingLetter = True Or Position = Len(NewPhrase) + 1
If MissingLetter = False Then
AllLettersGuessedCorrectly = True
Else
AllLettersGuessedCorrectly = False
End If
End Function
End Module
Edited by WingedPanther, 21 April 2009 - 06:25 AM.
add code tags (the # button)


Sign In
Create Account

Back to top










