The Student Room Group

Higher Computing Coursework Task Help

Scroll to see replies

Reply 60
Original post by lewis_dicks
I managed to work it out, but I used four arrays, one for the letter being extracted, one for the ASCII value of that letter, one for the crash counters and one for displaying the characters.


That's good you worked it out, but if the task is being graded in terms of efficiency as well as all the other aspects, you may lose the mark(s) as your as using an array where it is not needed. I am assuming that the array holding the ASCII values are used for the validation. You don't need to use an extra variable to validate that the 10-character string is between a and f, you only need a case statement and a boolean variable, I think I may have posted parts of the code for this early on this forum but I'll post part of it again.

Inside the loop you are using to extract each letter, you would just add the case statement in there, examining each character as you go, assuming the variable used to help the character is a 10 item array called TempString. The code would look like this:

For i = 1 To 10
[INDENT]'Character extraction code[/INDENT]
[INDENT]Select Case TempString[/INDENT]
[INDENT][INDENT]Case Is = "a"[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]ErrorFound = False[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]Case Is = "b"[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]ErrorFound = False[/INDENT][/INDENT][/INDENT]
and so on until you have done this for character f...
[INDENT][INDENT]Case Else[/INDENT][/INDENT]
[INDENT][INDENT]ErrorFound = True[/INDENT][/INDENT]
End Select
Next i

You would then just add ErrorFound = True to your conditional loop that will ask the user to re-enter the input if necessary.

It's up to you if you want to change it, if you fully understand the task you have been given and how you intend to tackle it, then I would change it. But it's up to you. If you have already written the documentation and completed the solution in this way, then I do not recommend changing it as it would involve, more-or-less, re-doing everything you have done so far.
Reply 61
Original post by JohnW1995
The method I used can't choose between levels if more than one level has the max crashes (I think it would only remember the first level it check, so if Level A and Level F had the same amount of crashes, it would flag Level A as having the most crashes), however the program should display how many times each level crashed, so the user should be able to see if two or more levels have crashed the same number of times. I can't remember what the test data values were that were given by the SQA but I don't think it would cause such an issue.

If it does, I would probably use either an IF statement or a case statement to check if any other levels has the same amount of crashes, or when assigning a level to the most crashes, it would assign letters (a - f) for the levels that crashed the same amount of times.

Good question though.


Just to say, that the sqa test data does have two levels with the same max no. of crashes.

If once you have found the max, you do another if statement like:

For times = 1 to 6

If no.ofcrahsesarray(times) = max THEN
DISPLAY level
End IF

Next loop

That's what I did and it seemed to work.
Reply 62
Original post by havengirl
Just to say, that the sqa test data does have two levels with the same max no. of crashes.

If once you have found the max, you do another if statement like:

For times = 1 to 6

If no.ofcrahsesarray(times) = max THEN
DISPLAY level
End IF

Next loop

That's what I did and it seemed to work.


Thanks for letting me know. I haven't gotten a chance to look at the task paper because we are now doing prelim revision and won't be going back to the coursework until at least the 17th. Thanks for letting me know though, I wasn't exactly sure how I would tackle that problem.
Wouldn't that algorithm just produce the highest value twice?
Original post by lewis_dicks
Wouldn't that algorithm just produce the highest value twice?


If I understand what they're recommending correctly, their program looks kind of like

1.

Get crash string

2.

Sort of invert it, so that e.g. "abaccadc" becomes [3, 1, 3, 1] (i.e. first element is number of times 'a' appears, second is the same for 'b', etc.)

3.

Find the maximum of this array (3 in the example)

4.

Loop through the array again: at each index, test if the value = that of the maximum, and print/append to a list/whatever the corresponding character was ('a', 'c')



It might be clearer if you name 'times' instead something like 'kind'.
Reply 65
Does anyone know how to clear text from a picture box on Visual Basic?
Thanks
Original post by havengirl
Does anyone know how to clear text from a picture box on Visual Basic?
Thanks


<name>.Cls, I think.
Reply 67
Original post by TheUnbeliever

Original post by TheUnbeliever
&lt;name&gt;.Cls, I think.


Thanks will try that tomorrow
Anyone found some good benchmarking software?
Original post by lewis_dicks
Anyone found some good benchmarking software?


Sorry, I missed 'quote' :frown: Check out 3DMark, it's a popular one.
Hi all !

could anyone please help me with this ,
Private Sub Validate_Entry(ByRef Entry As String)
Dim EntryOK As Boolean

