Algorithms and programming. Laboratory works

During the course, each student should create and present 4 laboratory works (A,B,C,D) – 4 tasks solved by computer programs.

During presentation of each program, the following items should be demonstrated:

·         commented text of the program (see description below) – first two tasks both in C++ and JavaScript, the second two – only C++,

·         prepared test plan and testing results,

·         executed program (see „Limitations and required input data validation” below).

 

Execution of the program repeatedly (only C++)

The program should be created in the way, the task (with potentially different inputs) is solved repeatedly, without quitting the program (so without need to rerun the program). E.g., for the program which calculates square root of the input, the execution would look like:

Input number:

9

Square root is 3

Continue (1) or quit (0)?

1

Input number:

2

Square root 1.414

Continue (1) or quit (0)?

0

The following example demonstrates, how to reach this in a simple manner by adding just 6 lines:

int ok;

do

{

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

    *** Part of the program

    *** to be repeated

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

    cout << " Continue (1) or quit (0)?" << endl;

    cin >> ok;

} while (ok == 1);

 

Test plan and results

A typical form of a test plan is a table with two columns with input data in the first column and response (output data or error message) in the second column. Test cases (lines in the test plan) should represent all logical regions of input data (e.g., for calculating square roots, test plan should include at least both negative input (for which an error message should be displayed) and positive input with “normal” output). A simple example of a test plan (Calculating square root of an integer):

Input

Desired response

9

3

2

1.414

0

0

-5

Error. No square root of a negative number

A test plan:

·         is a document, which contains the desired response of the program to the input data,

·         shouldn’t reflect peculiarities of the user interface.

In addition to the test plan, also test results should be provided to acknowledge the program conforms to the requirements expressed by the test plan. Test results can be presented in two ways:

·         as the 3rd  (and, probably, the 4th, if also for JavaScript) column stacked to the right of the test plan (see example below),

·         simply as a statement that the program conforms to the test plan.

An example of test plan and test results:

Input

Desired response

Results C++

9

3

+

2

1.414

+

0

0

+

-5

Error. No square root of a negative number

error message „negative number”

Test plan and test results to a great extent reflects the author’s contribution of quality testing of the program

Test plan and results can be submitted in any of the following forms:

·         a separate file (text, Word, Excel etc.),

·         hand-written or printed,

·         in a special commented block within the source code (preferably, in the end).

 

Commenting source code

Source code of a program should be well commented, i.e., it should contain at least general descriptions of the main conceptual blocks of the program and the information to understand the idea of an algorithm. Comments should be formed according the approach “what”, not the approach “how” (because this is already described by the source code itself), i.e., comments should be at least one abstraction level higher than source code.

E.g., this is a bad comment (not simply excessive, but even hazardous, because information duplication contradicts a good programming style):

a = 5; // number 5 is assigned to variable a

 

This could be good (however, of course, it depends from the context; comments shouldn’t be too detailed):

a = 5; // start with element #5

       // because first 4 elements are filled automatically

 

In the beginning of the program you should have a general comment about the program containing at least the following information:

·         Author’s name, student ID number.

·         Task number and text.

·         Date of solution.

E.g.,

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

John Nettles, jn99999

A99. Create a program which calculates square root of an integer number. Output is floating point number.

Program created: 2018/10/12

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

 

Topics for the tasks

·         A – branching and looping,

·         B – looping and functions,

·         C – arrays and functions,

·         D – object-oriented programming.

 

Limitations and required input data validation

If the presented program contains errors, the errors should be corrected and the program presented again.

Getting incorrect input data, the program should output a corresponding message.

Specification. For integer input (as defined in task description) it is not required to check whether something else then integer is input. So, the input data should be validated against logically unacceptable values (such as division by 0, square root of a negative number) within the fixed data type.

Built-in functions are allowed to use unless they degrade the essence of the task (e.g., it is not allowed to reduce the task to solve to a call of an existing function not created by the author).

Grading

Nominal grade for a task is 100%. If a program is not commented, up to 10% can be reduced. Repeated presentation of program can result with up to 20% reduction.

 Receiving tasks and presenting solutions

·         Tasks are individually sent for each student by the teacher.

·         Each task has different deadline for the solution:

1.      A – week 8 (C++, JavaScript)

2.      B – week 10 (C++, JavaScript)

3.      C – week 12 (C++)

4.      D – week 14 (C++)

If deadline is broken, the grade is reduced for up to 10% for every week after the deadline (the grade won’t fall below 40%)