Question about the Higher paper from last week

  • Alan McGregor
    Participant

    So I’ve been working through the paper from last week, as students have been asking about it. I am drawing a blank at Question 14(b) – scan is uploaded here – http://i59.tinypic.com/2exr4ec.jpg

    For 5 marks, candidates have to write an algorithm which validates that a phone number on a web form is a string of 11 digits. They can use pseudocode or a programming language of their choice. The length of 11 would be easy enough to validate but I’m struggling with the 0-9 part.

    I googled the javascript for it and got the following:

    function phonenumber(inputtxt)
    {
    var phoneno = /^d{11}$/;
    if((inputtxt.value.match(phoneno))
    {
    return true;
    }
    else
    {
    alert(“message”);
    return false;
    }
    }

    I can’t imagine that anyone memorised this, and if they did then it seems like an easy 5 marks to regurgitate! Pseudocode-wise I have had a look through the Higher specification and don’t see anything about comparing data types. Are candidates supposed to loop through each character and check that each is within the ASCII range for 0-9?

    Any thoughts would be welcomed. Curious to see what the SQA solution says to this one.

    DCullen
    Participant

    My class was still doing the old higher this year and the link is blocked for me so I’m just suggesting a possible solution from what you have written using substring extraction in VB…

    Edit (the code is not displaying properly for me and doesn’t seem to be showing If Mid$(number, counter, 1) < "0"
    Or Mid$(number, counter, 1) > “9” Then line properly)

    Dim number As String
    Dim valid As Boolean = True

    number = InputBox(“Enter an 11 digit phone number”)

    If Len(number) = 11 Then
    For counter = 1 To 10
    If Mid$(number, counter, 1) < "0" Or Mid$(number, counter, 1) > “9” Then
    valid = False
    End If
    Next
    Else
    valid = False
    End If

    If valid = True Then
    MsgBox(“Phone number valid”)
    Else
    MsgBox(“Phone number invalid”)
    End If

    Alan McGregor
    Participant

    Yes I was thinking of something along these lines but would <"0" or >“9” actually work with strings? Cheers for the reply.

    DCullen
    Participant

    Yes in VB “9” works. I just tested it.

    Lee Murray
    Participant

    In some languages it’s easy to do if you are testing it as you go. In other languages it’s much more difficult.

    For example, in Python you could do:

    userInput = input(“Enter a number: “)
    lenCheck = True
    numCheck = True

    if len(userInput) != 11:
    lenCheck = False

    for letter in userInput:
    if not letter.isdigit():
    numCheck = False

    if not numCheck:
    print(“There were non-numerical digits entered”)
    elif not lenCheck:
    print(“The length of a phonenumber must be 11 digits”)
    else:
    print(“Thank you”)

    (I’m guessing the indents won’t print properly, but you can get the idea).

    I think it’s far too difficult a question for pupils to write out the answer. If they were given a computer and Internet access, that would be fair.

    Even marking this question would be an utter nightmare. Your sample JavaScript answer may well be perfect, but I can’t tell just by looking at it (I’m not a JS expert). Will all markers be versed in all languages and be able to tell if someone has sufficiently validated the input?

    Like you, I can’t wait to see the solution. I can’t envisage there being a ‘one size fits all’ answer that pupils could genuinely be expected to provide. Then again, I’m often wrong 🙂

    Scott McBride
    Participant

    In VB you can simply check if the value is >= “0” and <= "9". Given that you would sensible to use pseudocode then you can simply describe what you are doing rather than coding it......

    Peter Thoresen
    Participant

    Pupils are not asked to write code – they have to create any kind pseudocode that shows the steps. No need to get bogged down with exactly how to check if a character, or anything else

    My solution:

    valid=true

    if length of pn is not 11 then
    valid = false
    else
    for every character of pn
    if character is not 0..9 then
    valid = false
    end if
    next character
    end if

    if valid=True then
    send “Valid” to display
    else
    send “Not valid” to display
    end if

    Alan McGregor
    Participant

    Yep that makes sense to me, but I wonder how many marks candidates will score for this question. Would have been much easier if they’d gone with the example from the old Higher coursework from last year, ie must be 11 characters long and begin with a “0”. My reading of this is that it confuses the data types unnecessarily. A 5-marker as well…

    pdoleman
    Participant

    Hi
    I realise it has been quite some time since the exam, but I’ve only just seen the paper. Question 4 on declarative language goes far beyond what I expected to teach. Has there been any guidance to let us know the depth of knowledge for different types of language?

    Enrico Vanni
    Participant

    There has been no guidance. The advice given when someone asked this in relation to the negative numbers question (and no specific mention of two’s complement in the course guide) was to teach to the level of the old Higher, which is a ludicrous solution, especially for topics that are covered in depth in the old optional units (should the topic be taught to mandatory or optional unit level if it is mentioned in both?), case in point being declarative languages mentioned briefly in old Software Development and in detail in old Artifical Intelligence. This is going to continue to be a problem going forward until clarification is given.

    jpaterson
    Participant

    And there will be no clarification. We have repeatedly SQA asked about depth of treatment and have been sent the same standard reply no matter how detailed the question or who it came from, so I wouldn’t hold your breath.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.