±«Óătv

Building a solution

Once you have created design plans, you must then implement them and build your solution. This will involve coding in an appropriate . You should choose an appropriate to work in.

Record the devolpment of your solution using screenshots and notes. Explain why you made the choices you did. This documentation should also incorporate developmental testing (tests as you progress).

Technical documentation

Provide annotated evidence of how your system was developed and show the examiners how you carried out developmental testing.

Your technical documentation should show how you used the features of the IDE.

These should include, where appropriate:

  • code editor
  • simple debugging tools
  • compiler
  • error diagnostics
  • run-time environment
  • Graphical User Interface (GUI)

Explain clearly how your program works and how you implemented the plans outlined in your design chapter. Record any errors you encounter and document how they were overcome.

The example below shows how evidence could be generated to support your Controlled Assessment task.

User Requirement 1.1: The solution will include a to capture a user's name as a string, use length and presence checks to validate the name, and return the name variable.

Python implementation

def validateName(name):
    '''A function to validate and return name'''
    if name !='' and len(name)<=20 #presence & length check
            print('Accepted')
            return name
    else:
    	print('Error')
#test runs
validateName('Bob')
validateName('')#a null entry
validateName('BobBobBobBobBobBobBob')#more than 20 characters

The first draft above uses a function called validateName that takes a parameter and checks the length is less than 20 characters and is not null.

>>>>
===============RESTART:
Accepted
Error
Error

Outcomes of the test runs can be seen above. â€Bob’ makes it through the validation function and is accepted, but 'BobBobBobBobBobBobBob' is too long and is not. Neither is an empty input – both generate an error.

Although the code meets the basic requirements, the next stage is to refine the code so it will loop if the name does not meet the validation criteria.

The validateName function was (rewritten) to include a looping structure that would force the user to enter a name that meets the validation rules.

def validateName():
    '''A function to validate and return name'''
    valid = False #flag to start loop
    while not valid:
        name = input('Please enter your name: ')
        if name !='' and len(name)<=20: #presence, length & type check
            print('Accepted')
            valid = True #break the loop
            return name
                
#test runs

name = validateName()
print(name)

Developmental testing

The first input is empty and is not accepted, so the function loops and ignores this input and asks the user to re-enter their name. This continues until a name that meets the validation criteria is entered.

Please enter your name:
Please enter your name:BobBobBobBobBobBobBob               
Please enter your name:Bob
       Accepted
       Bob

C# implementation

static void validateName(String name)
{
	if (name != "" && name.Length >= 20) // presence & length checks
    {
    	Console.WriteLine(name + " >> Accepted");
		return true;
     }
        Console.WriteLine(name + " >> NOT ACCEPTABLE.");
}

The first draft above uses a function called validateName that takes a and checks the length is less than 20 characters and is not null.

Wesley >> Accepted
 >> Unacceptable
Christine >> Accepted
The Right Honourable The Lord Mayor >> Unacceptable

Outcomes of the test runs can be seen above. Although the code meets the basic requirements, the next stage is to refine the code so that it will loop if the name does not meet the validation criteria.

class Program
{
    static void Main(string[] args)
    {
        bool valid = false; // assume the name is invalid
          
        while (!valid)
        {
           Console.Write("Enter a name: ");
           String name = Console.ReadLine(); //read in a name
           valid = validateName(name); //validate it
		   Console.Write("PRESS ENTER TO CONTINUE"); Console.ReadLine();
        }
     }

     static bool validateName(String nameToBeTested)
     {
        if (nameToBeTested != "" && nameToBeTested.Length <= 20) //presence & length checks
          {
            Console.WriteLine(nameToBeTested + " >> Accepted");
            return true;
           }
         Console.WriteLine(nameToBeTested + " >> NOT ACCEPTABLE - try again.");
         return false;
      }
}

The validateName function was converted to return a value signifying the validity of the user’s input. An iterative structure was then introduced into the main method to repeatedly call the validation function, allowing the user to make several attempts.

Developmental testing

Enter a name: Mrs Jacqueline Rose Beaumont
Mrs Jacqueline Rose Beaumont >> NOT ACCEPTABLE - try again.
PRESS ENTER TO CONTINUE
Enter a name: Mrs Jackie Beaumont
Mrs Jackie Beaumont >> Accepted
PRESS ENTER TO CONTINUE