42
M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Embed Size (px)

Citation preview

Page 1: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

M150: Data, Computing and information

Outline

1.Unit ten.

2.What’s next.

3.Review questions.

4.Your questions.

1

Page 2: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Software development

Software development in context. What do you require of your software. Designing your software. Detailing your designs, implementing your software. Testing your software. Debugging your software.

2

Page 3: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Software development in context

Other than writing the code, what is really required to create a finished software product?

Software development consists of many stages, and relies on a team effort.

Each team member is specialized in a specific stage.

Writing the code is one stage of software development.

A programmer is the person whose main responsibility is to write the code.

3

Page 4: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Software development in context

Software projects are big and complex and are supposed to meet the following requirements:

Interaction with other complex systems (ex: banking systems).

Support for a large number of simultaneous users (ex: mobile phone network).

Response to critical safety conditions.

Running continuously for months or years at a time (ex: a system for maintaining a power station).

4

Page 5: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?

Every software project needs to start with proper planning:

Who is our client?

What is the problem/need in question?

What is the requirement expected by the software?

To how many tasks the program needs to be divided?

Are there any repetitive parts in the program?

Who are the end users of the software?

How will the software interface look from the user side?

Where can things go wrong?5

Page 6: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?

We wish to develop a software called the OCAS (Overall Continuous Assessment Score) program.

What are the questions that we need to think about?

6

Page 7: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?

What is meant by OCAS?

A student’s final grade on a course depends on his continuous assessment marks (TMAs).

It is the average of the student’s TMA marks.

7

Page 8: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?

How do we calculate this average?

If all the TMAs are equally weighted, then the average of their grades will be the sum of their marks divided by their number.

On certain courses, not all TMAs contribute to the same percentage of the final grade, they are differently weighted, the percentage of their contribution is called weighting factor.

The weighted average (WA) for example for 4 TMAs is calculated using the following equation:

The general equation, with n being the number of TMAs is the following:

8

1

100

n

i ii

mark wf

WA

1 1 2 2 3 3 4 4

100

mark wf mark wf mark wf mark wfWA

Page 9: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?

How will the program ask the user to enter his TMA grades and return their average?

Does the OCAS program only work for M150 student users?

Do we need to use 2 different formulas depending if the TMAs are equally weighted or not?

What would happen if the student enters an invalid data as a TMA mark (ex: a string of characters or a negative number)?

What would happen if the student enters all 0 TMA scores?

How will the average be displayed, as a whole number, or with one decimal place, etc..?

9

Page 10: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software? A program specification is a document describing what the program does, so for our OCAS program it is as follows:

The assessment is based on at least 2 TMA marks and at most 8.

The TMAs may be differently weighted, but the weighting factor must be a whole number.

All summative TMAs must be included in the calculation even if the score is 0.

If the TMAs are equally weighted:

OCAS = (sum of all TMA scores)/(number of TMAs)

If the TMAs have different weights:

Contribution of each TMA = (TMA score x weighting factor of that TMA) / 100

OCAS = sum of contibutions 10

Page 11: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software? From the programming side:

The user will first be asked, using a dialogue box, for the number of TMAs on their course.

This input will be checked and if it is not a whole number in the range of 2 to 8 the user will repeatedly be asked to re-enter, until the input is of the correct form.

The user will then be presented with a series of dialogue boxes, in which they are asked to enter their TMA scores, one at a time.

If any entry is not a whole number from 0 to 100 the user will be repeatedly asked to re-enter, until the input is of the correct form.

No other checks on the validity of the TMA scores will be carried out: for example, a series of zeros will be accepted without query.

11

Page 12: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : What do you require of your software?The user will then be asked whether all TMAs are equally weighted.

If they are, the program will calculate the OCAS as a straight average.

If not, the user will be presented with a second series of dialogue boxes, in which they will be asked to enter the weightings for each TMA.

If any entry is not a whole number from 1 to 99 the user will be repeatedly asked to reenter, until the input is of the correct form.

A check will then be made that the weightings entered add up to 100. If not, the user will be asked to reenter all the weightings.

The program will then calculate the OCAS score, using the appropriate formula.

Finally, the program will display the OCAS, to two decimal places, in a dialogue box. 12

Page 13: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your softwareWhile designing a software, we create descriptions of it using diagrams and flow charts.

We follow a top-down approach when dealing with the problem, from its most general aspect to the smallest detail.

Partition the software in a modular way, using function libraries.

Think in terms of a main part that is small and simple and controls the execution of the modules.

The overall structure is referred to as preliminary design.

13

Page 14: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software Using structured English, “a” pseudo-code for our OCAS program is the following:

