Jump to content

HELP ME PLZ!! need a walk through of this.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
MichalS

MichalS

    Newbie

  • Members
  • Pip
  • 2 posts
For my exam im exspected to know and understand how this works and how it can be improved.
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)


#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
If I understands you right you need help to know what this code does, is that correct?

#3
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Well I will assume your class is over since mine are but maybe not. I dont know VB at all but the names of all the variables and subs and functions etc are all long and detailed it shouldnt be hard to just read it and realize what it does if your familiar with any type of flow charts

First a few variables are created

a sub is created

main sub is created

print the display menu sub

asks for input

few if statements to tell what the user inputted - and does basically what it says it does in the "DisplayMenu()" sub

A few functions are displayed at the bottom

#4
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Yes, it wasn't hard at all to figure out what it did, the question is if he still need it.