Building a solution - CCEAData types

Building a solution involves coding in an appropriate high level language, choosing an appropriate Integrated Development Environment (IDE), testing and documenting its development.

Part ofDigital Technology (CCEA)Digital development practice (programming)

Data types

Your technical documentation should also demonstrate your understanding of data types and how you used them in your solution. You should consider the following data types:

  • numeric
  • character
  • string
  • Boolean
  • date/time

User Requirement 2.1: A main menu will greet the user with a personalised message and ask what level they want to be tested at – Easy, Medium, Hard.

Python implementation

20 def menuSelection():
21 '''a function to present the menu to the user'''
22 print('Please select the level of difficulty from the menu Below:')
23 print('1. Easy')
24 print('2. Medium')
25 print('3. Hard')
26 choice = int(input())
27 return choice

The menuSelection function (line 20) has been developed to allow the user to input a number. By default, Python will this as a data type, therefore the function was expanded to cast the variable to an (line 26). The function can now be developed to return the integer which can be used later in the program.

Developmental testing

Please select the level of difficulty from the menu below:
1. Easy
2. Medium
3. Hard
1
1
Press any key to continue . . .

C# implementation

static int showTheMenu()
{ Console.WriteLine("Please select a difficulty level from the menu below:"); Console.WriteLine("1 - Easy"); Console.WriteLine("2 - Medium"); Console.WriteLine("3 - Hard"); int choice = Convert.ToInt32(Console.ReadLine()); return choice;
}

This function shows the menu and collects the user’s choice of difficulty level.

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.WriteLine("*****DIFFICULTY*****"); int level = showTheMenu(); Console.WriteLine("Level chosen = " + level);
}

Additional code is added to the main method to call the showTheMenu() function.

This is the behaviour of the whole program at this stage:

Enter a name: Jude
Jude >> Accepted
*****DIFFICULTY*****
Please select the difficulty level from the menu below:
1 - Easy
2 - Medium
3 - Hard
2
Level chosen = 2
Press any key to continue . . .