We said “a” pseudo-code and not “the” pseudo-code since each one of us has his own logical string of ideas.

14

Page 15: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software First step of our program is to get the user to enter the number of TMAs.

This number should be checked for validity, if it is within a required range.

We will be dealing also with TMA scores and weighting factors that need to be checked if within range.

It makes sense to write a function to do so.

15

Page 16: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software Specification for such a function will be as follows:

function getValidNumber(dataNeeded,startOfRange,endOfRange) /*************************************************************/ /* Function obtains a number in specified range from the user */ /* The function takes three arguments: */ /* dataNeeded – a string used to specify what the user should */ /* enter */ /* startOfRange – a whole number which specifies the */ /* lowest valid number in the range */ /* endOfRange – a whole number which specifies the highest */ /* valid number in the range */ /* Function returns a valid number in the range */ /************************************************************/

16

Page 17: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software The second step consists of asking the user for the TMA scores.

These scores need to be checked for validity.

It makes sense if the user has more than 1 TMA score, to store them in an array rather than individually declared variables.

A function is needed to do so.

17

Page 18: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software Specification for such a function will be as follows:

function getTmaScores(aNumber)/*************************************************************/ /* Function gets a set of valid TMA scores from the user */ /* The function has a single argument: */ /* aNumber– the number of TMAs on the course *//* The function returns an array containing the scores */ /*************************************************************/

18

Page 19: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software Next we need to Find out if TMAs are equally weighted.

This is a simple task which needs no refinement, done with an if/else statement.

The response from the user will be stored for subsequent testing.

19

Page 20: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software Calculating the OCAS differs if it is a weighted average or a regular average.

Already decided to store the TMA scores in an array.

The array is passed as a parameter to a function to calculate the average.

20

Page 21: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software The specification for a function that calculates the regular average will be as follows:

function calculateAverage(anArray)/*************************************************************//* Function calculates the average of the values in a *//* non-empty numeric array, correct to two decimal places *//* Function takes a single argument: *//* anArray – the array containing the values *//* Function returns the average of the values in the array */

/*************************************************************/

21

Page 22: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software In order to calculate the weighted average, we first need to know the weighting factor of each TMA, it makes sense to store them in an array

function getWeightingFactors(aNumber)/*************************************************************//* Function gets a set of valid weighting factors (in the range *//* 1 to 99, with a sum of 100) from the user. *//* The function has a single argument: *//* aNumber– the number of TMAs on the course *//* The function returns an array containing the weighting *//* factors. *//*************************************************************/

22

Page 23: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software The specification for a function that calculates the weighted average that needs both arrays the score values and the weighting factors will be as follows:

function calculateWeightedAverage(valueArray,weightingArray)/*************************************************************//* Function calculates the weighted average of the values *//* in a numeric array, using the weighting factors provided *//* in a second array. *//* Function takes two arguments: *//* valueArray– the array containing the values *//* weightingArray– a parallel array containing the *//* corresponding weighting factors *//* Function returns the weighted average of the values in *//* the array, correct to two decimal places. *//*************************************************************/

23

Page 24: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Designing your software The line-to-line translation of our pseudo-code will look something like this:

var numberOfTmas; // number of TMAs on the coursevar ocas; // the OCAS (overall continuous assessment score)var tmasEquallyWeighted; // whether TMAs are equally weightedvar tmaScores; // an array holding the TMAsvar weightingFactors; // array holding weighting factors for TMAs// get number of TMAs in the range 2 to 8numberOfTmas = getValidNumber('Enter number of TMAs on your course', 2, 8); // get array of valid TMA scorestmaScores = getTmaScores(numberOfTmas);// find out if TMAs are equally weighted – default value of 'y'tmasEquallyWeighted = window.prompt('Are the TMAs on your course equally weighted? Enter y or n', 'y'); //default value of 'y'// calculate ocas using appropriate formulaif (tmasEquallyWeighted == 'y'){ocas = calculateAverage(tmaScores)}else{weightingFactors = getWeightingFactors(numberOfTmas);ocas = calculateWeightedAverage(tmaScores, weightingFactors);};window.confirm('OCAS (overall continuous assessment score) is: ' + ocas); // display final OCAS score

24

Page 25: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Detailing your designs, implementing your software The code for our first function getValidNumber is the following:

25

Page 26: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Detailing your designs, implementing your software

The code for our second function getTmaScores is the following:

26

Page 27: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Detailing your designs, implementing your software

For our third function calculateAverage that evaluates the regular average, we need to add up all the elements of the score array and then divide it by the number of scores, so we need a summing function called sumElements:

27

Page 28: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Detailing your designs, implementing your software

