Lesson 16: Creating Specifications and Sorting Data
Today we are going to focus on the define bubble...
Look back at your research from last week. Review the research:
Brief Recap
Here is the Given Brief…
“Your school wants you to create a “quiz like” software that allows students to test their knowledge of various topics. The software will need to read information from an external file. This file will contain the questions and answers to each question. The software will then need to display the questions and answers and allow students to pick which answer they think is correct (multiple choice questions with 4 possible answers) . You may choose the theme and stakeholders for the quiz.”
Brief Development
Attributes & Specifications
It’s now time to use your research to help to write the attributes for your project.
Break down the project and consider the following:
- the needs of the user
- the needs of the client
- the resources available to you
- how you make the program work efficiently, etc
- the limitations of the software
What are Attributes?
Before starting to create ideas and concepts a designer uses their knowledge of and understanding of the context, need, stakeholder, etc, to be able to create a list of points that the technological outcome (or program in this case) needs to fulfil to make it successful. Key attributes are the most important needs for the outcome to be successful.
What is a specification?
A specification is the next stage of brief development.
You still create a list of needs and wants but you make sure they are very precise and accurate. They are usually based on background research and knowledge.
They are also used to help test a prototype’s fitness for purpose and it’s ability to fulfil the need.
Your task is to use your brainstorm, research and prior programming knowledge to write your own attributes and/or specifications for the given brief and need.
Think carefully about about the users needs and the requirements of the client.
How could you test the final prototype to make sure it is fit for purpose? Which attributes and specifications are KEY? Why?
Sorting Arrays
How to use an Array - Recap
To store information into an array, we need to provide an index. This acts as a position in our array/list.
Note: Arrays always start at an index of 0. This represents the 1st element in the array.
“Toby” is the 1st element in the array, even though the index is ‘0’
To sort data is to organise all elements in a list into an order based on a property. E.g sorting data alphabetically. What are some more ways to sort data?
What are some more examples of programs that do this?
How does a program sort data?
Each program has different methods and properties to sort lists of data by. Such as ordering prices from smallest to largest. But how does a program actually do this?
One method would be to look two elements at a time and determine which element is larger. If the first element is larger than the second element, we swap their positions in the array. (so the smallest element is at the beginning).
Then move onto the elements 2 and 3. Then elements 3 and 4 … etc.
Bubble sort
This method of sorting actually has a name. Bubble sort. “Bubble” because all the large numbers slowly float to the top (end) of the list. Watch the visual demonstration below.
How does this work - pseudocode
do
bool swapped = false
for i = 0 to array.size
if leftElement > rightElement
temp = leftElement
leftElement = rightElement
rightElement = temp
swapped = true
while swapped
The pseudocode can be broken down into the following steps:
- Keep looping until a swap hasn’t occurred (the list is sorted)
- Loop from the start of the list to the end of the list
- Check if element i (left element) is greater than element i + 1 (right element)
- If true, swap the values around
Efficiency of Algorithms
Another aspect of creating algorithms is how efficient these algorithms run. This can be broken down into :
- How complex each operation is
- How many operations there are
- How large is the list of data
To learn more about sorting algorithms and efficiency by watching the video here
You are required to create your own bubble sort algorithm using C# to sort through a list of scores read from an external file. Read the ReadMe file attached to learn more about the exercise.