Objective 1 Distinguish between true and false statements concerning the terms in the index for this block, or explain the terms in your own words.
Objective 2 Outline the main stages of the program development process, identifying the input and output for each stage.
SAQ2 Identify the input(s) and outcomes(s) of each stage of the program development process as set out in Section 2.1 and in Figure 2.
| Stage | Input(s) | Output(s) | |
| 1 | Requirement analysis | Problem statement | Feasability report |
| 2 | Task definition | Responses to the feasability report | Functional specification |
| 3 | Program design | Functional specifications as modified by user comments or test outcomes | Detailed specifications (including specification of modules) |
| 4 | Coding | Detailed specifications, as modified through change requests | Program expressed in a computer language |
| 5 | Verification | Coded module or program | Debugged module or program |
| 6 | Validation | Debugged module or program | Tested module or program |
| 7 | Operation and maintenance | Delivered program (including documentation)Bug reports, change requests | Bug fixes |
| 8 | Extension, re-design | Major change requests | New version of program |
| 9 | Documentation | All other inputs above | Listings, reports, manuals etc |
Objective 3 Identify the three main program constructs, and their variants, in their graphical form individually and as parts of more complex flowcharts.
SAQ6 (a) By tracing through the flowchart of Figure 15 (page 23) describe the sequence of program steps after the user selects the module with the intention of changing the number of readings and then succeeds in doing so.
The program first displays a local menu and asks the user to select among alternatives by pressing the corresponding key. When a key is pressed the program tests whether it was the letter 'a' key. If it is, the program displays a new message asking the user to key in a new value for the number of readings (or Esc if no change is to be made). When the new value is entered it is recorded by the program and a confirmation is displayed. The program then asks for any key to be pressed; when the user does so, control returns to the local menu.
(b) What control structures occur in part (a) of the module. And in part (b)?
Fig 15(a) is essentially tow loop (repetition) constructs, with a case (selection) construct serving as the tests and with input/ouput operations as action blocks in sequence constructs. Figure 15(b) is essentially a conditional (selection) construct again with sequence constructs (before and after the test).
Objective 4 Draw simple flowcharts from their written description, and conversely, interpret siomple flowcharts in words.
See SAQs 4 & 5 on page 22.
Objective 5 Identify the components of a programming enviroment and explain the use of software tools in the development of a program.
C programs are often developed in an environment which combines editor, complier, linker and debugging facilities. The editor allows the ssource code to be typed in and edited. The complier converts the source code to a set of computer instructions called the object code and the linker combines object code modules to produce a complete program expressed in the basic processor instructions that can be loaded into main memory and executed.
Objective 6 Understand the relationship between source, object and executable code files and know the conventions for naming them.
SAQ7 Describe the steps required in the procress that will turn the C source file, TESTPROG.C into an executable file. What additional files will be produced and what will they contain?
The C source file TESTPROG.C is complied into basic processor instructions that are stored in a new object-code file called TESTPROG.OBJ. This object-code file is linked to other modules, if there are any. If library modules are used, they are also linked to produce the final executable file, TESTPROG.EXE
Objective 7 Describe the purpose and structure of a C program.
C programs consist of a set of functions, one of which must be called main(). A function consists of its name followed by the code which forms the function enclosed in braces. The body of the code contains a number of statements, each terminated with a semicolon. These statements carry out the required operations.
Objective 8 Use comments effectively in C programs.
The C language is free format, and the statements can be broken up by comments and white space to improve readability.
Objective 9 Understand and use C functions that have arguments and return a value.
SAQ20 Assume that, as well as the wherey() function mentioned above, there is available an additional function called wherex() which returns the current screen-column position. Modify the single C statement: gotoxy(1,wherey()+2); which was introduced above to set a new screen position down two rows andalso across towards the right by two columns from the current position.
gotoxy(wherex()+2, wherey()+2);
Objective 10 Use available library functions in simple C programs.
Objective 11 Understand the reason for and be able to write down prototypes for given C functions
If a function is not defined before it is called, or is not even contained in the same file, then the compiler must be made aware of its existence by the use of a function prototype. This prototype declares the data types of the function's return value as well as the types of arguments.
SAQ23 What is the prototype for the gotoxy() function mentioned in SAQ20?
The prototype required is void gotoxy(int,int);
Objective 12 Declare, initialise and use C integer, character and floating-point variables.
SAQ 9 Which of the following list are vaild identifiers and which are not? What is wrong with the invalid ones? Are the valid ones good choices or might they lead to problems?
(a) TAX RATE Invalid, space is not allowed
(b)1TO10COUNT Invalid, must start with _ or letter
(c) %rate Invalid, must start with _ or letter, and % is not allowed
(d) key_HIT Valid, but mised case can lead to mistakes. Usual to use lower case letters for identifiers.
(e) _hit_flag Valid, but a leading underscore can have a special meaning in some environments.
(f) "go_to_it" Invalid, quotes are not allowed in an identifier
(g) suns_mass Valid
(h) suns_mass2 Valid, but in some C environments it is the same as (g) because only the first 8 characters are significant
SAQ10 A programmer decides to store the number of seconds elapsed from midnight to current time of day as an integer variable of type int, called secs_gone. Why is this data type an unsuitable choice?
The maximum likely value of secs_gone is 60 x 60 x 24 = 86,400. This is too large to store as an int type which has a maximum positive range of +32,767. The variable type long should be used instead.
SAQ11 Write down suitable declarations for the following variables:
(a) a variable to hold the weight of an object - A floating-point type is required here since objects are never exact units of weight. Thus a suitable declaration would be: float object_weight;
(b) a variable to hold the number of times a particular event had occurred - An integer variable is required here, declared as int number_of_events;
(c) a variable to hold the letter C for Celsuis units of F for Fahrenheit units in the display of temperatures - A character data type is needed to store a character, as below: char temp_units;
SAQ12 Why is it essential to intialise the variable temp_c in the program:
float temp_c = 22.0;
temp_f = temp_c * 9.0/5.0 + 32.0;
The variable temp_c must be initialised since its value is used immediately in the calculation to form the equivalent Fahrenheit temperature.
SAQ13 If the TMS reading interval is stored as an integral number of tenths of a second (e.g. a reading interval of 1 minute would be stored as 60 x 10 = 600 tenths of a second) write down a suitable declaration for the gvar_interval variable. The maximum interval is 100 minutes.
If the value is an integral number of tenths of a second, then an int type can be used. 100 minutes is 100 x 60 x 10 = 60 000 tneths of a second, and clearly the reading interval cannot be negative, so an unsigned int can be used, declared as:
unsigned int gvar_interval
Objective 13 Understand scope as applied to C local, global and static variables.
The parts of a program within which a variable is considered declared is called its scope. Variables declared within a function have local scope and are only valid within that function. In addition, unless the variable is declared as being static its value will not be retained between subsequent calls of the function. If a variable is declared outside a function, then that is available for access from within all functions in the program. Such a variable is said to have global scope.
SAQ14 Referring to the temperature conversion program in SAQ12 explain what changes would changes would be necessary to convert the variables temp_f and temp_c into global variables.
The changes required would be that the two declaration statements (the two float statements) are placed before the start of the main() function.
Objective 14 Understand and use casts in a C program.
Sometimes it is necessary within a statement to treat a variable of one data type as another type. In this case a cast can be used to get the compiler to convert the variable's value to the required data type, but only during execution of the statement containing the cast.
SAQ15 Write down the single C statement that will store in a float variable called result the result of adding 3.5 to the value of an integer variable called weight.
The required statement uses a cast as follows:
result = (float) weight + 3.5;
Objective 15 Use the C arithmetic, relational, logical and increment operators.
SAQ16 Work out the value of the integer variable called answer in the following statements:
(a) answer=7/3*4 ................. 8
(b) answer=5*3 ............... 2
(c) answer=2+2/3 ............... 2
(d) answer=((3+6)*5/9=110/4) .................. 4
SAQ17 (a) Are the answers to the following TRUE (value one) or FALSE (value zero) if variable a contains 12 and variable contains 8?
(i) 3>2 TRUE
(ii) 4>=4 TRUE
(ii) a!=b+4 FALSE
(b) What is the value of the variable called answer after the execution of each of the following C statements?
(i) answer = (4>1) TRUE, so 1
(ii) answer = (2==3) + 1 FALSE and 0 + 1 = 1, so 1
(iii) answer = (2>=2) + (-1<1) Both statements are TRUE, so 1 + 1 = 2
SAQ18 State whether the results of the following are TRUE or FALSE where a has the value 3 and b has the value 2
(a) (4>3) && (-1>-2) TRUE
(b) (3==1) || (3!=1) TRUE
(c) (a>b) && (a==(b+1)) && (b!=a) TRUE
SAQ19 What is the variable called result after execution of the following three lines of C code?
int result a=2, b=3;
result = ++a + b--;
result++;
In the second line, value a is incremented then used in the expression, whereas value b is used in the expression then decremented. So the value for this line will be (a = 2+1 = 3) + (b = 3). 3 + 3 = 6.
In the last statement the value of result is incremented to give its final value as 6 + 1 = 7.
Objective 16 Understand and use the C if-else, switch, while, do-while and for constructs.
Objective 17 Declare, initialise and use C data and string arrays.
SAQ31 In the declaration int data[5]={1,3,5,7,9} what is the value of data[3]?
The array element data[3] has the value 7, since the array offset is 3, but the element number is 4, and 7 is the fourth number in the intialisation statement.
SAQ32 Write down a declaration of a five-element integer array called 'numbers[]' of which only the first two elements are initialised with the values 100 and 200.
int numbers[5] = {100,200};
Objective 18 Outline what is meant by object-oriented programming and explain why it was developed.
The object-oriented approach divides the program into a number sections called objects. Each object is self-contained and contains methods (functions) and data. Objects are created as and when they are required in a program by instantiation of a class which contains the definition of the object. An object has a predefined (public) interface to other parts of the program, but the way in which it carries out its tasks is hidden from the outside of the object (a process known as encapsulation).
Object-oriented programming was developed out of a need to be able to create large, robust applications for moderm microprocessor-based computers.
Objective 19 Compare various high-level languages with C in terms of program structure, data types and structures, operations and constructs.
SAQ36 Write down a statement which assigns the result of the subtraction of a variable called b from another variable called a to a third variable called c, for each of the following high-level languages.
(a) C c=a-b; (allows access to the hardware of a computer at a lower level than the other languages)
(b) BASIC 10 LET C=A-B (a simple, easy-to-learn program)
(c) COBOL SUBTRACT B-VALUE FROM A-VALUE GIVING C-VALUE (used for data processing)
(d) FORTRAN C=A-B (used for mathematical calculations)
(e) Pascal c:= a-b (provides a teaching tool for structured programming)
Objective 20 Explain the effect of simple program given in a high-level language which uses statement types introduced in the block.
SAQ35 (a) What is the effect of the following program?
10 LET I = 1
20 IF I>5 THEN 60
30 PRINT I, I*I
40 LET I = I + 1
50 GOTO 20
60 END
For numbers between 1 and 5 the program causes the printing of each number and its square.
(b) How could it be changed to a test-at-exit loop?
By placing the IF... statement just before the GOTO ... statement.
Objective 21 Outline how the C language has been extended to provide an object-oriented programming environment (that is, C++)
C++ uses object-oriented programming structures. Classes are declared using the class keyword, and classes can contain C functions and data declarations that are only valid within the class. A class definition can contain both parts that are accessible from the outside (public) and parts that are not accessible (private). When a program needs to use a class, an object is created which contains the data items a class requires. In C++, classes can be used to create new data types as well as providing a means whereby large programs can be divided into manageable, self-contained sections.
Objective 22 Describe briefly what the Java language is, the background to its development, and how Java helps with the execution of the programs that are downloaded from an external source.
Java is an object-oriented language. It was developed to help with downloading programs from an external source such as the Internet or a computer network. Applets contain small programs which can be downloaded and executed when needed, and they are usually in a pseudo-code which has been compiled from the high-level Java language. As long as the computer has a Java virtual-machine simulator to interpret the file, the applet is a portable and compact way of distributing software across the network.
Objective 23 Given an application or a program requirement, discuss which of the high-level languages introduced would be the most suitable one to be used.
?????