The Student Room Group

Higher Computing Coursework Task Help

The coursework task for Higher computing has just recently been released and we're now beginning it in my class

Problem is, I'm terrible at programming. So was wondering if anybody has any advice on how to get started with my code etc

If anyone else has problems post them here aswell, someones bound to help :wink:

Scroll to see replies

What is the task this year?
Reply 2
Basically you have to take in a 10 character string of letters a-f. Validate that the string is 10 letters long and that only those characters have been used
Then count how many times each letter appeared in the string and display the count for each letter

It took me ages just to make the validation work, have no idea how to do the count of letters :frown:
Original post by judzi
It took me ages just to make the validation work, have no idea how to do the count of letters :frown:


Language? Visual Basic has Len: Len("Test") = 4
Reply 4
Original post by TheUnbeliever
Language? Visual Basic has Len: Len("Test") = 4


Using visual basic, I've started using Mid$ to find out what the letter is. I keep getting errors though
Original post by judzi
Using visual basic, I've started using Mid$ to find out what the letter is. I keep getting errors though


Kind of difficult to know what your problem is without knowing the errors, and I don't want to provide complete code, but Mid$(s, i, 1) will give you the character at position i in s. Other thoughts: how might a combination of Left and Right accomplish the same thing; and how will you handle "F" vs "f" cleanly?
Original post by judzi
Using visual basic, I've started using Mid$ to find out what the letter is. I keep getting errors though


To validate, you could use a conditional statement in VB like so:
word=inputbox("Enter a word please!")
If len(word) > 10 or < 10 then
msgbox(word & " is not 10 characters long!")
else
msgbox(word & " is 10 characters long!")
etc...

A case select would also work I think! :smile:
You can also have the code running in an infinite loop until the variable "word" has 10 characters. The aforementioned will then break the loop once satisfied.
Do
...validation code...
loop until len(word) = 10

It's been a while since I've used VB, it's C++ I've been working with but if there is any other apsect of the course(.i.e. processors, networking, AI etc...) that you don't understand, then feelfree to ask me!! :smile:
Reply 7
any one found a six core processor computer ?
Original post by fraser_94
any one found a six core processor computer ?


Mesh Slayer X79 Pro with the Intel i7 3930K.
I have a different problem; when it is displaying the the max crashes and its number, it always displays the letter a regardless of the input. it counts everything else fine. Also I am using VB just to let u know. Any ideas ? Thanks
(edited 12 years ago)
Original post by Charan_singh
I have a different problem; when it is displaying the the max crashes and its number, it always displays the letter a regardless of the input. it counts everything else fine. Also I am using VB just to let u know. Any ideas ? Thanks


Have you fixed this error?
If not, you may have the variable declared as the wrong type.. ie string instead of integer..

Or you may not be changing the count array, ie:

For counter = 1 To 10
If Mid(testrun, counter, 1) = "a" Then
count(1) = count(1) + 1
ElseIf Mid(testrun, counter, 1) = "b" Then
count(2) = count(2) + 1
ElseIf Mid(testrun, counter, 1) = "c" Then
count(3) = count(3) + 1
ElseIf Mid(testrun, counter, 1) = "d" Then
count(4) = count(4) + 1
ElseIf Mid(testrun, counter, 1) = "e" Then
count(5) = count(5) + 1
ElseIf Mid(testrun, counter, 1) = "f" Then
count(6) = count(6) + 1
End If
Next


OR ( :smile: ) when displaying the results, you may have forgotten to change the counter there?


ListBox1.Items.Add("a" & vbTab & vbTab & count(1))
ListBox1.Items.Add("b" & vbTab & vbTab & count(2))
ListBox1.Items.Add("c" & vbTab & vbTab & count(3))
ListBox1.Items.Add("d" & vbTab & vbTab & count(4))
ListBox1.Items.Add("e" & vbTab & vbTab & count(5))
ListBox1.Items.Add("f" & vbTab & vbTab & count(6))
(edited 12 years ago)
I have the counter sub routine sorted for mine, im using visual basic. Unfortunately, i don't think i have the initial validation routine correct.
I have the "Len(level_crashes)" thing fine but im unsure on how to limit the letters that are allowed to be entered to be between a-f.

thought about using "instr" but not sure?
Anyone able to help?
Cheers.
Original post by Davidoff1401
thought about using "instr" but not sure?

Seems a reasonable solution. Could have a string containing the letters "ghijk...xyz", iterate over it and use InStr to check that none of them are in the target string. Another solution would be to convert it to its integral ASCII representation using Asc and then do a straight integer comparison to check that it's inside the sensible range (you can use UCase/LCase to ensure you only have one such range). Bonus points if you can mention why this isn't a good idea.

EDIT: Just to be clear, both of these have problems which need to be at least considered.
(edited 12 years ago)
anyone know how to do the 3rd part (find max). I tried using an array and the counting occurrences algorithm. For the array I used a READ statement and the DATA was the counters for part 2. However, it doesn't seem to recognise the counters as number variables. Any tips?
Original post by GiantFrozenPenguin
anyone know how to do the 3rd part (find max). I tried using an array and the counting occurrences algorithm. For the array I used a READ statement and the DATA was the counters for part 2. However, it doesn't seem to recognise the counters as number variables. Any tips?


Can you explain what you're doing a bit more clearly? I don't know the task, but would be happy to help. :smile:
Reply 15
Java:

if(entryString.length() > MIN_STRING_LENGTH)
return;

int[] characterOccurences = new int[6];

for(char c: string.toCharArray())
{
if((int)c < ASCII_z && (int)c> ASCII_a) // casting will give ascii value
characterOccurences[c - ASCII_a]++; //- ASCII_a to offset from ascii to array index
else
return;}

someone give a link to the questions please
Sigh. I really don't think the best way of helping people is the wholesale posting of code. (Not getting at the previous poster in particular. It's something that happens a lot in these threads.) It's morally ambiguous, but the real problem is that it doesn't teach anything. For anyone who actually wants to make progress, questioning their approach and explaining yours is much more helpful.
Reply 17
Original post by TheUnbeliever
,


Generally I would agree with what you are saying but considering the complexity of that task and the time original poster posted the thread I don't think it's a real issue. Also giving examples of better code which is self explanatory is a good way of teaching.
Original post by dkdeath
Generally I would agree with what you are saying but considering the complexity of that task and the time original poster posted the thread I don't think it's a real issue. Also giving examples of better code which is self explanatory is a good way of teaching.


Fair enough :smile: Although, the original poster wasn't the one asking, and the final deadline for this task is months off. Also, I agree that this problem is sufficiently simple that the code is self-explanatory in what it's doing, I find that understanding what they're doing wrongly is useful. (For example: "it doesn't seem to recognise the counters as number variables" is not a technical description of any problem. Perhaps the poster doesn't really understand types?)
Reply 19
Still confused on how one would go about extracting each letter then verifying that it is between "a" and "f". I'm assuming I should just extract each letter by Mid$ then converting it to ASCII by using Asc function (?). Using Visual Basic if that is any help.

Quick Reply

Latest

Trending

Trending