Problem-solving & design
Computers are designed to perform tasks and solve problems. How it goes about doing these tasks is up to way the system is designed, and the programmer develops the product. Different problems can require different types of computer hardware, software, and peripherals. For example, a system which tracks purchases at a grocery store will require a much different setup than a personal gaming computer.
Pick any two of the three scenarios below, and write down in your notes your answers to the following questions about the computer systems they will need.
- What hardware will be needed?
- Who will operate the system?
- What issues might occur?
Fast food restaurant
Top down design
When designing a new system, one method is to start with the big idea and work your way down. In order to visualize this approach it’s often best to use something like structure charts, shown in the following example of a mobile phone system. Notice how it goes from the full system, and then into the three distinct areas that a phone will deal with. At each level of the chart the elements of the system become more detailed, or more specific. There are many benefits to top down design, including the ability allow a few individuals to quickly control the direction the project is taking. The opposite of top down design is bottom up, which is something you should be aware of, but not something that you’ll necessarily be tested on.
Written task: Structure charts
In this task you will create a structure diagram in your notes. Select one of the following systems (apps) and then create a chart with a minimum of 12 elements.
- Home security system
- Cleaning the living room
- Planting a garden
- Phone messenger app
Flowcharts provide a visual representation of an algorithm. Before you can really understand flowcharts, it’s important that you understand what an algorithm is, which you can do by watching the video below.
Practical activity: Algorithms
In this activity you will create two algorithms. The first involves something you do every day, like tying your shoes. In this case you might say something like, “Check if shoes on, if not then check for socks. If not, then put on left sock first.” The second algorithm you will do involves a computer science related task. Each of the algorithms should be multiple steps and be in your notes.
Task 1: Write an algorithm for an every day task.
Task 2: Write an algorithm for open a file and reading out all the lines one by one. You cannot refer to Python code in doing so.
There are many ways to represent algorithms, and flowcharts are one them. While you’re likely familiar with what a flowchart is, in computer science there is a specific way to write them. Each symbol in a flowchart has a special meaning, and these meanings match up with the underlying programming concepts of a process(assignment or calculation), input/output, conditional, functions (procedures) and other things such as databases. You will be responsible for knowing the following symbols:
Algorithms can be written as flowcharts and programs, and on you’ll need to know how to go back and forth between the two.
Practical activity: Flowcharts
In this activity you will convert the above flowcharts into Python programs. Be aware that they get more difficult as you go from left to right. If you can’t read it, just click on the image to see the full size.
Task 1: In the first flowchart you will get user input and provide an output indicating if a person can afford to live alone or not.
Task 2: In this second task you may notice that the symbols in the flowcharts are slightly different than those in the graphic. You will find these sorts of differences as you look at flowcharts online. In this flowchart you will convert temperatures from Fahrenheit to Celsius.
Task 3: This is perhaps the most difficult, and requires you to determine if a number is prime or not. As a hint, just assign a variable to be a number instead of inputting a new number each time.
The best way to determine if an algorithm is working as it should is by testing it. In the real world testing software usually comes with test cases, or a series of instructions that produce some result. Below is an example of a test case that been conducted to determine the login system is working correctly.
Notice that the test case contains the action the tester takes, what data to use and then expected vs. actual outcome. In this case the test failed and a bug (or error in the program) was detected. This sort of testing is done by testers whose job it is in the company to find bugs within the code and report them to the developers who fix them.
Another sort of testing, often done by those developers themselves, involves looking at the code and running it to find issues. Usually a developer will just run part of the code, or even just a single function to check if it’s doing what it’s supposed to.
Practical activity: Testing
In each of these tasks you will be given a function to test. For each function you will be told its purpose, after which you will come up with 4 test cases. For example, if I give you a function called InchesToCentimenters which takes a floating point value representing inches and returns the same value in centimeters, your test cases might look like the following:
If you then call the function with each of those inputs and get the expected output, then you can assume the program is working as expected. With the tasks below you need to create a table similar to the one above and give your input and expected output. Do this before you run the program. Then run the program and see if your expectations match the results.
Task 1: In this program a simple function is used to calculate how much to pay someone after they have paid 20% tax on their wage. So if a person works 10 hours for 200 NT per hour they should get 2000 NT before taxes. After 20% tax they will get $1600. Pick your own values, run the program and see if it produces the expected output.
Task 2: This program is a tester for prime numbers. You put in the starting and end number and then it will give you a list of all the primes between the two.
Validation & verification
When dealing with data that is put into a system there are two ways to check that everything is reasonable and accurate called validation and verification. Validation is used to determine if the data being entered in reasonable, while verification is used to check that data doesn’t change when it’s entered.
Book activity: Validation
See your book: pages 121 – 124 for examples of these. Take notes on the general ideas of discussed in class and then complete the activities 9.9, 9,10, 9.11 and 9.13 in your notes.
Trace tables are a way to follow the flow of a program while showing the values of the variables involved. It can help with debugging software, allowing programmers to create better software. These tables are often created through something called a dry run, which is to say that it uses pen and paper. Below is an example of a trace table being filled out by going through a Python program.
There are a few important things to notice about trace table above.
- It lists all the variables in the program
- It shows the output
- The blanks spaces are assumed to the last value in that column. If no value is assigned then the variable hasn’t been initialized.
- It shows the line number (this is optional)
Practice task: Trace tables
To practice using trace tables complete the following two tasks in your notes.
Task 1: On this web page you will find two programs written in pseudocode. You need to convert these into Python programs and then create trace tables showing the values at each step.
Task 2: In your book you should complete the activities 9.14, 9.15 and 9.16 in your notes. After you’ve done 9.16, change your Python code so that it works for all possible numbers.