- [Craig] In this video, we take a look at the importance of being able to identify inputs, processes and outputs to a problem.
(uplifting piano jingle)
We already established right back in our very first video,
the computer program is nothing more than an electronic device which takes input, processes data and delivers output.
You might remember this simple example.
For example, a computer could take in the number 5, it could perform the calculation multiply by 2,
and supply the output 10.
And of course, no matter what you're thinking about, computers basically follow the same process.
The input could be that supplied by a games controller, the actual console itself would process all of this data
and the output would be in the form of a change on the screen, sound through the speakers and maybe vibration feedback.
Essentially, a computer program - or more importantly, an algorithm - is the same.
And in terms of writing a computer program, you need to also be able to identify its inputs, processes and outputs.
Under exam conditions, these problems will usually be presented in the form of a scenario,
so let's take a look at a couple now.
So here, we have a fairly simple scenario.
Write a program to calculate the volume of a fish tank based on its dimensions and report the result to the user.
So, if we want to work out the volume of the fish tank,
then the inputs will need to be the length, the height and the depth,
and these could be supplied in centimetres or fractions of a metre,
so we need to store these in a data type which allows numbers with a decimal point, so a real or float.
Once that data has been input, we then move on to process.
So, we need to do something with those three variables.
Well, to work out the volume, we do length times height times depth.
And of course, there's no point in inputting that information and processing it with a calculation unless we then output the result,
and the output would be another variable called volume which again could have a fractional or decimal component,
so it would be stored in a real or float.
Let's look at another scenario.
Write a program which will ask the user for the number of students in their class
and then prompt them to enter each of their test scores in a range 0 to 100.
It should then output the highest, lowest and average score to the user.
Now, why don't you pause this video for a second and see if you can sketch out on a piece of paper
the inputs, processes and outputs that would be needed for this program?
Okay, so how did you do?
Obviously, they're going to need to input the number of students,
so if there's five students, we need to be asking for five test scores,
so that number needs to be input.
We also need to be inputting the current score, so we're going to ask x number of times for a score,
and each time that goes in, we need to store that in a current score.
There's various processes required here.
We know we're going to need to work out a total score, so we're gonna need to be performing a calculation.
Total score equals the current total score plus the new current score.
Once all scores are entered, we've been told we're going to need to output an average score,
so one of the processes will need to be average score equals the total score
divided by the number of students, which was entered earlier.
We probably need to store lists of scores in an array or a list,
and we need to loop through them or use some other function available in our programming language to return the min and the max scores.
And of course, having processed all this information, the program's being required to output
so we need to output min score, output max score, and also output the average score.
So as a recap, when tackling a problem, you need to think carefully about all the inputs, processes and outputs for that problem.
Inputs are anything which need to be supplied to the program so it can meet its goals.
These are often input by the user,
and you should consider an appropriate variable name and a data type for the input to be stored in.
Processes, you should be considering what calculations need to be performed while the program is running.
Does the data need to change formats or data types?
And finally, outputs.
Consider what your program needs to output, consider what form this output needs to take,
and consider an appropriate variable name and data type for any output if it needs to be stored.
(uplifting piano jingle)