EntryOK = False
For Counter = 1 To 10
Entry = LCase$(Entry)
Entry = Mid$(Entry, Counter, 1)
Entry = Asc(Entry)
If Entry >= 97 And Entry <= 102 Then
EntryOK = True
EntryOK = Chr$(Entry)
Else : MsgBox("level you enterd does not exist")
End If
Next
Loop until EntryOK = True

lstdisplay.Items.
End Sub

Anyone tell me whats up ? completely lost on the validation

and

Dim max_crashes As Integer
Dim Index As Integer

max_crashes = count(1)
For Index = 1 To 6
If count(Index) > max_crashes Then
max_crashes = count(Index)
End If
Next
lstdisplay.Items.Add(" ")
lstdisplay.Items.Add("The level that crashed- ")

For Index = 1 To 6
If count(Index) = max_crashes Then
lstdisplay.Items.Add(Chr(96 + Index))
lstdisplay.Items.Add(Chr(97 + Index))
lstdisplay.Items.Add(Chr(98 + Index))
lstdisplay.Items.Add(Chr(99 + Index))
lstdisplay.Items.Add(Chr(100 + Index))
lstdisplay.Items.Add(Chr(101 + Index))



End If
Next
End Sub
End Class

the counting the crashes is fine , but when it is displaying what levels crashed it gives every letter from a-f
Reply 71
Original post by Twofournine
Hi all !

could anyone please help me with this ,
Private Sub Validate_Entry(ByRef Entry As String)
Dim EntryOK As Boolean

EntryOK = False
For Counter = 1 To 10
Entry = LCase$(Entry)
Entry = Mid$(Entry, Counter, 1)
Entry = Asc(Entry)
If Entry >= 97 And Entry <= 102 Then
EntryOK = True
EntryOK = Chr$(Entry)
Else : MsgBox("level you enterd does not exist")
End If
Next
Loop until EntryOK = True

lstdisplay.Items.
End Sub

Anyone tell me whats up ? completely lost on the validation

and

Dim max_crashes As Integer
Dim Index As Integer

max_crashes = count(1)
For Index = 1 To 6
If count(Index) > max_crashes Then
max_crashes = count(Index)
End If
Next
lstdisplay.Items.Add(" ")
lstdisplay.Items.Add("The level that crashed- ")

For Index = 1 To 6
If count(Index) = max_crashes Then
lstdisplay.Items.Add(Chr(96 + Index))
lstdisplay.Items.Add(Chr(97 + Index))
lstdisplay.Items.Add(Chr(98 + Index))
lstdisplay.Items.Add(Chr(99 + Index))
lstdisplay.Items.Add(Chr(100 + Index))
lstdisplay.Items.Add(Chr(101 + Index))



End If
Next
End Sub
End Class

the counting the crashes is fine , but when it is displaying what levels crashed it gives every letter from a-f


For your validation, you don't have to use the Ascii values of the input in order to validate it. You only need a case statement after you have used substring on the 10 character string. The code would look similar to this:

Select Case TempString(Counter)
[INDENT]Case Is = "a"[/INDENT]
[INDENT][INDENT]EntryOK = True[/INDENT][/INDENT]
[INDENT]Case Is = "b"[/INDENT]
[INDENT][INDENT]EntryOK = True[/INDENT][/INDENT]
You would continue this down until you have done so for all the levels (a - f)
[INDENT]Case Else[/INDENT]
[INDENT][INDENT]EntryOK = False[/INDENT][/INDENT]
End Select

You would then use a conditional loop to check if EntryOK = False, if it does then ask the user to re-enter the input, if not then it should move onto the next sub routine.

As for the max crashes part, it would just be the find maximum algorithm, however, as the test data will cause there to be two levels that crashed the same number of times, the find maximum algorithm on its own will not produce the correct results. There are various ways of overcoming this, but I cannot find an efficient way of doing so as of yet.
Reply 72
Onto section 2 of the task now , anybody having any luck finding 6 core computer desktops that fit the price tag? Can't find any :/
Reply 73
Original post by judzi
Onto section 2 of the task now , anybody having any luck finding 6 core computer desktops that fit the price tag? Can't find any :/


TheUnbeliever posted the answer to your questions on the first page of this forum:

"Mesh Slayer X79 Pro with the Intel i7 3930K."
Reply 74
Hi, I am having trouble with my program with the input validation a-f using a case statement, Any help would be much appreciated. Thanks.