The sumElements function will be called from inside the calculateAverage function like so:

28

Page 29: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Detailing your designs, implementing your software

The other function that calculates the weighted average will be as follows:

29

Page 30: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Putting it all together

The functions that we wrote will be called from a main code.

These functions follow a certain hierarchy as shown in the figure below:

30

Page 31: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Putting it all together

After writing your program and before delivering it to the user, you will need to provide an instructions manual with it called user documentation.

A programmer documentation helps the people who will take care of the maintenance of the program, and even yourself to remember specific details in the code.

A project documentation or project log should include description of any part of the development process for future reference, why certain choices were maid other than others.

31

Page 32: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Testing your software A program accepted by the compiler or interpreter may however not do what it is required from it and not give the wanted result.

Such a program contains several errors that won’t be discovered unless the program is thoroughly tested.

Checking the functioning of a program requires making sure that separately each function or module is working properly.

Afterwards we still need to check if the program as a whole behaves appropriately, if the functions are called and used appropriately, tests that check that are called integration tests.

We need to be careful that correcting one error may result in other errors in parts of the code, keeping track of the modifications, encountered errors, and corrections is advised, this process is called regression testing.

32

Page 33: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Testing your software The first test is a visual test to walk through the written code and logically work out its behavior at each input.

Another type of test is the black box testing without looking at the code trying to figure out by testing a large number of input values and observing the output.

The white box testing involves looking at the details of the program code and devising tests that will exercise each possible path through the program, paying particular attention to those parts that are likely to be susceptible to errors.

In order to test the behavior of functions we can write down a small code that will test the function repeatedly with different arguments, such a code is called a test harness for the function.

An extreme value is a valid input according to the program specifications but in some respects it is a special case, causing the program to deviate from its general behavior (ex: an empty string given to a program that accepts string input, or a very large number given to a program that performs arithmetic calculation on numbers.

For numerical inputs, a boundary value occurs at the ends of ranges of numbers, where a program is specified to behave in a certain way for a given range of numbers, this behavior is usually coded using comparisons operators such as <, <=, >, >=. 33

Page 34: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Debugging your software When writing a program, two aspects need to be taken into consideration:

The syntax aspect, the rules of the programming language you are using.

The semantic aspect, the meaning of each statement, how will the compiler/interpreter understand it.

34

Page 35: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Types of errors There are three types of errors:

The common syntax errors such as forgetting the quotations when declaring a string, placing unequal parenthesis, forgetting a semicolon, etc…

The semantic errors such as misspelling identifiers, dividing by 0, trying to access an index that doesn’t exist, etc…

The logical errors such as using the wrong comparison operator, or writing a while loop that never ends, etc…

35

Page 36: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Types of errors In compiled languages (which JavaScript is not), the first task of the compiler is to check through the whole program for syntax errors.

It is only once these have been eliminated that the compiler attempts to translate the source code into machine code, at which point it may discover semantic errors.

With an interpreted language such as JavaScript, the distinction is not so clear because each program statement is checked, translated and executed line by line.

36

Page 37: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Activity 7.2 Look at the program code in the files Activity_10.7.2(a), Activity_10.7.2(b), Activity_10.7.2(c) and Activity_10.7.2(d). Where comments are included, assume that they correctly reflect the intention of the programmer. Each program contains a single error. The program will (at least initially) run, but not as required. In each case identify the error; explain why the program behaves as it does; and correct the code.

Try to identify the problems by inspection before running the code. If you run the programs you will find that Activity_10.7.2(d) hangs (i.e. it causes the browser to appear to freeze). In order to stop the program running you may need to close down your browser, so make sure that you don’t have anything important in another browser window before trying this.

37

Page 38: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Tracing variable values A good technique for locating errors is to trace down the variations of variable values at the execution of each line of code.

Another way to trace the values of variables is to display it after each execution, this way you SEE how it is varying.

For example:

38

Page 39: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

Unit ten : Tracing variable values The trace table for the previous examples is:

39

Page 40: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

2- What’s next

Unit eleven : Computing in the wild.

40

Page 41: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

3- Review questions Does a programming project arrive at its end when writing the code is finished? What questions do we need to ask a client who wants a software? What do we call the person who writes the code for a software? What is a pseudo-code? What do we mean by top-down approach? Define the following terms user documentation, programmer documentation, project documentation. What are the testing methods used to find out if a program works properly? Which types of errors can we encounter when writing a code? Name two techniques for efficiently debugging a code.

41

Page 42: M150: Data, Computing and information Outline 1.Unit ten. 2.What’s next. 3.Review questions. 4.Your questions. 1

4- Your questions

?42