Private Sub Validate_Input_Data(ByRef Found As Boolean, ByVal Counter As Integer, ByRef TempString() As String, ByRef TestData As String)

Found = False

Do
For Counter = 1 To 10
TestData = LCase$(TestData)
TestData = Mid$(TestData, Counter, 1)


Select Case TempString(Counter)

Case Is = "a"
Found = True

Case Is = "b"
Found = True

Case Is = "c"
Found = True

Case Is = "d"
Found = True

Case Is = "e"
Found = True

Case Is = "f"
Found = True

Case Else
Found = False

End Select

If Found = False Then

'Display message asking user to try again'
MsgBox (TestData & " is not a valid 10 character string! Please try again !")

'Else'
Else

End If

End Sub
(edited 12 years ago)
Original post by Chezoeduyv
Hi, I am having trouble with my program with the input validation a-f using a case statement, Any help would be much appreciated. Thanks.


Points:
- Why is Counter a parameter?
- Why do you modify TestData and then completely ignore it?
- Why do you need both TestData and TempString at all?
- Comments must start with a single quote, they don't need one at the end
- For loop syntax is:

For var = min to max
' ...
Next


Have one function (or procedure with a reference parameter which you use to pass the result out, if you don't know how to define a function) which takes a string, and returns true if that string is valid. Note that this needs exactly one input parameter (a string) and passes out a single value (a boolean, true if valid, false if not).

Then have another function/procedure, as above, which repeatedly asks for input until it is given something valid. This should take exactly zero input parameters, and pass out a single value (a valid string). That would look something like the following.

Function IsValid(ByVal input as String) as Boolean
Dim valid as Boolean
valid = true
' FOR EACH character IN input
Dim this_character_valid as Boolean
' Your case statement construct here, or any other method
valid = valid And this_character_valid ' think about why this works
' END FOR
IsValid = valid
End Function

Function GetCrashes() as String
Dim input as String
Do
' Read input using InputBox or whatever
Loop Until IsValid(input)

GetCrashes = input
End Function


Note my Visual Basic is rusty, but you should get the idea.
(edited 12 years ago)
Reply 76
Hi!

I'm back :/ I managed to take on board all the advice from everyone and get the program working ! Just one problem as you know in the SQA's test data two levels have crashed the same number of times and are the max crashed levels e.g. a=3 e=3 at the moment my program will only display a as the level that crashed most with 3 crashes however it should display a and e etc etc. I know this was discussed earlier but I have tried everything and cannot get it to work. All help will be much appreciated !

Thank you. (Code in next post)
Original post by Chezoeduyv
I know this was discussed earlier but I have tried everything and cannot get it to work. All help will be much appreciated !

I'm going to try my psychic powers :wink: and guess that you have a loop iterating through an array with 6 elements, corresponding to a-f. You compare each to the maximum and then update a variable.

max_char := 'z'
FOR i = 1 TO 6
IF counts = max_count THEN
max_char = ' a if i = 1, b if i = 2, etc. - probably using a case statement
END IF
END FOR


Obviously this only records the last maximum encountered. The easiest way of fixing this is to keep your index-to-character conversion, but instead of storing the result in a variable, just print it there and then.

An alternative is to make max_char an array of length five. (In the extreme, we might have had a situation like "aabbccddee".) We have an integer next which is initially 0, and tells us where to store the next thing into the array.

Now, when you do your index-to-character conversion, you store the result at max_char[next] and then increment next. Afterwards, you know the character(s) corresponding to the most crashes are those in the elements at indices less than next (e.g. in the extreme example I gave above, next would be 6 - assuming your first index is 1 - and all of the elements have valid data in.)
Reply 78
In the pseudocode tasks, are there any style conventions that the markers expect to see? My teacher barely mentioned pseudocode conventions in class.

As for the programming itself, I'm doing it in Python. I stupidly jumped into the programming before having properly looked at the task specification or having done the design tasks, thinking, "ooh, this looks simple, let's just skip to it and reverse-engineer the design notation". As a result, I'm now having to rewrite half of it. A valuable lesson: work out what code you're supposed to be writing before you waste time writing the wrong code.
Original post by Lenina
In the pseudocode tasks, are there any style conventions that the markers expect to see? My teacher barely mentioned pseudocode conventions in class.


Nope. You pretty much just make it up. :smile:

As a result, I'm now having to rewrite half of it. A valuable lesson: work out what code you're supposed to be writing before you waste time writing the wrong code.


:wink:

Quick Reply

Latest

Trending

Trending