Chapter 3.1 The Functions of Operating Systems 3.

1 (a) The Main Features of Operating Systems

The operating system (OS) must provide and manage hardware resources as well as provide an interface between the user and the machine and between applications software and the machine. The OS must also provide other services such as data security. Originally, if a program needed input, the program would have to contain the code to do this, similarly if output were required. This led to duplication of code so the idea of an OS was born. The OS contained the necessary input and output functions that could be called by an application. Similarly, disk input and output routines were incorporated into the OS. This led to the creation of subroutines to do these simple tasks, such as read a character from a keyboard or send a character to a printer. The joining together of all these basic input and output routines led to the input-output control system (IOCS). Originally, the IOCS could only read a punched card or send data to a card punch. However, as new input and output media, such as magnetic tape and disk, were developed the IOCS became more complex. Another complication was added when assembly and high-level languages were developed as the machine did not use these languages. Machines use binary codes for very simple instructions. With the development of these new types of programming language a computer would have to • • • • • • • load an assembler, compiler or interpreter, load the assembly or high-level program, do the translation, store the results somewhere in memory, execute the program, read input data, output the results.

The system had now become too complex for the human user to be able to organise it all. Also, as the processor could work much faster than the manual operator and the input and output devices, much time was wasted. Further, to make full use of the processor, more than one program should be stored in memory and the processor should give time to each of the programs. Suppose two programs are stored in memory and, if one is using an input or output device (both very slow compared to the processor), it makes sense for the other program to use the processor. In fact this can be extended to more than two programs as shown in Fig. 3.1.a.1. The OS must now manage the memory so that all three programs shown in Fig. 3.1.a.1 are kept separate as well as any data that they use. It must also schedule the jobs into a sequence that makes best use of the processor.

Program A

Using processor

I/O required

Using processor

Program B

Using processor

I/O required

Using processor

Program C

Using processor Processor in use

I/O required Processor in use

Processor

Processor idle Fig. 3.1.a.1 The I/O phase should not hold up the processor too much which can easily happen if the I/O devices are very slow, like a keyboard or printer. This can be overcome by using Simultaneous Peripheral Operations On-Line (spooling). The idea is to store all input and output on a high-speed device such as a disk. Fig. 3.1.a.2 shows how this may be achieved,

Input device

Input spool

Output spool

Output device

Read process

Application program

Write process

Fig. 3.1.a.2 Another problem is that programs may not be loaded into the same memory locations each time they are loaded. For example, suppose that three programs are loaded in the order A, B, C on one occasion and in the order C, A, B on another occasion. The results are shown in Fig. 3.1.a.3.

OS Program A

OS

Program C Program B

Program A Program C Program B Free Free

Fig. 3.1.a.3 A further problem occurs if two or more users wish to use the same program at the same time. For example, suppose user X and user Y both wish to use a compiler for C++ at the same time. Clearly it is a waste of memory if two copies of the compiler have to be loaded into main memory at the same time. It would make much more sense if user X's program and user Y's program are stored in main memory together with a single copy of the compiler as shown in Fig. 3.1.a.4.

OS User X's program and data

User Y's Program and data

Compiler

Free

Fig. 3.1.a.4 Now the two users can use the compiler in turns and will want to use different parts of the compiler. Also note that there are two different sets of data for the compiler, user X's program and user Y's program. These two sets of data and the outputs from the

compiler for the two programs must be kept separate. Programs such as this compiler, working in the way described, are called re-entrant. Memory management, scheduling and spooling are described in more detail in the following Sections. Distributed systems have operating systems that arrange for the sharing of the resources of the system by the users of that system. No action is required from the user. An example would be when a user asks for a particular resource in a network system, the resource would be allocated by the O.S. in a way that is transparent to the user.

There are a number of different types of interrupt. .1 needs to be modified as shown in Fig. a user has used up all the time allocated to his use of the processor. Start Fetch instruction Execute instruction Any more instructions? Yes No End Fig. Unfortunately things do go wrong and sometimes the normal order of operation needs to be changed. E.g. 3.b.1. Timer interrupt o Generated by an internal clock indicating that the processor must attend to time critical activities (see scheduling later).1.1 (b) Interrupts The simplest way of obeying instructions is shown in Fig.1.3.b. the sequence in Fig.b. called interrupts. Hardware error o For example. Program interrupt o Generated due to an error in a program such as violation of memory use (trying to use part of the memory reserved by the OS for other use) or an attempt to execute an invalid instruction (such as division by zero). If the OS is to manage interrupts. The nature of each of these types of interrupt is • • • • I/O interrupt o Generated by an I/O device to signal that a job is complete or an error has occurred.2. power failure which indicates that the OS must close down as safely as possible. 3. 3. This change in order is instigated by messages to the processor. 3.1. printer is out of paper or is not connected. For example.b.1 This is satisfactory so long as nothing goes wrong.1.

If one has occurred. . Taking the simplest case. There are several ways of dealing with this but the simplest is to place the interrupts in a queue and only allow return to the originally interrupted program when the queue is empty.Start Fetch instruction Execute instruction Is there an interrupt? No Yes Service the interrupt Any more instructions? Yes No End Fig.2 This diagram shows that. Alternative systems are explained in Section 3.b.b. the OS must see if an interrupt has occurred. Another problem the OS has to deal with happens if an interrupt occurs while another interrupt is being serviced. Chapter 3.c.3 explains registers that have to have their contents stored as well as explaining the processing cycle in more detail.3.1. This involves obeying a new set of instructions. the order of processing is shown in Fig.1.3.1. the OS must service the interrupt if it is more important than the task already being carried out (see priorities later). 3. after the execution of an instruction. The real problem is 'how can the OS arrange for the interrupted program to resume from exactly where it left off?' In order to do this the contents of all the registers in the processor must be saved so that the OS can use them to service the interrupt.

3.1. .b.Start Fetch instruction Yes Any more instructions? Execute instruction No No Is there an interrupt in the interrupt queue? Yes Service the next interrupt in the interrupt queue End Fig.3 The queue of interrupts is the normal first in first out (FIFO) queue and holds indicators to the next interrupt that needs to be serviced.

B using processor I/O B using processor A waiting for processor I/O A waiting for processor A using processor Fig. 3. Suppose the processor is required by program A. Program B makes a great deal of use of the processor and is said to be processor bound.1. it could be a long time before program A can print any wage slips. This is shown in Fig.c.1.2 shows what happens if A is given priority over B for use of the processor.1.c. another order may make one job more important than another. 3. This shows that the I/O bound program can still run in a reasonable time and much better throughput is achieved. world-wide sales of the company which has a turnover of many millions of pounds. Program A makes little use of the processor and is said to be I/O bound. The order may be chosen to ensure that maximum use is made of the processor.1 (c) Scheduling One of the tasks of the OS is to arrange the jobs that need to be done into an appropriate order. In the latter case the OS makes use of priorities.c.1. 3. and by program B. which is printing wage slips for the employees of a large company.1.1 Fig. If program B has priority over program A for use of the processor. B using processor I/O B using processor I/O B using processor I/O I/O B using processor I/O I/O A using processor A using processor A using processor Fig.c.3. which is analysing the annual. 3.2 A using processor .

3. all jobs entering the system normally enter via the ready state and (normally) only leave the system from the running state. I/O or processor bound.3 . Also. prevent the system failing if it is becoming overloaded.3 shows how jobs may be moved from one state to another. provide a reasonable response time to all users. The following is a list of criteria which may be used to determine a schedule which will achieve the above objectives. for example. Batch processing. The ready and blocked states are queues that may hold several jobs. Fig. make sure that the system is consistent by always giving similar response times to similar activities from day to day. Type of job. on-line and real-time jobs all require different response times. whether they are on-line users or a batch processing user. The time the job has been waiting to use the system. be fair to all users. The amount of time needed to complete the job.1. Give some jobs a greater priority than others when deciding which job should be given access to the processor. Resources used so far.1. of three states.c. and only one. Waiting time. In order to understand how scheduling is accomplished it is important to realise that any job may be in one.c. Resource requirements. A job may be ready to start. 3.The objectives of scheduling are to • • • • • maximise the use of the whole of the computer system. On a standard single processor computer only one job can be in the running state. how much I/O used so far. running on the system or blocked because it is waiting for a peripheral. I/O and processor time. The amount of processor time used so far. Enter the system READY BLOCKED RUNNING Leave the system Fig. If a processor bound job is given the main access to the processor it could prevent the I/O devices being serviced efficiently. the memory required. Note that a job can only enter the running state from the ready state. • • • • • • Priority. To achieve these objectives some criteria are needed in order to determine the order in which jobs are executed.

• • • • . but they can all be placed in one of two classes. SJF o simply means sort jobs in the ready queue in ascending order of time expected to be needed by each job. Some common scheduling policies are • • • • • First Come First Served (FCFS) Shortest Job First (SJF) Round Robin (RR) Shortest Remaining Time (SRT) Multi-level Feedback Queues (MFQ) and there are many more. MFQ o involves several queues of different priorities with jobs migrating downwards.When entering the system a job is placed in the ready queue by a part of the OS called the High Level Scheduler (HLS). SRT o the ready queue is sorted on the amount of expected time still required by a job. This is done by the Medium Level Scheduler (MLS). • FCFS o simply means that the first job to enter the ready queue is the first to enter the running state. A pre-emptive scheme allows the LLS to remove a job from the running state so that another job can be placed in the running state. The HLS makes sure that the system is not over loaded. In a non-pre-emptive scheme each job runs until it no longer requires the processor. Sometimes it is necessary to swap jobs between the main memory and backing store (see Memory Management in Section 3.d. The LLS decides the order in which jobs are to be placed in the running state. Moving jobs in and out of the ready state is done by the Low Level Scheduler (LLS). This may be because it has finished or because it needs an I/O device.1. These are pre-emptive and non-pre-emptive policies. RR o this gives each job a maximum length of processor time (called a time slice) after which the job is put at the back of the ready queue and the job at the front of the queue is given use of the processor. There are many policies that may be used to do scheduling. This scheme favours short jobs even more than SJF. This favours long jobs. If a job is completed before the maximum time is up it leaves the system. Also there is a danger of long jobs being prevented from running. New jobs are added to the queue in such a way as to preserve this order.

3.c. if a bank's computer is printing bank statements over night and someone wishes to use a cash point.c.c.1. 3. the cash point job must take priority. Priority 1 (high) Time up Priority 2 Priority 3 Queue Queue Queue P r o c e s s o r Priority 4 (low) RR Queue Fig. Also. This is shown in Fig. a computer monitoring the temperature and pressure in a chemical process whilst analysing results of readings taken over a period of time must give the high priority to the control program.1. and the job is not completely finished. Similarly.There are other ways of allocating priorities. the running program is placed back in the queue from which it came and the job that has entered the higher priority queue is placed in the running state.5 . instead of a first in first out queue a round robin system is used. the control program must take over immediately. When this time is up. This scheme is shown in Fig. Multi-level feedback queues work in a similar way except that each job is given a maximum length of processor time. 3. If the temperature or pressure goes out of a predefined range. this shows that queues are needed for jobs with the same priority. the job is placed in the queue which has the next lower priority level. Priority 1 (high) Queue P r o c e s s o r Priority 2 Priority 3 Queue Queue Priority 4 (low) Queue Fig. 3. on-line and real time applications will also have to have high priorities.4 In this scheme.4. At the lowest level. Safety critical jobs will be given very high priority. any job can only be given use of the processor if all the jobs at higher levels have been completed.1.1. if a job enters a queue that has a higher priority than the queue from which the running program has come.c.5. For example.

Clearly job E cannot be loaded into the space that job C has relinquished. If there are several jobs to be stored. B. In an examination the questions will be limited to basic definitions and explanations.1.1 Now suppose job C terminates and job E.) Fig. (Remember the OS will require some memory.d. Calculations of the addresses and other detail will not be required. there is 20k + 10 k = 30k of memory free in total. In order for a job to be able to use the processor the job must be stored in the computer's main memory. 3.d. 20k. and their data.1 shows one possible arrangement of the jobs.3. However. is next in the ready queue.1 (d) Memory Management This section can become very complex. . must be protected from the actions of other jobs. Suppose jobs A. One solution to the problem would be to move job D up to job B. 10k and 30k of memory respectively and the computer has a total of 130k available for jobs. Free 20k Job D 30k Job C 10k Job B 20k 130k available for jobs Job A 50k OS Fig 3. C and D require 50k. they. they are included here for completeness of the topic for those students who wish to understand in more detail. requiring 25k of memory.1. This would make heavy use of the processor as not only must all the instructions be moved but all addresses used in the instructions would have to be recalculated because all the addresses will have changed. So the OS must find some way of using it.

1.d. B. B. Job A Page 6 Page 5 Page 4 Page 3 Page 2 Page 1 Job B Page 4 Page 3 Page 2 Page 1 Job C Page 1 Memory Free C1 B4 B3 B2 B1 A6 A5 A4 A3 A2 A1 Fig. they may not always occupy the same locations.1. suppose jobs A. instead of jobs A. An alternative method is to divide both the memory and the jobs into fixed size units called “pages”. B. As an example. relative addressing can be used. So again there is a problem of using different addresses. this is called “compaction”. D and E consist of 6. 3. C and D being needed and loaded in that order.d. Possible solutions are • • • • whenever a job terminates. This system is known as variable partitioning with compaction. We also saw that sometimes it is necessary to move jobs around so that they fill the ‘holes’ left by jobs that leave. The part of the OS which carries out these tasks is a program called the loader.2 . 1.When jobs are loaded into memory. when a new job is too large for any existing space. it is required to load jobs A. These variable partitions are normally called segments and the method of dividing memory up is called segmentation. 3. Each of the jobs requires a different size of space. at regular intervals. Imagine that each job needs a space to fit into. Another problem to be solved is when to move jobs. 3 and 2 pages respectively. Supposing. B and C have been loaded into memory as shown in Fig. Now job D occupies different locations in memory to those shown above. That is. when the user decides. hence “variable partitions”. addresses are specified relative to the first instruction.2. C. The OS has the task of both loading the jobs and adjusting the addresses. D and E in that order. this space is the partition. 4. Also suppose that the available memory for jobs consists of 12 pages and jobs A. The calculation of addresses can be done by recalculating each address used in the instructions once the address of the first instruction is known. Alternatively.

Clearly we have a similar problem to that caused by segmentation.3.d.1.1. This can be overcome by keeping a table that shows which memory pages are used for the job pages. 3. Then. Memory E2 C1 E1 D3 D2 D1 A6 A5 A4 A3 A2 A1 Fig. Thus the solution is shown in Fig.1.Now suppose job B terminates. Job E Page 2 Page 1 Memory Free C1 Free D3 D2 D1 A6 A5 A4 A3 A2 A1 Fig.4.1.d. E consists of two pages. and jobs D and E are ready to be loaded.d. leaving one page plus the original one page of free memory. if each address used in a job consists of a page number and the distance the required location is from the start of the page.4 The problem with paging is again address allocation. 3. 3. E split . releasing four pages. 3. The 'hole' consists of four pages into which job D (three pages) will fit.3 The big difference between partitioning and paging is that jobs do not have to occupy contiguous pages.d. a suitable conversion is possible. in other words they are not joined together and we have the situation shown in Fig. so there is enough memory for E but the pages are not contiguous.

An alternative is to use variable length blocks. Since segments may be of different lengths. 3. in job A. address calculation has to be carefully checked. programmers divide jobs into segments.d. . In segmentation. Fig.1. This is needed to ensure that an address does not go out of range.5 shows how two jobs may be stored in memory. possibly of different sizes. In this case the programmer split Job A into 4 segments and Job B into 3 segments. when loaded into memory. This method is called segmentation. This may be represented by 5 Now suppose we have the following table 46 Job Page A1 A2 A3 A4 A5 A6 Memory Page 4 5 6 7 8 9 We see that page A5 is stored in page 8 of memory. took up the positions shown in the Figure.Suppose. These two jobs. thus 5 46 Becomes 8 46 Paging uses fixed length blocks of memory. the segments would consist of data. Usually. or sub-routines or groups of related sub-routines. The segment table must not only contain the start position of each segment but also the size of each segment. an instruction refers to a location that is on page 5 and is 46 locations from the start of page 5.

d. 3.5 .1.Job A Segment A4 Job B Segment B3 Memory Free A4 Segment A3 Segment B2 Segment A2 Segment A1 Segment B1 A3 B1 B3 A2 B2 A1 Fig.

Add displacement to base address to produce physical address. Size Base Address 1500 3500 Fig. When a program is running. Otherwise the displacement is added to the base address to produce the actual address in memory to be used. 2. The OS will look up. For example. This is also shown in Fig. We have seen that jobs can be loaded into memory when they are needed using a paging technique. the OS does not need to load page 2 again as it is already loaded. in the process segment table. To run this word processor only page 1 needs to be loaded initially. if the user wishes to copy and paste a piece of text.1. page 3 the code for formatting paragraphs and page 4 contains the code for cutting.d. Use segment number to find base address of segment from segment table. 3.6 Paging and segmentation lead to another important technique called virtual memory. the basic address (in memory) of segment 3. 4. Segment Number Displacement 3 132 Physical Address 3632 1.1. the appropriate page can be loaded. Get displacement. an error is reported. . 3. + Seg. 3.d. 6. The algorithm for this process is Get segment number. then page 2 will have to be loaded. Also suppose that page 2 contains the code for formatting characters. If the user now wishes to format some more characters. No. When other facilities are needed. suppose a word processor has been written with page 1 containing the instructions to allow users to enter text and to alter the text. displacement (from start of segment) 132. If it is. The OS checks that the displacement is not greater than the segment size. copying and pasting. 1 2 3 4 Segment Table Seg. 4.Now suppose that an instruction specifies an address as segment 3.1 produce error message 4. only those pages that contain code that is needed need be loaded. If displacement is greater than segment size. Similarly. 5. Use segment number to find length of segment from segment table.2 stop.6. If the user then wants to format some characters so that they are in bold. page 4 will have to be loaded.

Clearly. the new page can overwrite a page that is not currently being used. If the memory is very full. This situation is called disk threshing. For example. the OS can see if that page has been changed. this loading and saving can use up a great deal of time and can mean that most of the processor's time is involved in swapping pages. virtual memory can use segmentation as well as paging although this can become very complex. this means that programs can be written and used that are larger than the available memory. suppose the user wishes to use paragraph formatting. If it has. To keep track of this the OS keeps a flag for each page that can be initially set to zero. replace the page that has not recently been used or the first in first out method. All of these create extra work for the OS. Also. Systems can use both multi-programming and virtual memory. To further complicate matters not every page can be overwritten. Some pages contain a job's data that will change during the running of a program. There are many systems such as overwrite the page that has not been used for the longest period of time.Now. the flag can be set to 1. then the OS can load page 3 into the memory currently occupied by page 2. before overwriting a page. . The OS now has to both load and save pages. Now. There must be some system that decides which pages to overwrite. what happens if there is insufficient space for the new page to be loaded? As only the page containing active instructions need to be loaded. If the content of the page changes. then the OS will save the page before loading a new page in its place.

several jobs may wish to use the peripheral devices at the same time. It is important to realise that the output itself is not placed in the queue. the output from different jobs is kept separate. When the output from a job is finished. Suppose two jobs. As the files are on disk. are producing output that is to go to a single printer. one for each job. It is essential that the input and output for different jobs do not become mixed up.1. This can be achieved by using Simultaneous Peripheral Operations On-Line (spooling). such as disk.3. In a multi-programming. Spooling is used on personal computers as well as large computer systems capable of multi-programming. This means that the OS now can send the output to the printer in the order in which the file details enter the queue. the name (and other details) of the file can be placed in a queue. It should be noted that spooling not only keeps output from different jobs separate. Opening two files on a disk. The queue simply contains the details of the files that need to be printed so that the OS sends the contents of the files to the printer only when the file is complete. so that slow peripheral devices do not hold up the processor. multi-access or network system.a and is used to place input and output on a fast access device.1 (e) Spooling Spooling was mentioned in Section 3. As the name of a file does not enter the queue until all output from the job to the corresponding file is complete. in a network system. it also saves the user having to wait for the processor until the output is actually printed by a printer (a relatively slow device). The part of the OS that handles this task is called the spooler or print spooler. job 1 can write to File1 whenever it wishes and job 2 can write to File2. can do this. . The output is being produced in sections and must be kept separate for each job. Spooling can be used for any number of jobs. Suppose we call these files File1 and File2.

All OS's for PC's allow the user to copy. Probably the best known of these are MS-DOS (command driven) and Windows (GUI). disk drives and keyboard. printed with a shaded background. is not required by the CIE Computing Specification. However. This section. delete and move files as well as letting the user create an hierarchical structure for storing files. the boot program looks for an OS on disk C. but may be interesting and useful for understanding how the system works. You will see that the clock is keeping time although you are using another piece of software. RAM. If any of these devices. When a PC is switched on.3. They also allow the user to check the disk and tidy up the files on the disk. In fact the OS is swapping between the tasks so fast that the user is not aware of the swapping. Control is now passed to the boot program which first checks itself and the POST program.(f) Desktop PC Operating Systems There are basically two types of OS used on PC's. This is when the user opens more than one program at a time and can move from one to another. this is incorporated with the system's BIOS. Try opening a word processor and the clipboard in Windows at the same time. Another good example of multi-tasking is to run the clock program while using another program. This includes checking the buses. Try playing a CD while writing a report! The OS not only offers the user certain facilities. If no OS is found. These differ in the way the user uses them and in the tasks that can be carried out. such as the hard disk. The boot program first checks drive A to see if a disk is present. Adjust the sizes of the windows so that you can see both at the same time. systems clock. These are command driven and those that use a graphical user interface (GUI). Once found. in the case of Windows . This boot program is stored in read-only memory (ROM) and contains the basic input/output system (BIOS). an error message is produced. If there is no disk in drive A. The POST routine clears the registers in the CPU and loads the address of the first instruction in the boot program into the program counter. Now mark a piece of text and copy it to the clipboard. contain their own BIOS. it looks for an OS on the disk. Often the BIOS is copied from a slow CMOS BIOS chip to the faster RAM chips. Windows allows the user to use much more memory than MS-DOS and it allows multi-tasking. You will see the text appear in the clipboard window although it is not the active window. The CPU then sends signals to check that all the hardware is working properly. The first step the computer does is to run the power-on-self-test (POST) routine that resides in permanent memory. it contains only a very few instructions. it also provides application software with I/O facilities. If one is present. the boot program looks.1. This is because the OS can handle both tasks apparently at the same time. In this Section you will see how an OS is loaded and how it controls the PC. The PC is now ready to load the OS.

In order to do this. When a time-slice is up. with facilities to handle input and output. Windows also uses virtual memory if an application has not been allocated sufficient main memory. for the files IO. The OS supplies the user. Any OS has to be able to find files on a disk and to be able to store user's files.SYS which tells the OS how many files may be opened at the same time.SYS and AUTOEXEC. .COM. The OS tells MSDOS. This simply means dividing the disk radially into sectors and into concentric circles called tracks. Windows saves the output to the hard disk first and then does the printing in the background so that the user can continue to use the application.f. SYSINIT controls the rest of the boot procedure. As mentioned above. that is. If further printing is needed before other printing is completed.SYS and MSDOS. Windows uses the memory management techniques described in Section 3. If an application needs to use a hardware device. the OS has to save the contents of the CPU registers at the end of a time-slice and load the registers with the values needed by the next application. To do this. an interrupt occurs and Windows passes control to the next application. The files CONFIG. In order to do this the OS has a routine that will format a disk. called a time-slice. about 512 bytes. This is shown in Fig.1. the request is placed in a queue. Control is then passed to the next application. The second part contains resident OS commands. Windows gives each application a very short period of time. If not. In the case of Windows. then spooling is used as described in Section 3. This OS file is in three parts. 3. In the case of a slow peripheral such as a printer.SYS. Windows will load the appropriate device driver. The OS searches the root directory for a boot file such as CONFIG. If an application program needs to use a particular piece of hardware. This is continued so that all the applications have use of the processor in turn.BAT are created by the user so that the PC starts up in the same configuration each time it is switched on. To do this.systems. Two or more sectors on a single track make up a cluster. handle memory allocation and any other basic tasks. This table uses a linked list to point to the blocks on the disk that contain files. the application is given the use of that device. SYSINIT now takes control and loads MSDOS.1.d. Windows checks to see if that device is available. Once the files are found.1.SYS which works with the BIOS to manage files and execute programs. the operating system loads into different parts of memory.e.SYS holds extensions to the ROM BIOS and contains a routine called SYSINIT. The OS then guarantees the use of a block of memory to an application program and protects this memory from being accessed by another application program. and applications programs. copy and move files.1.SYS to load a file called COMMAND. It may also contain instructions to load various device drivers. the boot program loads the boot record. Windows allows multi-tasking. If it is. the OS uses the File Allocation Table (FAT). The first part is a further extension to the I/O functions and it joins the BIOS to become part of the OS. which then loads IO. such as DIR and COPY. the running of several applications at the same time.SYS. IO. In order to multi-task.

f.Cluster using 3 sectors Sectors Tracks Fig 3. The last cluster used has a null pointer (usually FFFFH) to indicate the end of the linking.2 In order to find a file. In order to store a new file.1. The directory entry for a file has a pointer to the first cluster in the FAT table. Thus. Cluster 0 1 2 3 4 5 6 7 8 9 10 11 Pointer FFFD FFFF 3 5 6 8 7 10 9 FFFF 11 FFFF Pointer from directory entry for File 1 Pointer from directory entry for File 2 End of File 1 is in cluster 9 End of File 2 is in cluster 11 Fig. .1 A typical FAT table is shown in Fig 3.2. In this table any unused clusters have a zero entry.1. all the OS has to do is to find the first cluster with a zero entry and to enter the cluster number in the directory.f. the OS gets the cluster number for the start of the file.1. Now the OS only has to linearly search for clusters with zero entries to set up the linked list. The first column gives the cluster number and the second column is a pointer to the next cluster used to store a file. the clusters that were used to save the file can be set to zero.f. The diagram shows details of two files stored on a disk. 3. if it finds it. the OS looks in the directory for the filename and. when a file is deleted. The OS can then follow the pointers in the FAT to find the rest of the file.

However. . the FAT table is normally loaded into RAM so that continual disk accesses can be avoided. Windows 98 uses FAT 32 which allows hard drives greater than 2 Gbytes to be formatted. Note that Windows 95/98 uses virtual FAT (VFAT) which allows files to be saved 32 bits at a time (FAT uses 16 bits). This will speed up the search of the FAT. It also allows file names of up to 255 characters.It may appear that using linear searches will take a long time.

hardware sharing (including print spooling). For example. Also. in a peer-to-peer network all the stations on the network have equal status. the NOS must only allow users with access rights permission to use files. Users are allowed to change how their desktops look and these are stored by the NOS for future reference. other users must only be allowed read access. The NOS then looks up. printing. When users log onto a network they must enter their user identity and password. the users' access rights and only allows them access to those files for which access is permitted. At the same time. in a table. the user interface. but to hide them from the users.1. the NOS has to manage • • • • • • • file sharing. these hidden files will not appear. file sharing. This is so that the user can be charged for such things as printing. it may be necessary for the NOS to keep details of who has used the network. In this system one station may act as a file server and another as a print server. The facilities provided by a NOS depend on the size and type of network. A client is a computer that can be used by users of the network. that is. software sharing. accounting.(g) Network Operating Systems This Section should be read in conjunction with Chapters 1. when and for how long and for what purpose. It is common practice for the NOS to not only make these files read only. To ensure the security of data. file security. It is important that users do not change system files (files that are needed by the NOS). If a user looks at the disk to see what files are present. the network manager gives users access rights. A peer-to-peer network has little security so the NOS only has to handle • • • communications.3. the NOS must only allow one user write access to the file. all the stations are clients. and to prevent users showing hidden files. communications. This means that when users log on they are always presented with the same screen. It may also record which files the user has accessed.6 from the AS text and 3. the NOS does not allow ordinary users to change these attributes. In order to avoid corruption and inconsistency. the amount of time that the network . it must prevent unauthorised access to data. To prevent users changing read only files to read write files. If a network contains one or more servers. File sharing allows many users to use the same file at the same time. As many users may use the network and its resources. The NOS also keeps a note of how the users want their desktops to look.10 from this A2 text.

the NOS must send a copy of that application to the user's station. one part may be called the H drive which is where users are allowed to save their work.has been used and storage of files. For all the above to work. Thus. spreadsheets and so on. The NOS must provide this service as well as preventing users accessing other users' folders. Another part of the drive may be called (say) the U drive where some users can store files for other users who will be allowed to retrieve. software and user.6 in the AS text. them unless they are saved in the user's own area.1. but not alter. the NOS must provide a user interface between the hardware. The NOS receives these packets and stores the data in different files for different users. It must be remembered that users must not need an understanding of all the tasks undertaken by the NOS. In order to do this. This is particularly true of printers. the NOS looks up the needs of the user and displays the appropriate icons and menus for that user. The NOS must also ensure that users' files are saved on the server and that they cannot be accessed by other users. When a user sends a file for printing. Users only have access to their own folders but can create sub-folders in their own folders. Several users may well wish to use the same hardware at the same time. As far as users are concerned they are using a PC as if it . The NOS will also only allow access to certain logical drives by a restricted set of users. but a NOS has to offer different users different interfaces. For example. As many users may wish to use a printer. This has been discussed in Section 3.e. each of which is allocated to a different user. These two parts must be able to communicate with one another so that messages and data can be sent around the network. This means that. The NOS must share the use of applications such as word processors. Finally. This drive will be divided up into folders. the amount of paper used for printing and so on. If a user tries to save work when there is insufficient space left. the server's hard drive may be partitioned into many logical drives.1. different parts of it can be treated as though they are different drives. although there may be only one hard drive. the packets from different users will arrive at the print server and will have to be sorted so that the data from different users are kept separate. When a particular file is complete. One part is in each station and the other is in the server(s). To do this the network manager will allocate each user a fixed amount of disk space and the NOS will prevent a user exceeding the amount of storage allocated. the NOS is in two parts. From time to time the network manager can print out details of usage so that charges may be made. the file is split into packets. Thus when a user requests an application. When a user logs onto a network.f. The need for rules to ensure that communication is successful was explained in Chapter 1. it can be added to the print queue as described in Section 3. This part of the NOS may also restrict the users' amount of storage available. the NOS will ask the user to delete some files before the user can save any more. no matter which station the user uses. the NOS will have to handle communications between stations and servers. The NOS must also allow users to define their own interfaces within the restrictions laid down by the network manager.

. The whole system is said to be transparent to the user. A good user interface has a high level of transparency and this should be true of all operating systems.were solely for their own use. This simply means that users are unaware of the hardware and software actions.

(5) Explain the difference between (i) Input/output bound jobs and (ii) Processor bound jobs. (3) 7. (4) 2. Explain how interrupts are used in a round robin scheduling operating system. Describe how a PC operating system uses a file allocation table to find files when necessary. . (3) 6.3. a) Explain the difference between paging and segmenting when referring to memory management techniques. Explain how an interrupt is handled by a processor which is working on another task. (2) b) Describe how virtual memory can allow a word processor and a spreadsheet to run simultaneously in the memory of a computer even though both pieces of software are too large to fit into the computer’s memory. State three different types of interrupt that may occur and say in what order the three interrupts would be handled if they all arrived at the processor together. giving a reason for your answer. Explain how the computer should prioritise the two types of job if it is going to make maximum use of the system. 4.1 Example Questions 1. 5. (4) Describe two types of scheduling that are used by computer processing systems. (4) 3.

Once this is done. The relationship between them is shown in Fig. was still tedious and took a long time. In this system each instruction is taken in turn and translated to machine code. Source Code (High-Level Language) COMPILER Object Code (Machine Language) Fig. The high-level language version of the program is usually called the source code and the resulting machine code program is called the object code. It has to be loaded in the computer's memory at the same time as the source code and there has to be sufficient memory to hold the object code. After assembly languages. Assembly languages allowed the use of mnemonics and names for locations in memory.a. although easier than using machine code. the programs had to be written in machine code.2 The Functions and Purposes of Translators 3. assemblers were written which could be loaded into the computer and then the computer could translate the assembly language to machine code. COBOL (Common Business Oriented Language) was developed for business applications. Another disadvantage is that when an error in a program occurs it is difficult to pin-point its source in the original program. Thus FORTRAN (FORmula TRANslation) was developed for science and engineering programs and it used formulae in the same way as would scientists and engineers. the machine code version can be loaded into the machine and run without any further help as it is complete in itself. Further.1. This not only took a long time.2 .1 . This system was developed because early personal 4.1 The problem with using a compiler is that it uses a lot of computer resources. Programs written in these languages needed to be translated into machine code. An alternative system is to use interpretation. To produce these programs. 3. Each assembly instruction mapped to a single machine instruction which meant that it was fairly easy to translate a program written in assembly language to machine code. To improve program writing assembly languages were developed. programmers had to write the instructions in binary.2 (a) Interpreters and Compilers When electronic computers were first used.Chapter 3. came high-level languages which used the type of language used by the person writing the program.2.a. This led to the birth of compilers. Writing programs in assembly language. This code was comprised of simple instructions each of which was represented by a binary pattern in the computer. A compiler takes a program written in a high-level language and translates into an equivalent program in machine code. it was also prone to errors. To speed up this translation process. 3. The instruction is then executed before the next instruction is translated. there has to be sufficient memory for working storage while the translation is taking place.2.

the translation from a high-level language to machine code has to go through various stages and these are shown in Fig. This method also has the advantage of producing error messages as soon as an error is encountered. interpretation is very useful during program development as errors can be found and corrected as soon as they are encountered. Against interpretation is the fact that execution of a program is slow compared to that of a compiled program. use both an interpreter and a compiler. This machine code version can then be distributed to users who do not have access to the original code. This is because the original program has to be translated every time it is executed. This enables the programmer to use the interpreter during program development and. This means that the instruction causing the problem can be easily identified. when the program is fully working. instructions inside a loop will have to be translated each time the loop is entered.2 . Also.computers lacked the power and memory needed for compilation. Whether a compiler or interpreter is used. However. it can be translated by the compiler into machine code.a. In fact many languages. Source Program Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Language Code Generation Code Optimisation Object Program 4. 3.2 .2. such as Visual Basic.2.

3. tabs. Single characters. When two names are hashed to the same address. This table is used throughout compilation to build up information about names used in the program. which we may find useful to make the code more readable. Multiple character tokens are represented by integers greater than 255 because the ones up to 255 are reserved for the ASCII codes. For example. etc. a linked list can be used to avoid the symbol table filling up. the following two pieces of code are equivalent although their format is considerably different. For example.c) can always expect the format of its input to be the same.3 . Often the lexical analysis takes longer than the other stages of compilation. Variable names will need to have extra information stored about them. and we will be looking at in 3.2 (b) Lexical Analysis The lexical analyser uses the source program as input and creates a stream of tokens for the syntax analyser. This must be done efficiently so a linear search is not sufficiently fast. the code will be in a standard format which means that the syntax analyser (which is the next stage. At various stages during compilation it will be necessary to look up details about the names in the symbol table. are replaced by their ASCII values. It is during syntax and semantic analysis that details such as the variable's type and scope are added. which can have many formats. it is usual to use a hash table and to calculate the position of a name by hashing the name itself. but the computer does not want) and comments. IF X = Y THEN 'square X Z := X * X ELSE 'square Y Z := Y *Y ENDIF PRINT Z IF X = Y THEN Z := X * X ELSE Z := Y * Y PRINT Z When the lexical analyser has completed its task. which have a meaning in their own right.2 . This is because it has to handle the original source code. it will report errors such as an identifier or variable name which breaks the rules of the language. In fact.2.. The lexical analyser also removes redundant characters such as white space (these are spaces. This is done by means of a symbol table. Tokens are normally 16-bit unsigned integers. During lexical analysis only the variable's name will be noted. Each group of characters is replaced by a token. 4. The lexical analyser may output some error messages and diagnostics.

If the original statement is sum := sum + + number this will be input as <variable> <assignment_operator> <variable> <arithmetic_operator> <arithmetic_operator> <variable> 4.j which discusses BackusNaur Form (BNF) and syntax diagrams. During this stage of compilation the code generated by the lexical analyser is parsed (broken into small units) to check that it is grammatically correct. It is against these rules that the code has to be checked.3. If the statement is sum := sum + number the parser will receive <variable> <assignment_operator> <variable> <arithmetic_operator> <variable> which becomes <variable> <assignment_operator> <expression> and then <assignment statement> which is valid. taking a very elementary language. All languages have rules of grammar and computer languages are no exception. The grammar of programming languages is defined by means of BNF notation or syntax diagrams.2 (c) Syntax Analysis This Section should be read in conjunction with Section 3. an assignment statement may be defined to be of the form <variable> <assignment_operator> <expression> and expression is <variable> <arithmetic_operator> <variable> and the parser must take the output from the lexical analyser and check that it is of this form.2 .4 . For example.5.

For example in C (and C++) the CONTINUE statement can only be placed inside a loop and the BREAK statement can only be placed inside a loop or SWITCH statement. flow of control checks and declaration checks. Many languages insist on the programmer declaring variables and their types. the lexical analyser may pick up this error because PRIT has not been declared as a variable and so is not in the symbol table. 4. This will mean that the statement containing PRIT will not parse to a valid statement. However. The compiler must ensure that statements like these are used in the correct place. It is at this stage that invalid names can be found such as PRIT instead of PRINT as PRIT will be read as a variable name instead of a reserved word. unconditionally.5 . Certain control constructs can only be placed in certain parts of a program. Some languages allow GOTO statements (not recommended by the authors) which allow control to be passed.and this does not represent a valid statement hence an error message will be returned. to another statement which has a label. These include label checks. During syntax analysis certain semantic checks are carried out.2 . It is at this stage that the compiler verifies that all variables have been properly declared and that they are used correctly. The compiler must check that such a label exists. The GOTO statement specifies the label to which the control must pass. Most compilers will report errors found during syntax analysis as soon as they are found and will attempt to show where the error has occurred. Note that in languages that require variables to be declared before being used. they may not be very accurate in their conclusions nor may the error message be very clear.

1. 3. In the latter case. where Ri represents an intermediate result. the code can be saved and distributed to computer systems as an executable program. Two methods can be used to represent the high-level language in machine code.d. R1 := B + C R2 := D – E R3 := R1 * R2 A := R3 / F This can also be represented by the tree shown in Fig. This is done as soon as the variable is encountered during code generation. TAC allows no more than three operands. The address of the variable is now calculated and stored in the symbol table.2. 4.6 . Before the final code can be generated. using three address code.2 (d) Code Generation It is at this stage. that the program is translated into code suitable for use by the computer's processor.3. when all the errors due to incorrect use of the language have been removed. This intermediate code can then be interpreted or translated into machine code. but a brief outline is given for those who may be interested. Instructions take the form Operand1 := Operand2 Operator Operand3 For example. an intermediate code is produced. This syllabus does not require knowledge of either of these methods. the assignment statement A := (B + C) * (D – E) / F can be evaluated in the following order. One uses a tree structure and the other a three address code (TAC).2 . During lexical and syntax analysis a table of variables has been built up which includes details of the variable name. its type and the block in which it is valid.

but should be aware of what it is.2. the type of code that is required. Candidates will not be expected to optimise code. An example of code optimisation is shown in Fig.2 where the code on the left has been changed to that on the right so that r1 * b is only evaluated once.2 . 3. Code can be improved in order to increase the speed of execution or in order to make size of the program as small as possible.2.d.2.1 E Other statements can be represented in similar ways and the final stage of compilation can then take place.2 There are many other ways of optimising code but the last section has hopefully made the concept clear. 3. a := 5+ 3 b := 5 * 3 r1 := a + b r2 := r1 * b r3 := r2 / a r4 := r1 .b r5 := r4 + 6 c := r3 – r5 Fig. Often compilers try to compromise between the two. The compiler has to consider. This process of improving the code is known as optimisation. at this point.d.:= A / * F + - B C D Fig.7 .d. 3. a := 5 + 3 b := 5 * 3 r1 := a + b r2 := r1 * b r3 := r2 / a r4 := r2 r5 := r4 + 6 c := r3 – r5 4.

2 . The linker calculates the addresses of the separate pieces that make up the whole program and then links these pieces so that all the modules can interact with one another. all of which have been separately compiled. The loader decides where in memory to place the code and then adjusts memory addresses as described in Chapter 3.2 (e) Linkers and Loaders Programs are usually built up in modules. As the whole program may consist of many modules.5. This method of creating programs is important as it reduces the need to keep rewriting code and will be further discussed under object oriented programming in Section 3. This process is done by the loader.8 . The idea of using modules that can be used in many programs was explained in Section 1.1. This is the job of the linker.f. These modules are then compiled into machine code that has to be loaded into the computer's memory.3 in the AS text.3. the modules will have to be correctly linked once they have been loaded. 4.

(2) b) Give one advantage of the use of each of the two translation techniques. the purpose of each. Explain why the size of the memory available is particularly relevant to the process of compilation. the stage of compilation known as lexical analysis. a) Explain the difference between the two translation techniques of interpretation and compilation. in detail. 4. 3.9 . Example Questions.2 1.3. (2) State the three stages of compilation and describe. briefly.2 . (6) Explain. (6) 4. (4) 2.

the processor has to use some special registers. therefore. The memory data register acts like a buffer and holds anything that is copied from the memory ready for the processor to use it.1 . 3. The central processor contains the arithmetic-logic unit (also known as the arithmetic unit) and the control unit. The current instruction register holds the instruction that is to be executed.a. This led to the introduction of compilers which accepted text as input and produced binary code as output. The Von Neumann architecture uses a single processor which follows a linear sequence of fetch-decode-execute. decodes them and synchronises the operations before sending signals to other parts of the computer. A typical layout is shown in Fig. Logical operations involve comparing binary patterns and making decisions. Sometimes the program counter is called the Sequence Control Register (SCR) as it controls the sequence in which instructions are executed. In order to do this. the program counter and the instruction registers are in the control unit and the memory data register and memory address register are in the processor.3 Computer Architecture and the Fetch-Execute Cycle 3. use the same memory.3 . The memory address register is used to hold the memory address that contains either the next piece of data or an instruction that is to be used. Arithmetic operations are those that add and subtract numbers. Von Neumann realised that data and programs are indistinguishable and can. This involves arithmetic and logical operations.3 (a) Von Neumann Architecture John Von Neumann introduced the idea of the stored program. The arithmetic-logic unit (ALU) is where data is processed.Chapter 3.1 which also shows the data paths. The control unit fetches instructions from memory. These are Register PC CIR MAR MDR Accumulator Meaning Program Counter Current Instruction Register Memory Address Register Memory Data Register Holds results The program counter keeps track of where to find the next instruction so that a copy of the instruction can be placed in the current instruction register. 4. and so on.3. The accumulator is in the arithmetic unit. Previously data and programs were stored in separate memories.

3.3 .Main Memory Central Processing Unit (CPU) Control Unit PC CIR ALU Accumulator MAR MDR Fig 3.2 .1 4.a.

Thus the next instruction is copied from memory into the MDR and is then copied into the current instruction register.3 . Step 1 simply places the address of the next instruction into the memory address register so that the control unit can fetch the instruction from the right part of the memory. However. 3. Load the instruction that is in the memory address given by the MAR into the memory data register (MDR). Steps 5. assuming that the instructions are in consecutive locations. the PC has to be loaded with the address of the instruction that is to be executed next. If it is an arithmetic instruction. if the instruction involves jumping to an instruction that is not the next one in order. Decode the instruction that is in the CIR. This address is in the address part of the current instruction. Execute the instruction. 8. 6a and 7 are the execute part of the cycle and steps 6b and 8 are the reset part. or vice versa. Load the address part of the instruction into the PC b.3 . 5.3. Now that the instruction has been fetched the control unit can decode it and decide what has to be done. At the end the cycle is reset and the algorithm repeated.3 (b) The Fetch-Decode-Execute-Reset Cycle The following is an algorithm that shows the steps in the cycle. Steps 1 to 4 are the fetch part of the cycle. 6. This is the execute part of the cycle. 4. Reset by going to step 1. hence the address part is loaded into the PC before the cycle is reset and starts all over again. 2. this can be executed and the cycle restarted as the PC contains the address of the next instruction in order. Load the instruction that is now in the MDR into the current instruction register (CIR). The memory data register is used whenever anything is to go from the central processing unit to main memory. 4. Load the address that is in the program counter (PC) into the memory address register (MAR). Increment the PC by 1. 7. Reset by going to step 1. If the instruction is a jump instruction then a. The program counter is then incremented by 1 so that it contains the address of the next instruction. 1.

decoded (by the control unit) or being executed (by the control unit).3.2 The effect of pipe lining is that there are three instructions being dealt with at the same time.3 (c) Parallel Processor Systems Using the above architecture for a microprocessor illustrates that basically an instruction can be in one of three phases.3 . Fetch Instruction 1 Instruction 2 Instruction 3 Instruction 4 Instruction 5 Decode Execute Instruction 1 Instruction 2 Instruction 3 Instruction 4 Fig. The result is shown in Fig. 3. which shows how this process.2 Fetch Instruction 1 Instruction 2 Instruction 3 Instruction 4 Instruction 10 Instruction 11 Instruction 12 Instruction 10 Instruction 11 Instruction 10 Instruction 1 Instruction 2 Instruction 3 Instruction 1 Instruction 2 Decode Execute Fig.3.3. the pipe will have to be cleared and the cycle restarted in this case. known as pipelining. Suppose Instruction 2 is a jump to Instruction 10.c.3.4 .3. Then Instructions 3.1.c. This would result in the situation shown in Fig. each of which handles one of the three stages. An alternative is to split the processor up into three parts.1 Instruction 1 Instruction 2 Instruction 3 This helps with the speed of throughput unless the next instruction in the pipe is not the next one that is needed. 4 and 5 need to be removed from the pipe and Instruction 10 needs to be loaded into the fetch part of the pipe. It could be being fetched (from memory).c. This SHOULD reduce the execution times considerably (to approximately 4. 3. 3. 3. Thus. works.c.

If the programs have been written for standard architectures. Using n/2 processors we could simultaneously add n/2 pairs of numbers in the same time it would take a single processor to add one pair of numbers. Continuing in this way the time to add the series would be considerably reduced. checks have to be made to ensure that all prerequisites have been completed. this would only be true for a very linear program. the pipe line has to be cleared and the process started again. so every time the sequence of instructions changes. Once jump instructions are introduced the problem arises that the wrong instructions are in the pipe line waiting to be executed. Consider finding the sum of n numbers such as 2 + 4 + 23 + 21 + …. one after the other.5 . However. One of the difficulties with this is that the programs running on these systems need to have been written specially for them. This would leave only n/2 numbers to be added and this could be done using n/4 processors. A simple example that shows how the use of parallel processors can speed up a solution is the summing of a series of numbers.1/3 of the standard times). Thus. This type of processing uses an architecture known as parallel processing. each carrying out an individual instruction at the same time as its partners.3 . then some instructions cannot be completed until others have been completed. Another type of computer architecture is to use many processors. which involves many independent processors working in parallel on the same program. however. 4. + 75 + 54 + 3 Using a single processor would involve (n – 1) additions. these systems are in use particularly when systems are receiving many inputs from sensors and the data need to be processed in parallel.

explaining. (2) Describe two ways in which the program counter can change during the normal execution of a program. explaining why such a reset is necessary. Explain what is meant by the term Von Neumann Architecture. a) Describe how pipelining normally speeds up the processing done by a computer. (3) 4. 1. a) b) Describe the function of the program counter. in each case. (4) Describe the initial state of the program counter before the running of the program.3 Example Questions The questions in this section are meant to mirror the type and form of questions that a candidate would expect to see in an exam paper.3 . As before.6 . (2) 3. Describe the fetch/decode part of the fetch/decode/execute/reset cycle. (7) 4. explaining the purpose of any special registers that you have mentioned. (2) b) State one type of instruction that would cause the pipeline system to be reset. The Program Counter (Sequence Control Register) is a special register in the processor of a computer.3. (2) c) 2. the individual questions are each followed up with comments from an examiner. how this change is initiated.

A computer is an electronic machine. which we remember in the next column and then start again. which makes the system more difficult. If electricity is not flowing through a wire it can stand for 0. But why multiply by 10? Why not multiply by 6? The answer is simply that we were taught to do that because we have 10 fingers. However. then it stands for 1. we have to learn.4 Data Representation. in 23 the 2 actually means 2 * 10. just like what happens when we run out of fingers. Instead of increasing the number of symbols in a system. This is very difficult to learn because of all the symbols needed.4 (a) Numerical Representation Counting is one of the first skills that a young child masters.Chapter 3. Electricity can be either on or off. 60 seconds = 1 minute.2…9 and also to understand that two identical symbols mean totally different things according to their ‘place’ in the number. and none of us consider counting from 1 to 100 difficult. to count. We can’t just pump through twice as much electricity. 6 * 60 degrees = 1 revolution.4 .1. Data Structures and Data Manipulation 3. The ancient Babylonians counted in a system. what we need is a carry system. the meanings of the symbols 0. by heart. The ‘units’ wire The ‘twos’ wire ADD 1 no electricity no electricity 0 =0 0 electricity no electricity ADD 1 no electricity Carry ADD 1 electricity electricity ADD 1 electricity 1 =1 0 0 =2 1 1 =3 1 4. The difficulty is what to do for the number 2. What we need is another wire. but we still use a system based on sixties today: 60 minutes = 1 hour. so we can count on our fingers until we get to the last one. which is similar to counting in sixties. If electricity is flowing. We don’t need to count in tens. For instance. it seems reasonable that if we decrease the number of symbols the system will be easier to use.1 .

Change 117 (in denary) into a binary number. Usually a byte has 8 bits in it. 4. A group of bits is called a BYTE. and repeat. so the column headings go up in twos instead of tens 32s 16s 8s 4s 2s units To turn a denary number into a binary number simply put the column headings. So each digit. 128 is greater than 117 so put a 0 and repeat. The first thing we must be able to do with the binary system is to change numbers from our system of 10 numbers (the denary system) into binary. e. 128 0 128 0 64 64 1 32 32 16 16 8 8 4 4 2 2 1 1 64 is less than 117 so put a 1. Each wire. or digit. the simplest being to use the sort of column diagrams. 0 and 1.4 . Answer: Always use the column headings for a byte (8 bits) 128 64 32 16 8 4 2 1 Follow the algorithm. put a 1 in the column and then subtract the column heading from the number. put a 0 in the column and start again with the next column on the right. Then start again with the next column on the right. start at the left hand side and follow the steps: • If the column heading is less than the number. this time we are using binary. 0 or 1.2 . is known as the binary system. A single bit has very few uses so they are grouped together. This name is normally shortened to BIT. Take 64 from 117 = 53. is known as a binary digit. This system. • If the column heading is greater than the number. Note: You will be expected to be able to do this with numbers up to 255.g. which were used in primary school to do simple arithmetic Thousands Hundreds Tens Units except. where there are only two digits. because that is the biggest number that can be stored in one byte of eight bits. is one bit. There are a number of methods for doing this.no electricity Carry no electricity Carry electricity 0 0 1 =4 The computer can continue like this for ever. and back again. just adding more wires when it gets bigger numbers.

512 64 8 1 So 117 (in denary) is 1 lot of 64.g. If you continue this the result (try it) is 16 1 8 0 4 1 2 0 1 1 So 117 (in denary) = 01110101 (in binary). Change 10110110 into denary. and repeat. 4. e.32 is less than 53. To turn a binary number into denary.3 . e. The value of this relationship is not important now. 64 1 8 6 1 5 Why bother with octal? Octal and binary are related. even the Babylonians’ sixties if you can learn the symbols. simply put the column headings above the binary number and add up all the columns with a 1 in them. but it is the reason why octal is in the syllabus. leaving another 53. so put a 1.4 . Fitting this in the columns gives 512 0 So 117 in denary is 165 in octal.g. If we take the three digits of the octal number 165 and turn each one into binary using three bits each we get 1 = 001 6 = 110 5 = 101 Put them together and we get 001110101 which is the binary value of 117 which we got earlier. If we count in eights (called the OCTAL system) the column headings go up in 8’s. 53 is 6 lots of 8 with 5 left over. 128 0 128 0 64 1 64 1 32 1 32 1 16 8 4 2 1 Take 32 from 53 = 21. Answer: 128 1 64 0 32 1 16 1 8 0 4 1 2 1 1 0 So 10110110 = 128 + 32 + 16 + 4 + 2 = 182 (in denary). This principle can be used for any number system.

so we use 6 that we already know. So a hexadecimal number BD stands for 11 lots of 16 and 13 units = 176 + 13 = 189 ( in denary) Note: B = 11. We could invent 6 more symbols but we would have to learn them. B stands for 11 and so on to F stands for 15. just use the same principles. Each digit is simply changed into a four bit binary number which are then placed after one another in order.g.4 . We need symbols going further than 0 to 9 (only 10 symbols and we need 16!). A barcode for chocolate looks like a number. 398602 in BCD Answer: 3 = 0011 9 = 1001 8 = 1000 6 = 0110 0 = 0000 2 = 0010 So 398602 = 001110011000011000000010 (in BCD) Note: All the zeros are essential otherwise you can’t read it back. This sounds very difficult. There is a problem with counting in 16’s instead of the other systems. 256 16 1 So 117 (in denary) is 7 lots of 16 (112) plus an extra 5. but it needn’t be. and a barcode for sponge cake looks like a number. which in binary = 1101 Put them together to get 10111101 = the binary value of 189. In hexadecimal A stands for 10. The arithmetic does not give a sensible answer.4 . octal and hexadecimal are all related in some way. Values like this that look like numbers but do not behave like them are often stored in binary coded decimal (BCD). but if the barcodes are added together the result is not the barcode for chocolate cake. Fitting this in the columns gives 256 0 16 7 1 5 Notice that 7 in binary is 0111 and that 5 is 0101. So binary. the letters A to F. e. which in binary = 1011 D = 13. Binary Coded Decimal Some numbers are not proper numbers because they don’t behave like numbers. put them together and we get 01110101 which is the binary value of 117 again. 4.Another system is called HEXADECIMAL (counting in 16’s).

4 (b) Negative Integers If a computer system uses a byte to store a number in the way that was suggested in 3. The example we used for binary storage was 117 which becomes 01110101 in binary. The second problem is not so easy to solve. how to represent fractions. these numbers need a second piece of data to be stored. There is still a limit on the size that can be represented.5 . so it stays as 01110101. Most computer systems use either two or four bytes to store a number. namely the sign. 4. If we want to store +117 or –117. There are two simple ways to store negative numbers. This means that +117 = 01110101 and -117 = 11110101 Notes: The range of numbers possible is now –127 to +127.3.4 . but later it becomes essential for making the arithmetic easier. The first is that the biggest number that can be represented is 255 because there aren’t enough bits to store bigger numbers. The byte does not represent just a number but also a sign. but it is now much larger. Use the first bit in the byte (the most significant bit (MSB)) to represent the sign (0 for + and 1 for -) instead of representing 128. Sign and Magnitude. The third problem is how to store negative numbers.a there are three problems that arise. this makes arithmetic difficult. Two’s Complement The MSB stays as a number.4. This is easily solved by using more than one byte to represent a number. This means that the column headings are -128 64 32 16 8 4 2 1 +117 does not need to use the MSB. -117 = -128 + 11 = -128 + (8 + 2 + 1) fitting this in the columns gives 10001011 Two’s complement seems to make everything more complicated for little reason at the moment. but is made negative. This will be looked at later in this chapter.

and the ability to take one away from another. To take one number away from another. Addition.4 . Answer: 91 = 01011011 -18 as a two’s complement number is –128 + 110 = -128 +(+64 +32 +8 +4 +2) = 11101110 Now add them 01011011 11101110 + 1 01001001 1 111111 But the answer can only be 8 bits.g. Work out 91 – 18 using their binary equivalents.6 . There are four simple rules 0+0=0 0+1=1 1+0=1 and the difficult one 1 + 1 = 0 (Carry 1) e.g. so cross out the 9th bit giving 01001001 = 64 + 8 + 1 = 73. but the same rules are used. The numbers and the answers will be limited to one byte.4 (c) Binary Arithmetic The syllabus requires the addition of two binary integers. This is where two’s complement is useful.3. simply write the number to be subtracted as a two’s complement negative number and then add them up. Add together the binary equivalents of 91 and 18 Answer: 91 = 01011011 18 = 00010010 + 01101101 = 109 1 1 Subtraction. 1+1+1 = 1 (carry 1) Things can get harder but this is as far as the syllabus goes. e. Notes: Lots of carrying here makes the sum more difficult. 4. One rule is extended slightly because of the carries.

in decimal notation. Here 0.23456 x 102.4 .23456 is called the mantissa and the number 2 is called the exponent. like 2. This form of representation is called floating point form. This means that we need only store.3.10101 is the mantissa and –11 is the exponent. Similarly. The number 0. in decimal.00010101 can be written as 0. Numbers that involve a fractional part. 0. the mantissa and the exponent. It is important that you understand this form of representing integers before you learn how to represent fractional numbers. in binary. 4.10101 x 2-11 and 0. This is what happens in binary.23456 and 2. the numbers 0.456 can be written as 0.246 and the exponent is –4.46710 and 101.10111 x 2101. Thus.7 .10111 x 25 or 0. consider the binary number 10111.10111 is the mantissa and 101 is the exponent.0000246 can be written 0. Now the mantissa is 0.246 x 10-4.01012 are called real numbers. In decimal notation the number 23. This could be represented by 0. 0. For example. It is now clear that we need to be able to store two numbers.4 (d) Floating Point Representation In the first part of this chapter we learned how to represent both positive and negative integers in two's complement form.

3. using 8 bits. using 8 bits for the mantissa and 8 bits for the exponent.00000101011 which is 0.1011 x 2100 and can be represented by 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 Mantissa Exponent Now find the two's complement of the mantissa and the result is 1 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 Mantissa Notice that the first two digits are different. is 11111011.11011 becomes 0. Care needs to be taken when normalising negative numbers. This is always done like this with positive numbers because it allows us to use the maximum number of digits. Again. The binary number 10. we have 0 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 Mantissa Exponent because the two's complement of –101. the point in the mantissa was always placed immediately before the first non-zero digit.101011 x 2-101.1011011 x 210 and can be held as 0 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 Mantissa Exponent Notice that the first digit of the mantissa is zero and the second is one. Now consider the binary number 0. Suppose we use 8 bits to hold the mantissa and 8 bits to hold the exponent. Thus the mantissa is 0.8 . Consider the binary number –1011.4 . Exponent 4.4 (e) Normalising a Real Number In the above examples.101011 and the exponent is –101. for a positive number. the first digit is always zero and the second is always one. The reason for normalising the mantissa is in order to hold numbers to as high a degree of accuracy as possible. The easiest way to normalise negative numbers is to first normalise the positive version of the number. The exponent is always an integer and is held in two's complement form. The mantissa is said to be normalised if the first two digits are different. The positive version is 1011 = 0. Thus.

1011 is 1.0001 + 0.01011 = 0.4 .0100 and –1 is 11111111 and we have 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 Mantissa Exponent The fact that the first two digits are always different can be used to check for invalid answers when doing calculations. change the decimal fraction –11/32 into a normalised floating point binary number.01 + 0.1011 x 2-1 Therefore –11/32 = -0.9 .As another example. 11/32 = 1/4 + 1/16 + 1/32 = 0.1011 x 2-1 Using two's complement –0.00001 = 0. 4.

0111111 x 210000000 = -0. the negative number furthest from zero) is 1.1000000 x 2-128 which is very close to zero.e. The first two digits must be different.1111111 and the largest positive number we can have for the exponent is 01111111.1000001 x 2-128 Note that we cannot use 1. The smallest positive mantissa is 0. This means that if we use more bits for the mantissa we will have to use fewer bits for the exponent. we have.0000000 x 2127 = -2127. The smallest negative number (i.e. This means that we have 0.1111111 x 21111111 = 0. for a positive number n.0000000 x 201111111 = -1. the computer uses the smallest positive number to represent zero. 2-129 ≤ n < 2127 and for a negative number n -2127 ≤ n < -2-129 4. Have you noticed that zero cannot be represented in normalised form? This is because 0. This represents 0. The largest negative number (i.1111111 x 2127 This means that the largest positive number is almost 1 x 2127. Thus.1000000 and the smallest exponent is 10000000. in fact it is 2-129.0000000 is not normalised because the first two digits are the same. Notice also that when we are talking size of number we mean the furthest to the left on a number line so -1 is a bigger number than -2.1000000 x 210000000 = 0.4 . The largest positive value we can have for the mantissa is 0. the negative number closest to zero) is 1.4 (f) Accuracy and Range There are always a finite number of bits that can be used to represent numbers in a computer.10 . Usually.3.1111111 for the mantissa because it is not normalised. Let us start off by using 8 bits for the mantissa and 8 bits for the exponent. Whereas. if we talk about largest magnitude negative number then the -2 is greater magnitude than -1 because the integer value is greater.

we shall have more binary places in the mantissa and hence greater accuracy.4 . We have increased the accuracy but at the expense of the range of numbers that can be represented. the range of values in the exponent is from –8 to +7 and this produces a very small range of numbers. That is. Similarly. 4. This will increase the number of bits in the mantissa that can be used to represent the number. However.11 . but we have a much greater range of values as the exponent can now take larger values.Now suppose we use 12 of the bits for the mantissa and the other four for the exponent. reducing the size of the mantissa reduces the accuracy.

12 .4 (g) Static and Dynamic Data Structures Static data structures are those structures that do not change in size while the program is running. there are some languages that do allow the size of arrays to be changed in which case they become dynamic data structures. A typical example is a linked list.4 .3.) Dynamic data structures can increase and decrease in size while a program is running. Storage no longer required can be returned to the system for other uses. Advantages Compiler can allocate space during compilation. A linked list only allows serial access. Makes efficient use of memory. (In fact. The following table gives advantages and disadvantages of the two types of data structure. Disadvantages Programmer has to estimate the maximum amount of space that is going to be needed. A typical static data structure is an array because once you declare its size. Only uses the space needed at any time. 4. Can be slow to implement searches. Easy to check for overflow. Can waste a lot of space. An array allows random access. Static structures Dynamic structures Difficult to program. it cannot be changed. Easy to program.

1 Data Now suppose we wish to insert an element between the second and third cells in the linked list.h. the algorithm must search the list to find the position for the new data.4.4. 4. 3.2.4.h.h.Insertion Consider Fig.1 which shows a linked list and a free list.2 The algorithm must check for an empty free list as there is then no way of adding new data.4 . The pointers have to be changed to those in Fig. HEAD Data Data Data Data FREE Data Data Data Fig. 3. It must also check to see if the new data is to be inserted at the front of the list. 3. 3. Head Data Data Data Data Free Data Data Fig.13 .4. The algorithm is given below.3. The linked list is created by removing cells from the front of the free list and inserting them in the correct position in the linked list.h. If neither of these are needed.4 (h) Algorithms Linked Lists .

If the list is empty report an error and stop. Check for an empty list by seeing if HEAD is NULL 7. 6.3. 8. 4. 3. 11. b. Set TEMP to pointer in PREVIOUS. Set HEAD to NEW and stop 9. 3.4. Set pointer in PREVIOUS equal to pointer in cell to be deleted. 3.4. report an error and stop. Search list to find the cell immediately before the cell to be deleted and call it PREVIOUS.h.4 . 5. 5.4. Copy data into cell pointed to by NEW. Make the pointer in PREVIOUS equal to NEW 12.Check that the free list is not empty. 3. Set NEW to equal FREE. Set pointer in cell pointed to by NEW to HEAD. Set FREE equal to TEMP and stop. Copy the pointer in PREVIOUS into TEMP. Head Data Data Data Data Free Data Data Fig. Set HEAD to NEW and stop. Call this cell PREVIOUS.h.1. 3.Deletion Suppose we wish to delete the third cell in the linked list shown in Fig. 6. Linked Lists . If data is less than data in first cell THEN a.h.3 Data In this case. 2. The result is shown in Fig. Set pointer in cell to be deleted equal to FREE. 1. 1. 8.14 . 2. 4. 10. Check that the list is not empty. Pointer in cell pointed to by NEW is set to NULL b. If HEAD is NULL then a. If the cell is not in the list. Make the pointer in the cell pointed to by NEW equal to TEMP and stop. 7. Remove the node from the stack by setting FREE to pointer in cell pointed to by FREE. 4. the algorithm must make sure that there is something in the list to delete. Search list sequentially until the cell found is the one immediately before the new cell that is to be inserted. If it is empty report an error and stop.

Searching Assuming that the data in a linked list is in ascending order of some key value. 4.4 . Set POINTER equal to HEAD REPEAT Set NEXT equal to pointer in cell pointed to by POINTER If new data is less than data in cell pointed to by POINTER then set POINTER equal to NEXT UNTIL Note: A number of methods have been shown here to describe algorithms associated with linked lists.Amendment Amendments can be done by searching the list to find the cell to be amended. An algorithm does not have to be in pseudo code. If the list is empty report an error and stop. The algorithm is 1. Linked Lists . Check that the list is not empty. Search the list to find the cell to be amended. the following algorithm explains how to find where to insert a cell containing new data and keep the list in ascending order.Linked Lists . Stop. 2. indeed.15 . It assumes that the list is not empty and the data is not to be inserted at the head of the list. Any method is acceptable provided it explains the method. 3. the sensible way of explaining these types of algorithm is often by diagram. Amend the data but do not change the key. 4. 5.

2.4 The algorithm for insertion is 1. 4.h. Stacks – Deletion When an item is deleted from a stack. the item's value is copied and the stack pointer is moved down one cell. 3. If we are to insert an item into a stack we must first check that the stack is not full. 3. Remember.Stacks – Insertion Fig. Insert new data item into cell pointed to by the stack pointer and stop. the pointer is zero. Stack Data Data Data Data Fig. when the stack is empty. If the stack is full report an error and stop. Pointer to Top of stack Top of stack Check to see if stack is full. This method assumes that the cells are numbered from 1 upwards and that. These are the only two operations you can perform on a stack.16 . The data itself is not deleted. Check to see if the stack is empty.4 shows a stack and its head pointer. Copy data item in cell pointed to by the stack pointer. The algorithm for deletion is 1. Having done this we shall increment the pointer and then insert the new data item into the cell pointed to by the stack pointer.4 . 4. we must check that the stack is not empty before trying to delete an item. a stack is a last-in-firstout (LIFO) data structure.4. Decrement the stack pointer and stop. 4.h. If the stack is empty report an error and stop. Increment the stack pointer. 3. 2.4. This time. 3.

Remember.Insertion Fig.5 shows a queue and its head and tail pointers. this will occur when the head and tail pointers point to the same cell. Check to see if queue is full. a queue is a first-in-first-out (FIFO) data structure. These are the only two operations that can be performed on a queue. This method assumes that the cells are numbered from 1 upwards and that. 3.h. 3. 3. 3. Check to see if the queue is empty.h. 2.Deletion Before trying to delete an item.4. when the queue is empty. Tail pointer Queues .Queues .17 . 4. Having done this we shall increment the pointer and then insert the new data item into the cell pointed to by the head pointer. Copy data item in cell pointed to by the tail pointer. 2. Head pointer Data Data Data Data Fig.4. the two pointers point to the same cell. Insert new data item into cell pointed to by the head pointer. Increment the head pointer and stop. The algorithm for deletion is 1. 4. If we are to insert an item into a queue we must first check that the stack is not full. If the queue is empty report error and stop. Increment tail pointer and stop.5 The algorithm for insertion is 1. 4. we must check to see that the queue is not empty. If the queue is full report an error and stop. Using the representation above.4 .

4.1. could comes before Jack. Jack could Spratt eat no fat Fig.i. If the new value is less than the value at the node move left.4. Current node = root. If tree is empty enter data item at root and stop. Insert a new node at this point and enter the data. it's after could so go right. If new data item is less than value at current node go left else go right.i.4 . 3. Create new node and enter data. 3. 4. 6. To add a new value. Current node = node reached (null if no node).3. Spratt comes after Jack so go right and enter Spratt. Repeat steps 4 and 5 until current node is null.Insertion When inserting an item into a binary tree. otherwise move right.4. Consider the tree shown in Fig.4 (i) Algorithms for Trees Trees .1 showing a tree containing data that is stored according to its alphabetic order. This is continued to produce the tree in Fig. 2. 5. Repeat this for each node arrived at until there is no node. 3. so go left and enter could. 3. Jack must be the root of the tree. it is usual to preserve some sort of order.1 The algorithm for this is 1. Now let's try putting "Jack Spratt could eat no fat" into a tree.18 . eat is before Jack so go left. we look at each node starting at the root. 4.i.

and is less than could so go left.2. 3. Current node contains could. The diagram with the dashed line would be read as Could. 6. 3. Eat.i. Current node is null. 4.19 . 5. No.i. Spratt Note that the words are now in alphabetic order.Using this algorithm and adding the word and we follow these steps. Jack could Spratt and eat no fat Fig. Node is not null. There are many different ways of reading the values from a tree. The tree is not empty so go to the next step. Create new node and insert and and stop. but the simplest is the one illustrated by the dashed line in the diagram above. Jack. using the algorithm Follow left subtree Read node Follow right subtree Return The values can be read in order. Fat. 3.4.4 . 4. We now have the tree shown in Fig. 3. 2. Current node contains Jack. It is also the only way that you will be asked to read a tree in an examination. Current node is null so exit loop. Node is not null.2 If the values are read from the left to the right. 3. 1. 5. and is less than Jack so go left. 4.4.

if there are n values in the list. Anne Bhari Chu Diane Now we only have a list of four entries. We now compare Chu with Bhari and find that Chu is greater than Bhari so we use the list Chu Diane which is half the length of the previous list. you will look at n/2 values each search. In this case Diane and Ejo are both near the middle. particularly if there are a large number of values. Comparing Chu with Chu we have found the position we want. if n is large. Clearly. As Chu is before Diane. You must also be able to report that a value has not been found in some circumstances. It does not expect the data to be in any particular order. These methods are the serial search and the binary search. However.4 (j) Searching Methods There are many different methods of searching but only two will be considered here.20 . in this case we usually take the smaller value.4 . This method can be very slow. Anne Bhari Chu Diane Ejo Frank Gloria Hazel Suppose we wish to find the position of Chu. 4. That is we have halved the length of the list. The least number of comparisons is one. To find the position of a particular value involves looking at each value in turn and comparing it with the value you are looking for. this occurs if the first item in the list is the one you want. The serial search expects the data to be in consecutive locations such as in an array. Now compare Chu with the value that is in the middle of the table. Now suppose the list is sorted into ascending order as shown below. you will need to make n comparisons if the value you want is the last value. we now look only at this list. When the value is found you need to note its position. This has only taken three comparisons.3. on average. This means that. this can be a very large number of comparisons.

We must also make sure that. Serial Search Let the data consist of n values held in an array called DataArray which has subscripts numbered from 1 upwards. The algorithm to find the position of X is 1. Report error. if we use the second list (cells 5 to 8). dividing by two will give a whole number and this will tell us where to split the list. the first cell stays at 1 but the last cell becomes 4. array is empty. Suppose we have a list of eight values. but are included here because the authors are aware that some students are interested in the more formal solutions to problems.21 . 4. If n < 1 then report error. the first cell in the new list is unchanged but the last is changed. 2. if we move into the first list (cells 1 to 4). make sure that all the lines are indented. We must split the lists in two. Now. X is not in the array and stop. That is the first cell was 1 and the last cell was 8. the first cell is changed but the last is not changed. Find the mid-point cell in the current list. This means that if we use the first list. when we split a list in two. When we started we needed to consider the list in cells 1 to 8. Binary Search Assume that the data is held in an array as described above but that the data is in ascending order in the array. The formal algorithms for these searching techniques are not necessary as part of the syllabus. the data must first be sorted and this can take some time. as an array subscript must be an integer.4 . For i = 1 to n do a. Splitting this gives a list of the four values in cells 1 to 4 and four values in cells 5 to 8. Here is the binary search algorithm. Let X be the value we are trying to find. However. However. If there is more than one operation to perform inside a loop. if the list consists of an odd number of values we will need to find the integer part of it. However.4 (j) is not part of the CIE syllabus but is included here for interest sake only. It must be stressed that the remainder of this section 3.Clearly. We must check that the array is not empty before starting the search. if we use the second list. If DataArray[i] = X then return i and stop. Similarly. this is more efficient than the serial search method. we use the correct one for the next search. 3. This gives us the clue of how to do the sort. the first cell becomes 5 and the last is still 8. If there is an even number of values. Note that the for loop only acts on the indented line. 1. While the list is not empty do a.

Mid Found = TRUE ENDIF ENDIF ENDWHILE IF NOT Found THEN {Unsuccessful search} Output 'Value not in the list' ENDIF END 4. A more detailed algorithm is given below that is useful f you wish to program the binary search. Make the search list the first half of the current search list d. item not in the list. Binary Search Algorithm In this algorithm. c. 2. Report error. If the value in this cell is the required value. You would not be expected to be able to reproduce this during an examination.b.4 .22 . {Initialisation} First = 1 Last = n Found = FALSE {Perform the search} WHILE First <= Last AND NOT Found DO {Obtain index of mid-point of interval} Mid = INT(First + Last) / 2 {Compare the values} IF X < Vector[Mid] THEN Last = Mid – 1 ELSE IF X > Vector[Mid] THEN First = Mid + 1 ELSE Output 'Value is at '. X is the value we are trying to find and n is the number of values in the array. If the value to be found is less than the value in the mid-point cell then i. Vector is a one-dimensional array that holds the data in ascending order. return the cell position and stop. Else make the search list the second half of the current search list.

3.4 (k)

Sorting and Merging

Sorting is placing values in an order such as numeric order or alphabetic order. The order may be ascending or descending. For example the values 3 5 6 8 12 16 25 are in ascending numeric order and Will Rose Mattu Juni Hazel Dopu Anne are in descending alphabetic order. Merging is taking two lists which have been sorted into the same order and putting them together to form a single sorted list. For example, if the lists are Bharri Emi Kris Mattu Parrash Roger Will and Annis Chu Liz Medis Ste when merged they become Annis Bharri Chu Emi Kris Liz Mattu Medis Parrash Roger Ste Will There are many methods that can be used to sort lists. You only need to understand two of them. These are the insertion sort and the merge sort. This Section describes the two sorts and a merge in general terms; the next Section gives the algorithms. Insertion Sort In this method we compare each number in turn with the numbers before it in the list. We then insert the number into its correct position. Consider the list 20 47 12 53 32 84 85 96 45 18 We start with the second number, 47, and compare it with the numbers preceding it. There is only one and it is less than 47, so no change in the order is made. We now compare the third number, 12, with its predecessors. 12 is less than 20 so 12 is inserted before 20 in the list to give the list 12 20 47 53 32 84 85 96 45 18 This is continued until the last number is inserted in its correct position. In Fig. 3.4.k.1 the blue numbers are the ones before the one we are trying to insert in the correct position. The red number is the one we are trying to insert.

4.4 - 23

20 47 12 53 32 84 85 96 45 18 Original list, start with second number. 20 47 12 53 32 84 85 96 45 18 No change needed. 53 32 84 85 96 45 18 Now compare 12 with its predecessors. 12 20 47 53 32 84 85 96 45 18 Insert 12 before 20. 12 20 47 53 32 84 85 96 45 18 Move to next value. 12 20 47 53 32 84 85 96 45 18 53 is in the correct place. 12 20 47 53 32 84 85 96 45 18 Move to the next value. 12 20 32 47 53 84 85 96 45 18 Insert it between 20 and 47 12 20 32 47 53 84 85 96 45 18 Move to the next value. 12 20 32 47 53 84 85 96 45 18 84 is in the correct place. 12 20 32 47 53 84 85 96 45 18 Move to the next value. 12 20 32 47 53 84 85 96 45 18 85 is in the correct place. 12 20 32 47 53 84 85 96 45 18 Move to the next value. 12 20 32 47 53 84 85 96 45 18 96 is in the correct place. 12 20 32 47 53 84 85 96 45 18 Move to the next value. 12 20 32 45 47 53 84 85 96 18 Insert 45 between 32 and 47. 12 20 32 45 47 53 84 85 96 18 Move to the next value. 12 18 20 32 45 47 53 84 85 96 Insert 18 between 12 and 20. Fig. 3.4.k.1 Merging Consider the two sorted lists 2 4 7 10 15 and 3 5 12 14 18 26

In order to merge these two lists, we first compare the first values in each list, that is 2 and 3. 2 is less than 3 so we put it in the new list. New = 2 Since 2 came from the first list we now use the next value in the first list and compare it with the number from the second list (as we have not yet used it). 3 is less than 4 so 3 is placed in the new list. New = 2 3 As 3 came from the second list we use the next number in the second list and compare it with 4. This is continued until one of the lists is exhausted. We then copy the rest of the other list into the new list. The full merge is shown in Fig. 3.4.k.2. First List 2 4 7 10 15 2 4 7 10 15 2 4 7 10 15 Second List 3 5 12 14 18 26 3 5 12 14 18 26 3 5 12 14 18 26 New List 2 2 3 2 3 4

4.4 - 24

2 2 2 2 2 2 2 2

4 4 4 4 4 4 4 4

7 7 7 7 7 7 7 7

10 10 10 10 10 10 10 10

15 15 15 15 15 15 15 15

3 3 3 3 3 3 3 3

5 5 5 5 5 5 5 5

12 12 12 12 12 12 12 12

14 14 14 14 14 14 14 14

18 18 18 18 18 18 18 18

26 26 26 26 26 26 26 26

2 2 2 2 2 2 2 2

3 3 3 3 3 3 3 3

4 4 4 4 4 4 4 4

5 5 5 5 5 5 5 5

7 7 7 7 7 7 7

10 10 10 10 10 10

12 12 12 12 12

14 14 15 14 15 18 14 15 18 26

Fig. 3.4.k.2

4.4 - 25

3.4 (l)
Insertion Sort

Sorting Algorithms

The following is an algorithm for the insertion sort. {Look at each card in turn, starting with the second card} FOR Position = 2 to n DO CurrentValue = Vector[Position] {Keep value of current number} {and store it in position 0} Vector[0] = CurrentValue {Now look at each number to the left of current number (Position – 1) and move each number right if it is greater than CurrentValue. If the number is not greater than CurrentValue, insert CurrentValue.} Pointer = Position - 1 WHILE Vector[Pointer] > CurrentValue DO Vector[Pointer + 1] = Vector[Pointer] {Move left one place} Pointer = Pointer – 1 ENDWHILE Vector[Pointer + 1] = CurrentValue ENDFOR END

4.4 - 26

VectorC) I=J=K=1 WHILE I ≤ M AND J ≤ N DO IF VectorA(I) < VectorB(J) THEN VectorC(K) = A(I) I=I+1 K=K+1 ELSE IF VectorA(I) > B(J) THEN VectorC(K) = VectorB(J) J=J+1 K=K+1 ELSE VectorC(K) = VectorA(I) I=I+1 J=J+1 K=K+1 ENDIF ENDIF ENDWHILE IF I > M THEN FOR R = J TO N STEP 1 DO VectorC(K) = VectorB(R) K= K + 1 NEXT R ELSE FOR R = I TO M STEP 1 DO VectorC(K) = VectorA(R) K=K+1 NEXT R ENDIF END 4.4 . Merge(VectorA. VectorB. VectorA and VectorB have been sorted into ascending order and if there are any duplicates they are only copied once into VectorC.Merging The following algorithm merges two sets of data that are held in a two onedimensional arrays called VectorA[1 to M] and VectorB[1 to N] into a third onedimensional array called VectorC.27 .

4 .4 (i) for the simple algorithm to turn the items in a binary tree into a sorted list. 4.28 .3.4 (m) Sorting using a Binary Tree See the end of section 3.

a) Express the number 113 (denary) in (i) binary (ii) in BCD using an appropriate number of bytes in each case. Eda. (4) 2. Gali in alphabetic order. using single byte arithmetic. (ii) state the most negative value that can be stored. (4) 7.4 . Joh. Sean. Dav. (3) 8. (4) 4. State the difference between dynamic and static data structures giving an example of each. using a single byte for each answer. (4) b) Using the answer obtained in part (a) show how 113 (denary) can be expressed in (i) octal (ii) hexadecimal. 5.3. (4) Add together the binary equivalents of 34 and 83. a) A floating point number is represented in a certain computer system in a single 8 bit byte. (i) State the smallest positive value. (2) 3. a) Show how a binary tree can be used to store the data items Feddi.29 . (1) 6. 4. Explain how the denary number –27 can be represented in binary in (i) sign and magnitude (ii) two’s complement notation. (4) a) Explain how the fraction part of a real number can be normalised. b) State the benefit obtained by storing real numbers using normalised form. Give each answer as an 8 bit binary value and as a decimal equivalent. (4) b) Explain why problems may arise if Joh is deleted from the tree and how such problems may be overcome. (3) Describe a floating point representation for real numbers using two bytes.4 Example Questions 1. (4) b) Explain the relationship between accuracy and range when storing floating point representations of real numbers. Both are stored in two’s complement form and the mantissa is normalised. 5 bits are used for the mantissa and 3 bits for the exponent. showing you working.

giving an indication of when it would be advisable to use each. Describe two types of search routine. 4. 11.30 . (6) 10.4 . (6) Describe the steps in sorting a list of numbers into order using an insertion sort. (4) Given two sorted lists describe an algorithm for merging them into one sorted list.9.

5 . Examiners will use your code to see if you understand the question and can explain your answer.5 Programming Paradigms 3. you may well find it helpful. treat the code in this Chapter simply as an explanation of the different facilities in different programming paradigms. Thus.1 .5 Introduction This Chapter uses a number of different programming languages to illustrate the points being explained.Chapter 3. the accuracy of the syntax will not be marked. This is perfectly satisfactory. However. indeed it will often help you to clarify what you are saying. to include code in your answers. in answering examination questions. 4. Do not think that you have to be able to program in all the languages used in the following Sections. If you do write code. You will not be asked to write program code in the examination.

5 (a) Programming Paradigms Programming paradigms are simply methods of programming. Initially. FORTRAN (FORmula TRANslation) and ALGOL (ALGOrithmic Language) were developed mainly for scientific and engineering problems. X: Y: Z: 4. It uses terms like file. BASIC (Beginners All purpose Symbolic Instruction Code) was developed to enable more people to write programs. That is.1 Although this assembly language is an improvement over machine code. exactly the procedure that should be followed to solve a problem. All these languages follow the procedural paradigm.a.5. this is a very low-level programming paradigm.2 . move and copy. Smalltalk and Java) were developed.a. once an object is fully working. data and methods of manipulating the data. These replaced machine code functions with mnemonics and addresses with labels. This was difficult and led to many errors that were difficult to find. Assembly language programming is also a low-level paradigm although it is a second generation paradigm. The problem with procedural languages is that it can be difficult to reuse code and to modify solutions when better methods of solution are developed. The next advance was the development of procedural languages. are kept as a single unit called an object. In order to address these problems. correct and maintain. The only way that a user can access the data is via the object's methods. It also means that the internal workings of an object may be changed without affecting any code that uses the object. For example. Although one of the ideas behind the development of ALGOL was that it was an appropriate language to define algorithms. COBOL (Common Business Oriented Language) uses the language of business. object-oriented languages (like Eiffel. This means that. Label Function LDA ADD STA STOP 20 35 Address Comments X Load the accumulator with the value of X Y Add the value of Y to the accumulator Z Store the result in Z Stop the program Value of X = 20 Value of Y = 35 Location for result Figure 3. Programs written in binary are said to be written in machine code. assembly languages were developed. These languages are problem oriented as they use terms appropriate to the type of problem being solved. In these languages. Figure 3.1 shows an assembly language program that adds together two numbers and stores the result.3.5 . These are third generation languages and are also known as high-level languages. it is still prone to errors and code is difficult to debug. step by step. it cannot be corrupted by the user. they describe. computers were programmed using binary. To make programming easier.5.

Given a database the computer searches for a solution. In these languages the computer is told what the problem is. The computer is not given a procedure to follow as in the languages discussed so far.A further advance was made when declarative programming paradigms were developed.5 .3 . 4. not how to solve the problem.

a typical piece of code could be switch (UserChoice) { case 'A': cout << "A is for Apple. cout << "Enter the breadth: ". case 'C': 4. exactly. Read the length Read the breadth Multiply the length by the breadth Output the result In C++ this can be coded as cout << "Enter the length: ". For example.".".4 . break. cin >> Length. suppose a user enters a single letter and the output depends on that letter.5 (b) Programming Paradigms and examples. we have IF (Number > 0) cout << "The number is positive. ELSE cout << "The number is negative. For example. ELSE { IF (Number = = 0) cout << "The number is zero.". Here each line of code is executed one after the other in sequence. the steps required to solve a problem. Most procedural languages have two methods of selection. 2. 4. case 'B': cout << "B is for Banana. 3. cout << "The area is " << Area << endl. in C++.". to find the area of a rectangle the steps are 1. break. Area = Length * Breadth. cin >> Breadth. selection and repetition (see Section 1.5 . } In C++ multiple selections can be programmed using the SWITCH statement.3 in the AS text). These languages use the constructs: sequence. Procedural languages specify. For example. These are the IF … THEN … ELSE statement and the SWITCH or CASE statement.".3.

//Using a WHILE loop Sum = 0. Some of these languages are more robust than others.". As stated earlier. } cout << "The sum is " << Sum.5 .5 . i++) { Sum = Sum + i. The following pieces of C++ code add the first ten positive integers. while (i <= 10) { Sum = Sum + i. } cout << "The sum is " << Sum.cout << "C is for Cat. The use of functions and 4. } Repetition (or iteration) is another standard construct. FOR (int i = 1. i = 1. The point to note with these procedural languages is that the programmer has to specify exactly what the computer is to do. Procedural languages are used to solve a wide variety of problems. This means that the compiler will not let the programmer write statements that may lead to problems in certain circumstances. Most procedural languages have many forms of this construct such as FOR … NEXT REPEAT … UNTIL … WHILE … ENDWHILE A typical use of a loop is to add a series of numbers. i <= 10. break. //Using a FOR loop Sum = 0. Procedural languages may use functions and procedures but they always specify the order in which instructions must be used to solve a problem. there are procedural languages designed to solve scientific and engineering problems while others are more suitable for solving business problems.". default: cout << "I don't recognise that letter. There are some that are particularly designed for solving problems of control that need real time solutions. i++.

//All programs have to have a main method public static void main(String [ ] args) { //Start the programm from its constructor new Shapes ( ). These were true object-oriented languages. Although OOP languages are procedural in nature. That is. is an object. This slowed the development of OOP. registration number S123KAY. had become well established. as memory became cheaper and CPUs more powerful.write( ). In the 1970s it was realised that code was not easily reused and there was little security of data in a program.write( ).procedures help programmers to reuse code but there is always the danger of variables being altered inadvertently. with a syntax similar to C++. }//end of main method. engine capacity. My car. }//end of constructor Shapes. the real world consists of objects not individual values. medium = new Rectangle(10.5 . C++ also includes classes although the programmer does not have to use them. 25). Both of these objects are cars and cars have similar attributes such as registration number. large. By the 1980s Smalltalk. The following is an example. large. is another object. is a fully object-oriented language. //Print the details of the rectangles small. OOP requires a large amount of memory and. 5). However. of a class that specifies a rectangle and the methods that can be used to access and manipulate the data.out. 100).println("The areas of the rectangles are:\n"). using Java. class Shapes { /* Shapes Version 1 by Roger Blackford July 2001 ---------------------------------------------------------This illustrates the basic ideas of OOP */ // Declare three object variables of type Rectangle Rectangle small.6 . In order to model the real world. This means that C++ can be used as a standard procedural language or an object-oriented language or a mixture of both! Java.write( ). Also. the Object-oriented Programming (OOP) paradigm was developed. medium. OOP is considered to be a new programming paradigm. OOP became more popular. Kay's car. and so on. colour. my car and Kay's car are instances of a class called cars. //Print out a header System. registration number W123ARB. large = new Rectangle(50. memory was expensive and CPUs still lacked power. Unfortunately. in the 1970s. and later Eiffel. // Create a constructor where the initial work is done Shapes ( ) { // Create the three rectangles small = new Rectangle(2. 4. medium.

Here small is given a width of 2 and a length of 5. class Rectangle { //Declare the variables related to a rectangle int length. More details of Object-oriented Programming will be given in Section 3. This method has to be used to output the details of the rectangles. This is a declaration and does not assign any values to these objects. small. which has the same name as the class. Java simply says that. The latter is achieved by calling the write method. }//end of constructor This example contains two classes. The class Shapes has a constructor called Shapes. The class Rectangle also has a method called write( ). they have null values. The class Rectangle has a constructor that assigns values to width and length and then calculates the area of the rectangle. In fact.7 . small. its constructor then prints a heading and the details of the rectangles. //Calculate the area area = width * length.5 .5. length = l. for example. Later. It is from here that the program will run. medium is given a width of 10 and a length of 25 and large is given a width of 50 and a length of 100.println("The area of a rectangle " + width + " by " + length + " is " + area). the class constructor. 4. The first is called Shapes and is the main part of the program.f. }//end of write method. which declares two objects of type Rectangle. Remember. medium and large are objects of the Rectangle class.}//end of class Shapes. int area.write( ) will cause Java to look in the class called Rectangle for a write method and will then use it. int l) { width = w. }//end of constructor Rectangle //Create a method to output the details of the rectangle void write ( ) { System. The second class is called Rectangle and it is a template for the description of a rectangle. In the class Shapes. //Create a constructor that copies the initial values into the object's variables Rectangle (int w. the new statement creates actual rectangles. int width.out. at this stage. When a new object is created from a class. is called. This means that.

The output is True if a. the following returns the square of a number. in the language "Haskell". All programs consist of a series of functions that use parameters for input and pass values to other functions. Then (a = = b) and (b = = c) are both False. b = 5 and c = 7. b and c are not all the same. square n = n * n says that the function requires the value of n as input and outputs n * n. b = 5 and c = 5. (iii) a = 5. square :: Int → Int square n = n * n is a function that squares a number. min2 :: Int → Int → Int min2 x y | x <= y =x | otherwise = y 4. There are no variables like the ones in procedural languages.8 . You should find that (i) and (ii) give an output of True and (iii) gives an output of False. like procedural languages. However. See what happens if (i) a = 2. (ii) a = 2. Hence not (( a = = b) && (b = = c)) is True. Therefore (a = = b) && (b = = c) is False. the programmer has to tell the computer the precise steps to be taken to solve a problem. square :: Int → Int says that we have a function called square that takes an integer as input and outputs an integer. Most functions use guards to determine the output. Consider the following example. For example. Suppose a = 2.The functional programming paradigm provides a very high level view of programming. b = 2 and c = 3. b = 3 and c = 3. different takes three integers as input and outputs a Boolean value True or False. Another example is different :: Int → Int → Int → Bool different a b c = not (( a = = b) && (b = = c)) Here.5 .

But we already have solutions to these problems so why not use them and we have min4 :: Int → Int → Int → Int → Int min4 a b c d = min2 a (min3 b c d) This is simply the use of step-wise refinement/top-down design as explained in Section 1.3 in the AS text. Suppose we wish to find the minimum of four integers.Here | x <= y is a guard. If x <= y is False. If x <= y and x <= z then x must be the minimum and the function outputs x and stops. If this returns a True value. the function outputs x and ends.5 . However. The function first checks to see if x <= y is True. If the guard returns a False value. y is output. Traditionally this could be written (in Visual Basic) as sum = 0 For count = 1 to n sum = sum + count Next count This may also be written in Haskell as sum :: Int → Int sum n |n = 1 =1 4. There are many ways of doing this but they all consist of sub-problems. The second guard checks this. It in fact outputs the minimum of three integers. if this is not true. Now consider this function min3 Int → Int → Int → Int min3 x y z | x <= y && x <= z =x | y <= z =y | otherwise =z Here the function is expecting three integers as input and outputs an integer. The trick is to keep breaking a problem down into sub-problems until the sub-problems can be solved by using simple functions. Functional programming can be very powerful. If it is. x is not the minimum therefore y or z must be the minimum. Haskell moves to the next line and checks the guard.9 . One algorithm is min of a b c d = min of (a and (min b c d)) This uses two functions namely the minimum of three integers and the minimum of two integers. Another facility of functional programming that makes it a powerful programming paradigm is the use of recursion. So the function outputs y. the function continues and outputs z. In this case there is no guard. Consider the problem of finding the sum of the first n integers.

output 1. Declarative languages tell the computer what is wanted but do not provide the details of how to do it.cs. The first guard says that if the input integer is 1. The method is also used in robot control.1. Diagrammatically we have sum 3 | 3 =1 False | otherwise = 3 + sum 2 → sum 2 |2 = 1 False | otherwise = 2 + sum 1 → sum 1 | 1 = 1 True =1 =2+1 =3 =3+3 =6 The combination of step-wise refinement and recursion means that functional programming is a very powerful tool. then output n plus the value of sum (n – 1). An example of a declarative language is Prolog. Now consider the call sum 3. Because a program written in a functional language consists only of functions it means that the program can be mathematically proved to be correct.b. The idea behind declarative languages is shown in Fig. Another programming paradigm is the declarative one. airline scheduling and compiler writing.5 .h. Then sum (n – 1) calls the same function but with the input being 1 less than the last call. These languages are particularly useful when solving problems in artificial intelligence such as medical diagnosis. If this guard is False.| otherwise = n + sum (n-1) This is simply saying that the function sum expects an integer as input and outputs an integer. fault finding in equipment and oil exploration. This is repeated until the input is reduced to 1 when a value of 1 is output. More powerful features of functional programming will be addressed in Section 3.10 .bell-labs.B www. Common problems that have been solved using this paradigm are telecomm switching.5. This means that very reliable programs can be written. N. control of robots.com/who/wadler/realworld/ is worth a visit as it describes real world problems that have been solved using functional programming. 3.5. 4.

female(anne). male(jaz).11 . which then searches the database for the answers and returns them to the user. Note that in Prolog values start with a lowercase letter and variables start with an uppercase letter.User Search Engine Database Fig.1 Here the user inputs a query to the search engine.5 . female(sandip). male(tom). male(charnjit). In a procedural language the database may be held in a twodimensional array Gender as shown below. using Prolog. will return X = charnjit X = jaz X = tom Notice that the user does not have to tell Prolog how to search for the values of X that satisfy the query. suppose the database is female(jane). A user may want to know the names of all the males. 4. The query male(X). 3.b.5. For example.

However.12 . _ ). The result is X = charnjit Y = mary X = charnjit Y = rajinder X = jaz Y = atif If we only want a list of fathers we use the underscore and create the query parent(X. atif). we can simply write parent(X. parent(charnjit. In Prolog we use the query parent(X. and suppose we wish to know the name of the mother of Atif. Prolog will output X = sandip Try writing a Visual Basic program to do this. parent(sandip. male(X). parent(jane. parent(charnjit.5 . suppose we now add to the Prolog database the following data. atif). 1 female female female male male male 2 Jane Anne Sandip Charnjit Jaz Tom 4.Print Gender[count. To get a list of all the fathers. 1] = "male" Then picResults. female(X).mary). atif). parent(jane. 2] End If This is fairly straightforward. male(X). Y). rajinder). mary). parent(jaz. rajinder).Array Gender 1 2 3 4 5 6 In Visual Basic we could write For count = 1 To 6 If Gender[count.

5. There are no FOR … NEXT.13 . Examples of rules will be given in Section 3.and the result is X = charnjit X = charnjit X = jaz Further examples are given in Section 3. There is no IF … THEN … statement.5 . WHILE … DO … or REPEAT … UNTIL … loops as such.g. At this stage the important point is that the programmer does not have to tell the computer how to answer the query. Examples of facts are given above. The system simply consists of a search engine and a database of facts and rules. 4.g.5.

5.1. This process is called step-wise refinement or top-down design.3 Calculate deductions 1.2.5 Output wages slip Either of these designs can be turned into a series of functions and procedures. The program could be called Wages and consist of the following functions and procedure.5 .2 Calculate other deductions 1. The worker is paid 6.5 (c) Structured Design A complex problem needs to be broken down into smaller and smaller sub-problems until all the sub-problems can be solved easily. Wages Get number of hours Calculate gross pay Calculate deductions Calculate net pay Output wage slip Calculate normal wages Calculate overtime Calculate tax Calculate Others Fig. 3. 1.5.2.3.2 Calculate overtime 1.3. 4. Tax and other contributions have to be deducted.50 per hour for up to 40 hours and time-and-a-half for all hours over 40.1 Get number of hours 1.c.14 .4 Calculate net pay 1.2 Calculate gross pay 1.1 An alternative way of writing this is to use numbered statements. This can be easier if there are many sub-problems to be solved. Wages 1. 3.1 Calculate normal wages 1.1 Calculate tax 1.c. This can be represented by Fig. Consider the problem of calculating the wages for an hourly paid worker.3.

a procedure should be used. Get number of hours Calculate gross pay Calculate deductions Calculate net pay Output wage slip 4. This is true in all languages.5 .c. A function has to be typed. NetWage) Procedure to print the wage slip Here we can see that if a single value is to be returned. Others. If there are no values to be returned. its return type is void. That is. Tax.5. That is. if a function is not going to return a value. If more than one value is to be returned.15 . GrossWage.d. Deductions) returns net wage after deductions Procedure OutputResults(Hours. 3. we may have Int GetHours( ) or GetHours( ) As Integer These statements state that the function will return an integer value and it does not expect any values to be fed into it. the simplest way to do this is to use a function. C++ or Java. no value is actually returned. the programmer must specify the type of value to be returned. Another type of diagram is used with the Jackson Structured Programming (JSP) technique.1 shows the sequence of steps. These languages only use functions. Fig. in the above. Note: If you are programming in C. then a procedure should be used.5. Double CalculateNormalWages(Int Hours) or CalculateNormalWages(Hours As Integer) As Double expects to be given an integer value as input and returns a value of type Double. there are no procedures. For example. Parameters will be discussed further in Section 3. C++ and Java. Deductions.Wages GetHours( ) returns an integer in range 0 to 60 CalculateWages(Hours) returns gross wage CalculateNormalWages(Hours) returns wage for up to 40 hours CalculateOvertime(Hours) returns pay for any hours over 40 CalculateDeductions(GrossWage) returns total deductions CalculateTax(GrossWage) returns tax due CalculateOthers(GrossWage) returns other deductions due CalculateNetWage(GrossWage. In C.

WHILE … DO … . Fig.c. etc. A Condition Else BO Fig. The asterisk is used to indicate that B is an iterative process. 3. 3.16 .5.5 . The third level shows that the red component consists of many (which may be zero) cards.c.5.c.c. B has to be repeated.3.c. 3. Note the use of a circle inside the boxes to indicate that the operations B and C are conditional.4 shows this.Calculate gross pay consists of the sequence Calculate normal wages Calculate overtime Calculate deductions consists of the sequence Calculate tax Calculate Others The diagram does not illustrate selection (IF … THEN … ELSE …) nor does it show repetition (FOR … DO … . Fig. the second layer shows that the pack is divided into red and black components.2 shows selection in JSP design.).5.3 Initially we shall consider diagrams that represent data.5.5.2 CO Repetition (also known as iteration) is shown in Fig. The top level shows we are using a pack. 3. Similarly. A B * Fig. 3. black consists of many cards. Consider a pack of ordinary playing cards which has been divided into red and black suits. that is. 4.

3.5. The data structure is shown in Fig.5 Now suppose we deal a hand of cards from a shuffled pack until a spade is dealt. 3.5. Hand Cards before a spade O Spade card O non-spade cards followed by a spade card Card * Fig.c. Pack Spade O Heart O Diamond O Club O Spade * card Heart * card Diamond * card Club * card Fig.6 Many cards (may be zero) 4.5 .Pack Red O Black O Red card * Black card Fig.17 .6.5 shows a pack divided into suits. 3. 3.5.4 * Fig.5. 3.c.c.c.c.5.

5.c. Logical data structures describe the data with respect to a given application.Finally consider a sequential file that contains daily takings of a shop in date order.5. These totals act as validation checks.7 O O Present Absent The JSP diagrams we have seen so far have shown physical data structures. 3. this shows that the ELSE part of the decision does nothing. 3. 3. Present and absent are processes that are performed according to the presence or absence of the respective totals. Fig.18 . At the start of the file is a header record describing the contents of the file. Further there are no decisions below the totals in this diagram because they are not being used.5 . 3. notice the use of null ( ─ ) in the decision at the bottom of the diagram.5.8.c. At the end of the file is the total for all the months recorded.7. The logical diagram is shown in Fig. Notice that the diagram does not violate the data structure shown in the previous diagram. Suppose we wish to extract the takings for all Mondays from the file shown in Fig.c. At the end of each month's takings is a grand total for the month.5. Sales Header record File data Total sales * Month's data O O Present Absent Month's body Month's total * Day's total Fig. 4. Also.7 shows this data structure.c.

Sales

Header record

File data

Total sales

* Month's data

Month's body

Month's total

* Day's total

O

O

Monday Fig. 3.5.c.8

Now suppose the application is to extract February's data. In this case we need to read past January totals so these must be shown in the logical data structure. However, once we have dealt with February, we do not wish to read the remaining months' data. Fig. 3.5.c.9 shows the logical structure for this problem.

4.5 - 19

Sales

Header record

File data

Total sales

Jan

Feb

Mar

Apr

May

Jun

Jul

Aug

Sep

Oct

Nov

Dec

* Day's data

Month total

* Day's data

Month total

Fig. 3.5.c.9 The next step is to enter, on the diagram, the constraints. This is done by numbering the constraints and then listing their meanings. Placing the constraints on Fig. 3.5.c.8 produced Fig. 3.5.c.10 where C1 is until end of file data C2 is until end of month's body C3 is day = Monday

4.5 - 20

Sales

Header record

File data C1 * Month's data

Total sales

Month's body

Month's total

C2 * Day's total C3
O

ELSE
O

Monday

Fig. 3.5.c.10 In this example, separate procedures can be written for each box in the logical structure. That is, each section in the diagram can be a separate procedure or function. Each procedure and function can use parameters to pass data to and from the calling procedure or function. This is further explained in the next Section.

4.5 - 21

3.5 (d)

Standard Programming Techniques.

The previous Section discussed top down design and JSP diagrams. Both systems lead to modules that can be programmed easily. Each module is a solution to an individual problem and each module has to interface with other modules. As long as the interfaces are clearly specified, each module can be given to a different programmer to code. All that the programmers need to know is the problem and how its solution must communicate with the solutions to other modules. This means that two programmers may happen to use the same name for a variable. Also, the programmers will need to pass values to other modules and be able to accept values from other modules. This was briefly discussed in Section 1.3 in the AS text. Let us first consider how data can be input to a function or procedure. This is done by means of parameters. The function below, written in Visual Basic, finds the perimeter of a rectangle given its length and breadth. This is not the only way of finding the perimeter and it probably is not the best way. However, it has been written like this in order to illustrate certain programming points. Public Function PerimeterOfRectangle(X As Integer, Y As Integer) As Integer X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function In this function X and Y are integers the values of which must be passed to the function before it can find the area of the rectangle. These variables are called formal parameters. To use this function, another program will have to call it and provide the values for X and Y. This can be done by means of a statement of the form Perimeter = PerimeterOfRectangle(4, 6) or we can use A=3 B=4 Perimeter = PerimeterOfRectangle(A, B) In both of these statements the variables inside the parentheses ( 4 and 6 in the first example and A and B in the second) are called actual parameters. How the values are passed to the function or procedure depends on the programming language. In the first example the values 4 and 6 are stored in the variables X and Y. In the second example, in Visual Basic, the addresses of A and B are passed to the function so that X and Y have the same address as A and B respectively. In C++, in both cases the actual values are passed to the function which stores them in its own variable space. Thus we have two different ways of passing parameters. Fig. 3.5.d.1 shows how Visual Basic normally passes parameters.

4.5 - 22

5. B Perimeter = PerimeterOfRectangle(A.Print "After call to Sub A = ".2 Visual Basic is said to pass parameters by reference (or address) and C++ passes them by value.d. 3.5.3 shows the output when this program is run.23 . Public Function PerimeterOfRectangle(X As Integer. A. Calling Program A B Memory Location 3 4 3 4 Fig 3.3. A.Print "Perimeter = ". " and B = ".d.2 shows what normally happens when C++ passes parameters.Calling Program A B Memory Location 3 4 Fig.d.5 . Perimeter picResults. Y As Integer) As Integer X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function Private Sub cmdShow_Click() Dim A As Integer Dim B As Integer Dim Perimeter As Integer A=3 B=4 picResults. Here is the function described above and a copy of the calling function in Visual Basic. Function X Y 4. B. B) picResults. " and B = ". notice that two extra memory locations are used and that C++ makes a copy of the values of A and B and stores them in separate locations X and Y.d.Print "Before call to Sub A = ". End Sub Fig.1 Function X Y Fig 3.5. It is interesting to see the effect of passing values by address.5.

24 .d. 4. Here is a modified form of the Visual Basic function together with the output from running the modified program. Visual Basic can pass parameters by value and C++ can pass parameters by reference.5.3 Notice that after the function has been run the values of A and B have changed.3. 3.4 In order to pass parameters by reference in C++. This is because the addresses of A and B were passed not their actual values. the formal parameter must be preceded by an ampersand (&). ByVal Y As Integer) As Integer X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function Fig.d.Fig.5 .5. Public Function PerimeterOfRectangle(ByVal X As Integer. In Visual Basic we have to use the ByVal key word if we want values to be passed by value.

A. C X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function Fig.5 4. shown in Fig.Variables can have different values in different parts of the program. Y As Integer) As Integer Dim C As Integer C = 10 picResults. A.d.5. Perimeter picResults. 3. " and B = ". Look at the following Visual Basic code and its output.d.5 . 3. " and C = ".5.Print "Perimeter = ".Print "After call to Sub A =".25 .5. B. C End Sub Public Function PerimeterOfRectangle(X As Integer. " and B = ". B Perimeter = PerimeterOfRectangle(A.Print "In Sub C = ".Print "Before call to Sub A = ". B) picResults. Private Sub cmdShow_Click() Dim A As Integer Dim B As Integer Dim C As Integer Dim Perimeter As Integer A=3 B=4 C=5 picResults.

B) picResults.Print "Perimeter = ". In Visual Basic this is done by means of the statement Public C As Integer which is placed in a module. writing different routines.Print "In Sub C = ". " and C = ". If we do this with the previous example the code becomes Public C As Integer 'This is in the module Private Sub cmdShow_Click() Dim A As Integer Dim B As Integer Dim Perimeter As Integer A=3 B=4 C=5 picResults. This is very helpful as it means that different programmers. do not have to worry about the names of variables used by other programmers. Perimeter picResults.This shows that C has a different value in the function PerimeterOfRectangle to in the calling function cmdShow_Click.Print "Before call to Sub A = ".5. C Perimeter = PerimeterOfRectangle(A.26 .5 . the variable has to be declared as global. 3. is changed in the calling routine also. " and B = ". C is said to be a local variable and the C in PerimeterOfRectangle is stored in a different address to the C in cmdShow_Click. To do this. A. Y As Integer) As Integer C = 10 picResults. However. C X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function Fig. C End Sub Public Function PerimeterOfRectangle(X As Integer. B. " and B = ". In fact it is changed throughout the program.Print "After call to Sub A =". it is sometimes useful to be able to use the same variable in many parts of a program.d. A. " and C = ". B.6 shows that the value of C. 4. Local variables only exist in the block in which they are declared. when changed in the function PerimeterOfRectangle.

3.5. What happens if a variable is declared as both global and local? The following code declares C as global and C as local in the function PerimeterOfRectangle and the result of running it is shown in Fig. This means that a variable can be local to a small block of code.Fig.6 In C++ variables can be declared at any point in the program.7. In the following example i is only available in the for loop.5. i++) { cout<<i } cout<<i //This is illegal.d. i<=10. The output statement after the loop is illegal as i no longer exists.27 . i no longer exists. Global variables should be used as sparingly as possible as they can cause a program to be very difficult to debug. for (int i = 1. 4. This is because C is declared as a local variable in this function and this means that the global C is not used. We now have the ability to allow variables to be used only in certain parts of a program or in any part.5 . Notice that the value of C in the function cmdShow_Click is not changed although its value is changed in PerimeterOfRectangle. 3. This is because it is not always clear when global variables are being changed.d.

" and C = ".5.Print "Perimeter = ". C X=2*X Y=2*Y PerimeterOfRectangle = X + Y End Function Fig. " and B = ". " and C = ".Print "Before call to Sub A = ".Public C As Integer 'global declaration Private Sub cmdShow_Click() Dim A As Integer Dim B As Integer Dim Perimeter As Integer A=3 B=4 C=5 picResults.Print "In Sub C = ". A. B) picResults. B.d. A. Perimeter picResults.28 .5 . C End Sub Public Function PerimeterOfRectangle(X As Integer.7 4.Print "After call to Sub A =". B. 3. C Perimeter = PerimeterOfRectangle(A. " and B = ". Y As Integer) As Integer Dim C As Integer 'local declaration C = 10 picResults.

. 150 then 100.e.5 . The numbers represent the addresses of the instructions following the calls to functions.e. the computer needs to know where to return to when the function or procedure is completed. .5 (e) Stacks and Procedures When a procedure or function is called. .e. 3. This means that we need a data structure that provides a last in first out facility. Return Fig.5. functions and procedures may call other functions and procedures which means that not only must several return addresses be stored but they must be retrieved in the right order. 4. . That is. the last address stored is the first address needed on returning from a function. This can be achieved by using a stack. . Further. . In the above example. . When the returns take place the addresses will be needed in the order 250. 3. . .1 Notice that the addresses will be stored in the order 100. Main program . Call Function B 150 … . Call Function C 250 … . the addresses will be stored in the stack each time a function is called and will be removed from the stack each time a return instruction is executed. .2. Return Function C . 150 then 250.5. A stack does precisely this. This is shown in Fig.1 shows what happens when three functions are called after one another. so we store the return addresses in a stack.5. Fig. Call Function A 100 … . . . the return address must be known. 3. Return Function B . . .29 . That is. End Function A .3. .

Calls and Returns Call Function A Push return address onto stack Stack Stack pointer Call Function B Push return address onto stack Stack pointer Call Function C Push return address onto stack Stack pointer 100 150 100 250 150 100 Return from C Pop return address off stack Stack pointer Return from B Pop return address off stack 250 150 100 250 150 100 Stack pointer Return from A Pop return address off stack 250 150 100 Stack pointer NULL Fig.5 .3.e.30 .2 4.5.

5 . B2.Now suppose that values need to be passed to. A2) and Proc B(B1. That is. Proc A(A1.Y2. Return Fig.31 . a function or procedure. note how the stack pointer is moved each time an address or actual parameter is popped onto or popped off the stack. . . . 3.X2) 200 … Proc A(A1.e. . This is shown in Fig. 4. A1 and A2 are the formal parameters for Proc A and B1.4. or from. .3 Proc B(B1.e.5. B2 and B3 are the formal parameters for Proc B.B2. B3).Y3) 400 … .5. when the procedures are called the actual parameters must be placed on the stack and the procedures must pop the values off the stack and store the values in the formal parameters. Then.B3) . Return Now let us suppose that all the parameters are being passed by value.3 which shows the procedures being called and the return addresses that must be placed on the stack.A2) . Suppose we have a main program and two procedures. Again a stack can be used. Main program . Call Proc A(X1.e. 3.5. . Now look at Fig. . 3. Call Proc B(Y1.

Call Proc A(X1.Y3) PUSH 400 PUSH Y1 PUSH Y2 PUSH Y3 Stack pointer Y3 Y2 Y1 400 200 B3 = Y3 (POP Y3) B2 = Y2 (POP Y2) B1 = Y1 (POP Y1) Stack pointer Y3 Y2 Y1 400 200 Return from Proc B Y3 Y2 Y1 400 200 Stack pointer Return from Proc A Y3 Y2 Y1 400 200 Stack pointer NULL 4. X2) PUSH 200 PUSH X1 PUSH X2 Stack pointer X2 X1 200 A2 = X2 (POP X2) A1 = X1 (POP X1) X2 X1 200 Stack pointer Call Proc B(Y1.32 .Y2.5 .

Finally. The calling program can then pop the value off the stack. or functions.5 . how do functions return values? Simply push them on the stack immediately before returning. Note that the return address has to be popped off the stack before pushing the return value onto the stack. This works in exactly the same way as the addresses of variables are passed so there is no need to return the values via parameters.33 . The procedures.Next we must consider what happens if the values are passed by reference. will access the actual addresses where the variables are stored. 4.

length. The class Rectangle calculates the area when an instance of a class is instantiated.5.a does not do this. That is. class Rectangle must provide a suitable method.1 Object Objects can only access the data by using the methods provided. In this Section we consider these concepts in a general way. If a user wishes to access the width and length of a rectangle. we cannot write area : = myRectangle.3. 4.a. an object of this class cannot directly calculate its area. This is shown in Fig. There are many such languages.f. Visual Basic). using diagrams rather than any particular language. Object Object Object Fig. 3.5 . Data encapsulation (or data hiding) has been explained in Section 3. Smalltalk) and others which have evolved (C++.a showed some simple examples of programs written in an object-oriented language. some of which were designed as such (Eiffel. In the case of the rectangle class. the class must provide methods to do this. inheritance and polymorphism. All these languages have classes and derived classes and use the concepts encapsulation.34 .width * myRectangle. Java is an OOP language whose syntax is based on C++. An object cannot manipulate the data directly.5. instantiations of a class.5 (f) Object-Oriented Programming (OOP) Section 3.5.1 where the objects. that is. are prevented from directly accessing the data by the methods. It is the concept that data can only be accessed via the methods provided by the class.5. 3.f.5. To find the area of myRectangle. where myRectangle is an object of type Rectangle. Methods to return the width and length are given below. The example in Section 3. The only way to find the area is to use the write( ) method which outputs the area.

The name of the class will appear at the top of the rectangle. This is shown in Fig. To find the perimeter we can write myWidth := myRectangle. Inheritance allows the re-use of code and the facility to extend the data and methods without affecting the original code. This is shown in Fig.2 Now suppose we want a class Employee that requires the same data and methods as Person and also needs to store and output an employee's National Insurance number. followed by the data followed by the methods.35 . Also. Clearly. 3. the design can be changed.2. it cannot change their values. without the user's program being affected. The concept of data being only accessible by means of the methods provided is very important as it ensures data integrity. 3. if the original design of a method is found to be inefficient. Once a class has been written and fully tested. In the following diagrams. integer getLength( ) { getLength := length. myRectangle can now use these methods to get at the width and length. Consider the class Person that has data about a person's name and address and a methods called outputData( ) that outputs the name and address. }//end of getWidth method. we shall use a rounded rectangle to represent a class. Thus. getName( ) and getAddress( ) that return the name and address respectively.integer getWidth( ) { getWidth := width.getWidth( ).5. unknowingly to the user.getLength( ). }//end of getLength method. We can do this by creating a class called Employee that inherits all the details of the class Person and adds on the extra data and methods needed.5 .5. myPerimeter := 2 * (myWidth + myLength).f. myLength := myRectangle. 3. Person name address outputData( ) getName( ) getAddress( ) Class name Data Methods Fig. Another powerful concept is that of inheritance.f. we do not wish to rewrite the contents of the class person. neither its methods nor the data can be tampered with. However.5. an object consists of the data and the methods provided by the class.3 where the 4.f.

5. How does the program determine which one to use? If myPerson is an instantiation of the Person class.f. then myPerson.4. will use the outputData( ) method from the Person class. Person is called the super-class of Employee and Employee is the derived class from Person.5. The concept of a method having two different meanings is called polymorphism.5 . one is hourly paid and the other is paid a salary.3 Notice that we now have two methods with the same name.arrow signifies that Employee inherits the data and methods provided by the class Person. Person name address outputData( ) getName( ) getAddress( ) Employee NINumber outputData( ) getNINumber( ) Fig. An object of type Employee can use the methods provided by Employee and those provided by Person. will use the method outputData( ) from the Employee class if myEmp is an instantiation of the Employee class.outputData( ). Now suppose we have two types of employee. 4.f.36 .outputData( ). Both of these require the data and methods of the classes Person and Employee but they also need different data to one another. The statement myEmp. 3. This is shown in Fig. 3.

System.out. This is done by writing a method.4 How can an object of type Employee output the name and address as well as the N.println("The N. 3.I.I. number? The outputData( ) method in class Employee can refer to the outputData( ) method of its superclass.5.5 . in class Employee. of the form void outputData( ) { super. 4. }//end of outputData method.Person name address outputData( ) getName( ) getAddress( ) Employee NINumber outputData( ) getNINumber( ) HourlyPaidEmp hourlyRate outputData( ) getHourlyRate( ) SalariedEmp salary outputData( ) getSalary( ) Fig.f. number is " + NINumber).37 .outputData( ).

Note also that there will only be one (or possibly two) marks for this type of question. Similarly. 4..I.38 . In the above. Inheritance is the ability of a class to use the variables and methods of a class from which the new class is derived.Here super. However. The following definitions would be satisfactiory answers to questions that say 'State the meaning of the term … '. A class describes the variables and methods appropriate to some real-world entity. In this case a simple definition is all that is required.5 . Definitions Data encapsulation is the combining together of the variables and the methods that can operate on the variables so that the methods are the only ways of using the variables. we have explained the meanings of terms such as data encapsulation. class and inheritance. number. An object is an instance of a class and is an actual real-world entity. sometimes the examiner may ask you to simply state the meanings of these terms. the other derived classes can call the methods of their super classes. outputData( ) calls the outputData( ) method of the super-class and then outputs the N.

we say that the search has succeeded 4. Prolog now outputs X = charnjit Prolog then goes back to the database and continues its search. In order to do this. It continues in this way until the whole database has been searched. female(sandip).mary). mary). That is. parent(sandip. The complete output is X = charnjit X = jaz X = tom No The last line means that there are no more solutions. atif). It finds male(jaz) so outputs X = jaz and again continues its search. the goal is to find all X that satisfy male(X). parent(jaz.3. We say that X is instantiated to charnjit. The query male(X) is known as a goal to be tested. in declarative languages. we shall use the following facts. parent(charnjit.5 . We now look at how this works using examples of Prolog scripts. we saw that. female(jane). parent(charnjit. rajinder).5.1. rajinder). parent(jane. Prolog starts searching the database and finds male(charnjit) matches male(X) if X is given the value charnjit. parent(jane. Remember that variables must start with an uppercase letter. male(jaz). If Prolog finds a match. female(anne).5 (g) Declarative Languages In Section 4. male(tom). male(charnjit). Suppose we ask male(X). the programmer can simply state what is wanted having declared a set of facts and rules.39 . atif). constants start with a lowercase letter.

parent(X. That is.mary). When the goal is true. Prolog now looks for the predicate father and finds the rule father(X. atif). In the database and the rule the components female.and the goal is true.5 . male(charnjit). male. male(tom). female(sandip). Prolog now uses the second part of the rule male(X) 4. Y) :. parent(sandip. Y). rajinder) This is the new goal. This rule states that X is father of Y if (the :. Prolog outputs the corresponding values of the variables. Y).symbol) X is a parent of Y AND (the comma) X is male. parent(jaz. In this rule Y is instantiated to rajinder and Prolog starts to search the data base for parent(X. Y). Prolog finds the match parent(jane. male(X). parent(jane. rajinder). Y) :. female(anne). mary). parent(charnjit. Suppose our goal is to find the father of rajinder.parent(X. Now we shall add the rule father(X. The database now looks like this.40 . rajinder) if X is instantiated to jane. our goal is to find all X that satisfy father(X. parent(charnjit. Y) :.parent(X. male(jaz). atif). female(jane). parent(jane. male(X). male(X). father(X. rajinder). rajinder). parent and father are called predicates and the values inside the parentheses are called arguments.

1 c is parent of d b is parent of c a is parent of b 4. Prolog's new goal is male(jane) which fails. rajinder) is true and Prolog returns X = charnjit Prolog continues to see if there are any more matches. This can be used to create alternative versions for a rule.1 shows how ancestor is related to parent.g.5 . to try to match the goal parent(X.5. The next step is to try to satisfy the goal male(charnjit) This is successful so parent(charnjit. from this point in the database. 3. Prolog does not give up at this stage but backtracks to the match parent(jane. 3.with X = jane. rajinder) and starts again. Thus father(charnjit. There are no more matches so Prolog outputs No A powerful tool in Prolog is recursion. rajinder) with X instantiated to charnjit.5.41 . The Fig. rajinder) and male(charnjit) are true. a a is ancestor of b b b is ancestor of c a is ancestor of c c a is ancestor of d b is ancestor of d d Fig. That is. rajinder) This time Prolog finds the match parent(charnjit.g.

Let us see how it works using Fig. It finds parent(a.1 which represents the database parent(a. It finds the first rule ancestor(X. Z). 4. Prolog finds the second rule and tries to match parent(a. and Z is a parent of W and W is a parent of Y.parent(X.parent(X. d). c) with each predicate in the database. Prolog fails but does not give up. ancestor(Z. Y) :. 3. It backtracks and looks for another rule for ancestor. b) so instantiates Z to b. Thus Prolog looks for parent(b. Y) :. This is now put into the second part of the rule to produce ancestor(b. b). c) and succeeds.3. But it also shows that X is an ancestor of Y if X is a parent of Z and Z is a parent of Y. This means that Prolog has to look for a rule for ancestor. Y) :.5 . parent(b.parent(X. parent(c.This shows that X is an ancestor of Y if X is a parent of Y. In Fig. b is an ancestor of c and c is an ancestor of d. c). Y).g. The first rule states that X is an ancestor of Y if X is a parent of Y. Thus the rule is recursive. In Prolog we require two rules that are written as ancestor(X. c).42 . It also shows that X is an ancestor of Y if X is a parent of Z . c). ancestor(X.g. by setting the goal ancestor (a. The second rule is in two parts. this is saying that a is an ancestor of b. Y). Prolog finds the first rule and tries to match parent(a. Y). Z).1.5. This can continue forever.5.

Joint conditions use the logical operators OR and AND. Zak) We use the symbol ← to represent if and have loves(Mary. x is a variable. dogs) ← likes(Jane. dogs) 4. Prolog stands for Programming in LOGic and its notation is based on that of predicate calculus. This form of programming is based on the mathematics of predicate calculus. b). Therefore Prolog returns Yes. The meaning of the conclusion is that Frank likes anything (or anybody) that likes computing.43 . Now try to trace what happens if the goals are ancestor(a. You should find that the first goal succeeds and the second fails. Predicate calculus is a branch of mathematics that deals with logic. The names of the relations are called predicate symbols. Harry) ← loves(Harry. Examples are loves(Mary. Mary) likes(John. We also have atomic conclusions such as Mary loves Harry if Harry loves Mary John likes dogs if Jane likes dogs Frank likes x if x likes computing In the last atomic conclusion.5 . Harry) likes(Philip. In this form the name of the relation is written in front of the atomic formula. examples of which are John likes x if x is female AND x is blonde Mary loves Bill OR Mary loves Colin if Mary loves Don The atomic formulae that serve as conditions and conclusions may be written in a simplified form. All we have done in this Section is based on the rules of predicate calculus.This means that with X = a.d) and ancestor(c. In predicate calculus the simplest structures are atomic sentences such as Mary loves Harry Philip likes Zak The words in italics are part of the names of relationships. Y = c we have Z = b and the second rule succeeds.

Instantiation is giving a variable in a statement a value.The AND is represented by a comma in the condition part of the atomic conclusion. male(x) ← human(x) These examples show the connection between Prolog and predicate calculus. blonde(x) The OR is represented by a comma in the conclusion.5 . AS with the previous Section we include here the definitions of terms used in this Section. You do not need to understand how to manipulate the examples you have seen any further than has been shown in this Section. they can be used when a question says ''State the meaning of the term … '. 4.44 . x) ← female(x). Predicate logic is a branch of mathematics that manipulates logical statements that can be either True or False. For example female(x). A goal is a statement that we are trying to prove whether or not it is True or False. For example likes(John. Remember. Definitions Backtracking is going back to a previously found successful match in order to continue a search.

45 .i.i. The memory address register (MAR) holds the address of the instruction or data that is to be fetched from memory. Remember that these are used to execute machine code instructions not high-level language instructions. 4. This register is also known as the Sequence Control Register (SCR). 3. How these binary numbers are interpreted depends on the registers in which they end up.5. Remember that the computer cannot distinguish between data and instructions.3.5 . The MDR is the only route between the other registers and the main memory of the computer. including instructions on their way to the CIR. The memory data register (MDR) holds data to be transferred to memory and data that is being transferred from memory.5.1 shows the minimum number of registers needed to execute instructions.1 The program counter (PC) is used to keep track of the location of the next instruction to be executed. Both are held as binary numbers. A L U Accumulator Working Register I n t e r n a l B u f f e r Program Counter Memory Address Register Current Instruction Register A d d r e s s B u s M e m o Index Register Memory Data Register D a t a B u s r y Fig. The current instruction register (CIR) holds the instruction that is to be executed. 3. ready for decoding.5 (h) Use of Special Registers/Memory Addressing Techniques Fig.

5 . In order to do this we shall assume that a memory location can hold both the instruction code and the address part of the instruction.46 . 302 and 303 as shown in the following table and that the PC contains the number 300.The accumulator is where results are temporarily held and is used in conjunction with a working register to do calculations. For example. This will allow us to use up to 212 (= 4096) instruction codes and 220 (= 1 048 576) memory addresses. The index register is a special register used to adjust the address part of an instruction. we shall use mnemonics for instructions such as Code LDA STA ADD STOP Meaning load the accumulator store the accumulator add the contents of memory to the accumulator Stop We shall also use decimal numbers rather than binary for the address part of an instruction. 4. This will be explained in more detail later. We shall now see how these registers are used to execute instructions. To simplify things further. These are not required for this examination. Suppose four instructions are stored in locations 300. 301. Note that the diagram does not show the control bus and the signals needed for instructions to be correctly executed. a 32-bit memory location may use 12 bits for the instruction code and 20 bits for the address part.

. 5 7 ? . . . Notes Load accumulator with contents of location 400 Add contents of location 401 to accumulator Store contents of accumulator in location 402 Stop Location 400 contains the number 5 Location 401 contains the number 7 Not known what is in location 402 4.5 . .47 . . . . 300 301 302 303 304 . LDA 400 ADD 401 STA 402 STOP .Address . Contents . . . . . . 400 401 402 .

As the contents of an address are needed.The fetch part of the instruction is Action Copy contents of PC to MAR Add 1 to PC Copy contents of location pointed to by MAR into MDR Copy instruction in MDR to CIR PC 300 301 301 301 MAR 300 300 300 300 CIR ? ? ? LDA 400 MDR ? ? LDA 400 LDA 400 The instruction is now decoded (not shown in the table) and is interpreted as 'load the contents of the location whose address is given into the accumulator'.5 . A summary of the steps needed to fetch and execute the LDA instruction are shown in Fig.48 . Note that all data moves between memory and the MDR via the data bus. the address part of the instruction is copied into the MAR. in this case 400. Note that the PC already contains the address of the next instruction.5.h. 3. We now start the execution phase.2 4. Action PC Copy address part of instruction 301 to MAR MAR CIR 400 LDA 400 MDR LDA 400 Now use the MAR to find the value required and copy it into the MDR. Now use the same steps to fetch and execute the next instruction. Action Copy contents of address given in MAR to MDR PC 301 MAR CIR 400 LDA 400 MDR 5 Finally copy the contents of the MDR to the accumulator. All addresses use the address bus.

Set PC to address of first instruction Copy PC to MAR Increment PC Copy contents of location pointed to by MAR to MDR Fetch phase Copy instruction in MDR to CIR Decode instruction Copy contents of address part of CIR to MAR Copy contents of address in MAR to MDR Execute phase for LDA instruction Copy contents of MDR to accumulator Fig.h.5.5 .2 4. 3.49 .

5.h. . . Notes Add the contents of location 500 to the accumulator If accumulator < 0 go back to the instruction in location 300 Suppose the PC contains the number 300. Contents .h.h. what happens during the execute cycle depends on the instruction. . ADD 500 JLZ 300 .5.In Fig. How can we arrange to change the order in which instructions are fetched? Consider these instructions. This is because the PC is only changed by successively adding 1 to it.3 This process works fine but only allows for the sequential execution of instructions.50 .i. Fetch next instruction ( See Fig 3. Address . . 4. . 3. after the instruction ADD 500 has been fetched and executed the PC will hold the number 301. 3.5. . 300 301 . The next step is to execute this instruction.5. the STA n (store the contents of the accumulator in the location with address n) has the execute steps shown in Fig. 3. For example.3.5 .5.2) Copy the contents of the address part of instruction in CIR to MAR Copy the contents of the accumulator to MDR Copy the contents of the MDR to the address given in MAR Fig. The steps are shown in Fig. .4. 3.3. Now the instruction JLZ 300 will be fetched in the usual way and the PC will be incremented to 302.i. .

5.5.5 .4 No So far we have used two copy instructions (LDA and STA).h.i.5. This is known as direct addressing.h.2) Is accumulator < 0 Yes Copy address part of CIR to the PC Fig.2) Copy the address part of the instruction in CIR to MAR Copy the contents of the location whose address is in the MAR to the MDR Copy the contents of the MDR to the MAR Copy the contents of the location whose address is in MAR to accumulator Fig. Here the address part of the instruction specifies where to find the address to be used. 3. 3. 3.5.5. the address part has specified where to find or put the data.Fetch next instruction ( See Fig 3. one arithmetic instruction (ADD) and one jump instruction (JLZ).5 shows how this type of instruction is executed if the instruction is LDI (load the accumulator indirectly). Fetch next instruction ( See Fig 3.51 .h. Fig. In the case of the copy and arithmetic instructions. An alternative method of using the address part of an instruction is called indirect addressing.i.5 4.

Often it is necessary to access successive memory locations for data. the programmer increments the index register (IR).The advantage of this mode of addressing is that the actual address used in our example can be the full 32 bits giving 232 addresses. We could have an instruction. which uses index addressing. Suppose we wish to add a series of numbers stored in locations with addresses 600 to 609. After all. Consider the instruction. Index addressing uses an index register that the programmer initially sets to zero.52 . We do not want to write a load instruction followed by nine add instructions. say ADDX. The situation is PC 301 MDR ADDX 700 CIR ADDX 700 MAR 700 IR 5 Before the ADDX instruction is executed the contents of the IR must be added to the MAR to give PC 301 MDR ADDX 700 CIR ADDX 700 MAR 705 IR 5 Thus the contents of address 705 are added to the accumulator. ADDX 700 and let the contents of the index register be 5. in location 300. The programmer then increments the IR to make it 6 so that the next time the ADDX 700 instruction is executed the addressed used will be 706. 4. what would happen if we wished to add 100 numbers? We can solve this problem by using indexed addressing. After each add instruction is executed. Index addressing adds the contents of the index register to the address part of the instruction before using the address.5 .

Early versions of Fortran and BASIC were not structured and are usually treated as second generation languages. The users of these packages tell the application what they want to do not how to do it.5 . The result would be Dalvinder Frank Georgina In fact. Consider the following table called Students. Fourth generation languages do not do this. Third generation languages need the user to specify clearly all the steps that need to (Procedural Languages) be taken to solve a problem.7 32.53 . Databases often use query by example (QBE). In Access we could simply create a query with columns for name and height and in the height column we would write > 150 for the criteria. In fact Access uses the Structured Query Language (SQL) to create the queries. We could also specify. C++ and Pascal.4 28. name Alan Brenda Charnjit Dalvinder Elmira Frank Georgina height 150 140 148 152 143 158 151 weight 31. An example is mail merge . For example. Here all the user has to do is tell the software what table or database to use and the mail merge will take place. However.8 30.2 27. Visual Basic is structured and can be treated as a third generation language. Here the user simply states what is required and the software will do the task.1 33. by means of a check box. 4. we can write the query in SQL as SELECT name FROM Students WHERE height > 150.3. Languages that accompany modern database.2 (Declarative Languages) Now suppose we wish to find the names of all those students who have a height greater than 150. Microsoft Access lets a user specify conditions such as DOB < 01/01/90 and the necessary coding will be done.5 (i) Third and Fourth Generation Languages Third generation languages are those that use a structured syntax such as C.8 28. This is what Access does. that only the name should be printed. word processing and spreadsheet packages do not need the user to do this.

5 . A more complicated query is SELECT name FROM Students WHERE height > 145 AND weight > 32. Again. (Advantage of fourth generation languages) 4. The development of fourth generation languages has meant that people who are not programmers can produce useful results. we do not tell the computer exactly how to find the answer required as we would with a third generation language.54 .Notice that we do not have to give the steps needed to check each entry in the table Students.

5 . A digit is 0 or 1 or 2 or … or 9 and we write this as <digit> ::= 0|1|2|3|4|5|6|7|8|9 where the vertical line is read as OR.5 (j) Backus Naur Form and Syntax Diagrams Since all programming languages have to be translated to machine code by means of a computer. But a computer language does not restrict the number of digits. so we shall start with the definition of an integer. count <= 10. 9 do not. This is because integer and digit have definitions elsewhere. But we must now define a digit. the digits 0. … . 9. An integer is a sequence of the digits 0. All languages use integers. A particular compiler will restrict the number of digits only because of the storage space set aside for an integer. An example of the start of a FOR loop in Visual Basic is For count = 1 To 10 but C++ expects for (count = 1. We therefore need. Notice that all the digits have to be specified and that they are not inside angle brackets (< and >) like <integer> and <digit>. a set of rules that specify precisely every part of the language. 4. We can write this as <integer> ::= <digit> This is read 'an integer is defined to be (::=) a digit'. count++) A Visual Basic compiler would not understand the C++ syntax and vice versa.3. Now the number of digits in an integer is arbitrary. Our full definition of a single digit integer is <integer> ::= <digit> <digit> ::= 0|1|2|3|4|5|6|7|8|9 This is called Backus Naur Form (BNF).55 . 1. That is. 2. they must be clearly defined. These rules are specified using Backus Naur Form (BNF) or syntax diagrams. 2. … . an integer can be a single digit. it can be any number. for each language. 1. Thus the following are all valid integers. 0 2 415 3040513002976 0000000123 Thus. Each statement must be of a prescribed form.

k. Strictly speaking we have defined an unsigned integer as we have not allowed a leading plus sign ( + ) or minus sign ( . Thus. all integers of more than one digit start with a single digit and are followed by an integer. <integer> is a single digit and write <integer> ::= <digit>|<digit><integer> That is. We now have the full definition of an unsigned integer which.5. 4. eventually. But 47 is a single digit integer ( 4 ) followed by a single digit integer ( 7 ).But how are we going to specify integers of any length? Consider the integer 147 This is a single digit integer ( 1 ) followed by the integer 47. This means that at any time <integer> can be replaced by <digit> and the recursion stops. Applying this definition several times produces the sequence <integer> ::= <digit><integer> =<digit><digit><integer> =<digit><digit><digit><integer> To stop this we use the fact that. in BNF. an indefinitely long integer is defined as <integer> ::= <digit><integer> This is a recursive definition as integer is defined in terms of itself.56 .). is <unsigned integer> ::= <digit>|<digit><unsigned integer> <digit> ::= 0|1|2|3|4|5|6|7|8|9 This definition of an unsigned integer can also be described by means of syntax diagrams as shown in Fig. This will be dealt with later. 3.1.5 . Thus. Eventually the final integer is a single digit integer. <integer> is a <digit> OR a <digit> followed by an <integer>.

integer digit digit 0 1 2 3 4 5 6 7 8 9 Fig. That is. 3.j.57 . try to start at the top with a general definition and then try to break the definitions down into simpler and simpler ones. If we do this we get the following definition. Thus <signed integer> ::= + <unsigned integer>| . we have used top-down design when creating these definitions. It is usual to say that an integer is an unsigned integer or a signed integer. in BNF.1 Now we shall define a signed integer such as +27 -3415 This is simply an unsigned integer preceded by a + or – sign. it is better to use several definitions than try to put all the possibilities into a single definition. of an integer.<unsigned integer> <unsigned integer> ::= <digit>|<digit><unsigned integer> <digit> ::= 0|1|2|3|4|5|6|7|8|9 There are other valid ways of writing these definitions.5.<unsigned integer> and we can use the earlier definition of an <unsigned integer>. 4. <integer> ::= <unsigned integer>|<signed integer> <signed integer> ::= + <unsigned integer>| . However.5 . In other words. We have broken the definitions down until we have terms whose values can be easily determined.

58 .j. The characters can be any letter.j.2 Care must be taken when positioning the recursion in the definitions using BNF. <variable> ::= <letter>|<character><variable> 4.3. 3.2 shows the corresponding syntax diagrams.5. digit or the underscore.5. Valid examples are A x sum total24 mass_of_product MyAge Let us see what happens if we use a similar definition to that for an unsigned integer. Suppose we define a variable as a sequence of one or more characters starting with a letter.Fig. integer digit + - digit 0 1 2 3 4 5 6 7 8 9 Fig.5 .

That is 00135 is not allowed 0 is allowed. You should also note that. This means that the last time it is called it will be a letter and this will be at the head of the variable. in the definition of integer. Let us now use our definition of an integer to define a real number such as 0.347 -2. we used tail recursion.34 00235. We must rewrite our definition in such a way as to ensure that the first character is a letter. 4. S and u for <character> and then m for <letter>. but here we have used head recursion. The correct definition is <variable> ::= <letter>|<variable><character> <character> ::= <letter>|<digit>|<under-score> <letter> ::= <uppercase>|<lowercase> <uppercase> ::= A|B|C|D|E|F|G|H|I|J|K|ZL|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z <lowercase> ::= a|b|c|d|e|f|g|h|i|j|k|zl|m|n|o|p|q|r|s|t|u|v|w|x|y|z <digit> ::= 0|1|2|3|4|5|6|7|8|9 <under-score> ::= _ A syntax diagram can also represent this. Continuing in this way we use 2. Moving the recursive call to the front of <character> can do this. it is <real number> ::= <integer> .59 . This means that our definition simply means that we must end with a letter not start with one. This is left as an exercise. This means that an integer can be a zero digit non-zero digit non-zero digit followed by any digit. <unsigned integer> Finally. suppose we do not want to allow leading zeros in our integers.5 .862 +14.<character> ::= <letter>|<digit>|<under-score> Now 2Sum is valid as we use <character><variable> with <character> = 2 and <variable> = Sum.006 The result is very simple.

integer 0 digits digits 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Fig. this is <integer> ::= <zero>|<digits> <digits> must be a single non-zero digit or a non-zero digit followed by any digits.4 4.j. In BNF.5 .5. 3.60 . 3.4 shows the corresponding syntax diagram.5.j.This means that an integer is zero or digits where digits must start with a non-zero digit. This gives us <digits> ::= <non-zero digit>|<digits><digit> where <zero> ::= 0 <non-zero integer> ::= 1|2|3|4|5|6|7|8|9 <digit> ::= <zero>|<non-zero digit> Fig.

1. and in that time the examiner not only has to examine this section but also the other 9 sections in module 3. complex. 5. a) b) Explain the difference between direct and indirect addressing and explain why indirect addressing allows access to more memory locations than indirect addressing. so the idea of long. and a two digit number or • A point and a two digit number A positive integer has been defined as <INTEGER> A digit is defined as <DIGIT>::= 0/1/2/3/4/5/6/7/8/9. a point. 4. algorithm type questions are not feasible. Explain the terms (i) data encapsulation (ii) inheritance (iii) instantiation when applied to programming in an object oriented programming language. Define.5.61 . Explain the passing of parameters by reference and by value. and knowledge based. The exception may be with the types of language which may produce a question on the lines of the object oriented question in the sample material. take heart! The whole examination only lasts 2 hours. Distinguish between procedural languages and declarative languages. However. 3.3.5 Example Questions Having worked through the 66 pages of section 3. the variable <AMOUNT OF MONEY> Using the previously defined values of INTEGER and DIGIT. You are going to be asked questions that will be taken from the syllabus but which will be fairly short. many students will be worried about the detail offered and the need to answer examination questions on what is very difficult and complex work. draw a syntax diagram to define AMOUNT OF MONEY.5 . (6) (4) (4) 2. using Backus Naur form. (6) An amount of money can be defined as • A$ sign followed by either • A positive integer or • A positive integer. 4. This works out at only 12 minutes for each section.

To overcome this we could introduce a new field called On Order of type Boolean. we will create a new order because the stock that has been ordered has not been delivered.. In some cases the company's name has been entered as Food & Drink Ltd. Suppose we want to know which items need to be reordered.a. Further. Typically a stock file would contain records describing stock. What happens if management ask for a list of best selling products? The file has not been set up for this and to change it so that such a request can be satisfied in the future involves modifying all existing software. shown in Fig. 3. sometimes as Food and Drink Ltd. The problem is when we check the stock the next day. This leads to redundant data or data duplication. This means that a match is very difficult because the data is inconsistent.6 .1. Each field would have its own data type and hold a single item of data. Field Name Description Cost Price Selling Price Number in Stock Reorder Level Supplier Name Supplier Address Data Type String Currency Currency Integer Integer String String This led to very large files that were difficult to process. suppose we want to know which products are supplied by Food & Drink Ltd. This can be set to True when an order has been placed and reset to False when an order has been delivered. The original software is expecting the original seven fields not eight fields. Another problem is that each time a new product is added to the database both the name and address of the supplier must be entered.6. shows how data can be proliferated when each department keeps its own files. as we only need to sequentially search the file and. if Number in Stock is less than the Reorder Level. make a note of the item and the supplier and output the details. The following example. This means that the software designed to manipulate the original file must be modified to read the new file layout. This is fairly straightforward. Unfortunately it is not that easy. A typical file would consist of a large number of records each of which would consist of a number of fields. 4.Chapter 3. Each record may consist of the following fields. Further ad hoc enquiries are virtually impossible. and sometimes the full stop after Ltd has been omitted.6 (a) Files and Databases Originally all data were held in files.1 ..6 Databases 3.

6. Description. Worse still. 4. Sale Price. amount owing. Cost Price. suppose the Order Department order some parts and there is an increase in price. We first need to find the parts supplied by a particular supplier from one file and then use a second file to find which customers have bought those parts. • Duplication of data Details of suppliers have to be duplicated if a supplier supplies more than one part.6 . etc. Description. Customer name and address. The Order Department increases the Cost and Sale prices but the Accounts Department do not.2 . Sale Price Supplier name and address. Sales Department Programs to record orders from customers Accounts Department Programs to record accounts of customers File containing Customer name and address. therefore it takes up time and more space. Re-order level. What happens if a customer changes his address? The Sales Department may update their files but the Accounts Department may not do this at the same time.Purchasing Department Programs to place orders when stocks are low File containing Stock Code. Details of customers are held in two different files. Duplication leads to loss of data integrity.1 This method of keeping data uses flat files. 3. Flat files have the following limitations. Fig. Data has to be entered more than once. This difficulty can be compounded if data is needed from more than two files. Number sold. etc File containing Stock Code. • Separation and isolation of data Suppose we wish to know which customers have bought parts produced by a particular supplier. etc. Duplication is wasteful as it costs time and money.a. dates of orders. there is now a discrepancy.

3. This means that each time a new query was asked for. • Fixed queries and the proliferation of application programs File processing was a huge advance on manual processing of queries.a.6. C programs cannot read files created by a COBOL program. Examples of these are shown in Fig. To try to overcome the search problems of sequential files. • Incompatibility of files Suppose one department writes its applications in COBOL and another in C. a new program had to be written.6. This led to end-users wanting more and more information. two types of database were introduced. some of which were incompatible. If there is a need to change any of these formats. whole programs have to be changed.3 respectively.3 .6.• Data dependence Data formats are defined in the application programs. Often. again causing a problem. Different applications may hold the data in different forms.2 Hierarchical Database 4. Suppose an extra field is needed in a file. even if they do not use that new item of data. 3. These were hierarchical and network databases.2 and Fig. the data needed to answer the query were in more than one file.a. Then COBOL files have a completely different structure to C files. 3.6 . again all applications using that file have to be changed. Employee Part-Time Full-Time Cleaner Cashier Hourly Paid Salaried Tool Setter Cashier Manager Supervisor Fig.a.

down and across the tree like structure.3 shows how complex the pointers can become.6.a.a. 4. The diagram in Fig. 3.3 Network Database The hierarchical model can still lead to inconsistent and redundant data.6 . except that it has more complex pointers. This makes it very difficult to maintain a network database.Smart Cards Definitions Applications Electronic Purse Visa AMERKORE International Mondex Aston University Travelling NatWest Access Control Fig. 3. A network database allows movement up. An hierarchical database allows movement up and down the tree like structure. A network database is similar to an hierarchical one.4 .6.

Country. 1 2 3 No. 3. Midshire BN2 5RG To: Bill Jones London England Product No. each record must be of a fixed length and each field must contain only one item of data. Description)) where DELNOTE is the name of the relation (or table) and Num.: 005 Date: 14/08/01 Description Table Desk Chair Fig. In tabular form the data may be represented by Fig. Then check the boxes 'Hide spelling errors on this document' and 'Hide grammatical errors in this document'. So. In the relational database model. Also. 4. We write the details of our delivery note as DELNOTE(Num. ProdID and Description are the attributes. 3. The Square. City. each record must be of a fixed length so a variable number of fields is not allowed. City. the delivery note has more than one part on it.6. CustName. Easy Fasteners Ltd Old Park. Country. Consider the following delivery note from Easy Fasteners Ltd. At this stage we should start to use the correct vocabulary for relational databases.6 . ProdID and Description are put inside parentheses because they form a repeating group. This is called a repeating group. This can be done by choosing Options… from the Tools menu and clicking on the Spelling and Grammar tab. (ProdID. The files are called relations (or tables). This is so that you can see the keys.6 (b)2.6 (b) Relational Databases and Normalisation Note: When reading this Section you may wish to turn off the facility that underlines spelling mistakes. CustName. repeating groups are not allowed. In this example. Instead of fields we call the columns attributes and the rows are called tuples.5 . we cannot say 'let there be three fields for the products as some customers may order more products than this and other fewer products. (b)1 In this example. Berrington.3.

we simply underline the attributes that make up the key.6 (b)2 This again shows the repeating group. 3. City. We say that this is in un-normalised form (UNF). the answer is no.Num 005 CustName Bill Jones City London Country England ProdID 1 2 3 Description Table Desk Chair Fig. another delivery note may have the same products on it. Fig. Do we really need to record the details of the customer for each item on the delivery note? Clearly. all the incomplete dependencies have been removed. 4NF and 5NF. Description) To indicate the key. We can write this as DELNOTE(Num. ProdID. the relation DELNOTE still contains redundancy. we have removed the repeating group. CustName.6 (b)3 ProdID 1 2 3 Description Table Desk Chair To make each row unique we need to choose Num together with ProdID as the key. This form solves most problems. Country. Because we have identified a key that uniquely identifies each tuple. Num 005 005 005 CustName Bill Jones Bill Jones Bill Jones City Country London England London England London England Fig 3. so we need to use the combination of Num and ProdID to form the key.6 (b)3. Remember. 4. Definition of 2NF A relation that is in 1NF and every non-primary key attribute is fully dependent on the primary key is in Second Normal Form (2NF). To put it into 1st normal form (1NF) we complete the table and identify a key that will make each tuple unique. That is. Normalisation theory recognises this and allows relations to be converted to Third Normal Form (3NF). This is rare and beyond the scope of this syllabus. 3. This is shown in Fig. Definition of 1NF A relation with repeating groups removed is said to be in First Normal Form (1NF). a relation in which the intersection of each tuple and attribute (row and column) contains one and only one value. (Note: Occasionally we need to use Boyce-Codd Normal Form.) Let us now see how to move from 1NF to 2NF and on to 3NF. However.6 . That is.6 .

City. We say that Num determines CustName. Can you see any more data repetitions? The following table of data may help. and in which no non-primary key attribute is transitively dependent on the primary key is in 3NF. DEL_PROD needs a compound key because a delivery note may contain several parts and similar parts may be on several delivery notes. ProdID → 0 (Dummy functional dependency) We now have three relations. CustName. we lose the connection that tells us which parts have been delivered to which customer.In our example. That is.6 . City. Description only depends on ProdID. DELNOTE(Num. Country ProdID → Description If we do this.7 . Definition of 3NF A relation that is in 1NF and 2NF. City and Country depend only on Num and not on ProdID. Country ProdID determines Description and write Num → CustName. To maintain this connection we add the dependency Num. all non-key elements are fully dependent on the primary key. using the data supplied. Description) DEL_PROD(Num. 4. We now have the relations in 2NF. CustName. Num 005 005 005 008 008 014 002 002 002 CustName Bill Jones Bill Jones Bill Jones Mary Hill Mary Hill Anne Smith Tom Allen Tom Allen Tom Allen City London London London Paris Paris New York London London London Country England England England France France USA England England England ProdID 1 2 3 2 7 5 7 1 2 Description Table Desk Chair Desk Cabinet Cabinet Cupboard Table Desk Country depends on City not directly on Num. it does not depend on Num. We need to move on to 3NF. City. Country) PRODUCT(ProdID. ProdID) Note the keys (underlined) for each relation.

Country but it is City that determines Country.8 . City) CITY_COUNTRY(City. Removing this transitive functional determinacy. that is City → Country and we can write Num Num → City → Country → CustName We say that Num transitively functionally determines Country. ProdID) Let us now use the data above and see what happens to it as the relations are normalised. 4.In our example we are saying Num → CustName.6 . we have DELNOTE(Num. CustName. City. Description) DEL_PROD(Num. Country) PRODUCT(ProdID.

1NF DELNOTE Num 005 005 005 008 008 014 002 002 002

CustName Bill Jones Bill Jones Bill Jones Mary Hill Mary Hill Anne Smith Tom Allen Tom Allen Tom Allen

City London London London Paris Paris New York London London London

Country England England England France France USA England England England Convert to 2NF

ProdID 1 2 3 2 7 5 7 1 2

Description Table Desk Chair Desk Cupboard Cabinet Cupboard Table Desk

DELNOTE Num CustName 005 Bill Jones 008 Mary Hill 014 Anne Smith 002 Tom Allen DEL_PROD Num 005 005 005 008 008 014 002 002 002

City London Paris New York London

PRODUCT Country ProdID England 1 France 2 USA 3 England 7 5

Description Table Desk Chair Cupboard Cabinet

ProdID 1 2 3 2 7 5 7 1 2

Convert to 3NF

4.6 - 9

DELNOTE Num 005 008 014 002

CustName Bill Jones Mary Hill Anne Smith Tom Allen

DEL_PROD City Num London 005 Paris 005 New York 005 London 008 008 014 002 002 002

ProdID 1 2 3 2 7 5 7 1 2

PRODUCT CITY_COUNTRY ProdID Description City 1 Table London 2 Desk Paris 3 Chair New York 7 Cupboard 5 Cabinet

Country England France USA

Now we can see that redundancy of data has been removed. In tabular form we have UNF DELNOTE(Num, CustName, City, Country, (ProdID, Description)) 1NF DELNOTE(Num, CustName, City, Country, ProdID, Description) 2NF DELNOTE(Num, CustName, City, Country) PRODUCT(ProdID, Description) DEL_PROD(Num, ProdID) 3NF DELNOTE(Num, CustName, City) CITY_COUNTRY(City, Country) PRODUCT(ProdID, Description) DEL_PROD(Num, ProdID) In this Section we have seen the data presented as tables. These tables give us a view of the data. The tables do NOT tell us how the data is stored in the computer, whether it be in memory or on backing store. Tables are used simply because this is how users

4.6 - 10

view the data. We can create new tables from the ones that hold the data in 3NF. Remember, these tables simply define relations. Users often require different views of data. For example, a user may wish to find out the countries to which they have sent desks. This is a simple view consisting of one column. We can create this table by using the following relations (tables). PRODUCT DEL_PROD DELNOTE CITY_COUNTRY to find ProdID for Desk to find Num for this ProdID to find City corresponding to Num to find Country from City

Here is another example of normalisation. Films are shown at many cinemas, each of which has a manager. A manager may manage more than one cinema. The takings for each film are recorded for each cinema at which the film was shown. The following table is in UNF and uses the attribute names FID Title CID Cname Loc MID MName Takings FID Title 15 Jaws 23 Tomb Raider Unique number identifying a film Film title Unique string identifying a cinema Name of cinema Location of cinema Unique 2-digit string identifying a manager Manager's name Takings for a film CID TF GH JK TF GH JK FB NM TF LM TF NM Cname Odeon Embassy Palace Odeon Embassy Palace Classic Roxy Odeon Odeon Odeon Roxy Loc Croyden Osney Lye Croyden Osney Lye Sutton Longden Croyden Sutton Croyden Longden MID 01 01 02 01 01 02 03 03 01 03 01 03 MName Smith Smith Jones Smith Smith Jones Allen Allen Smith Allen Smith Allen Takings £350 £180 £220 £430 £200 £250 £300 £290 £390 £310 £310 £250

45 56

Cats & Dogs Colditz

Converting this to 1NF can be achieved by 'filling in the blanks' to give the relation

4.6 - 11

FID 15 15 15 23 23 23 23 23 45 45 56 56

Title Jaws Jaws Jaws Tomb Raider Tomb Raider Tomb Raider Tomb Raider Tomb Raider Cats & Dogs Cats & Dogs Colditz Colditz

CID TF GH JK TF GH JK FB NM TF LM TF NM

Cname Odeon Embassy Palace Odeon Embassy Palace Classic Roxy Odeon Odeon Odeon Roxy

Loc Croyden Osney Lye Croyden Osney Lye Sutton Longden Croyden Sutton Croyden Longden

MID 01 01 02 01 01 02 03 03 01 03 01 03

MName Smith Smith Jones Smith Smith Jones Allen Allen Smith Allen Smith Allen

Takings £350 £180 £220 £430 £200 £250 £300 £290 £390 £310 £310 £250

This is the relation R(FID, Title, CID, Cname, Loc, MID, MName, Takings) Title is only dependent on FID Cname, Loc, MID, MName are only dependent on CID Takings is dependent on both FID and CID Therefore 2NF is FILM(FID, Title) CINEMA(CID, Cname, Loc, MID, MName) TAKINGS(FID, CID, Takings) In Cinema, the non-key attribute MName is dependent on MID. This means that it is transitively dependent on the primary key. So we must move this out to get the 3NF relations FILM(FID, Title) CINEMA(CID, Cname, Loc, MID) TAKINGS(FID, CID, Takings) MANAGER(MID, MName)

4.6 - 12

There are in fact four altogether. In the earlier example we had the four relations DELNOTE(Num. CITY_COUNTRY. 3. Description) DEL_PROD(Num. ProdID) In an E-R diagram DELNOTE.3. Country) PRODUCT(ProdID.6 (c) Entity-Relationship (E-R) Diagrams Entity-Relationship (E-R) diagrams can be used to illustrate the relationships between entities. These are one-to-one one-to-many many-to-one many-to-many represented by represented by represented by represented by Fig. CustName. CITY_COUNTRY. City) CITY_COUNTRY(City. Entities have the same names as relations but we do not usually show the attributes in E-R diagrams.6 .6 (c)1 is the E-R diagram showing the relationships between DELNOTE. We now consider the relationships between the entities. Each DELNOTE can be for only one CITY_COUNTRY because a City only occurs once on DELNOTE Each CITY_COUNTRY may have many DELNOTE because a City may occur on more than one DELNOTE Each DELNOTE will have many DEL_PROD Num in DELNOTE could occur more than once in DEL_PROD Each DEL_PROD will be for only one DELNOTE because each Num in DEL_PROD can only occur once in DELNOTE Each PRODUCT will be on many DEL_PROD PRODUCT can occur more than once in DEL_PROD Each DEL_PROD will have only one PRODUCT because each ProdID in DEL_PROD can only occur once in PRODUCT The statements show two types of relationship.13 . PRODUCT and DEL_PROD are called entities. PRODUCT and DEL_PROD. 4.

Cname. If there are any one-to-one relationships. 3. FILM connected by FID takes is for takes is for TAKINGS CINEMA connected by CID MANAGER connected by MID TAKINGS manages managed by CINEMA These produce the ERD shown in Fig. one of the entities can be removed and its attributes added to the entity that is left. Loc. the E-R diagram will not contain any many-to-many relationships. MName) in 3NF.6 . Title) CINEMA(CID. We have the following relationships.14 . Takings) MANAGER(MID.6 (c)1 If the relations are in 3NF.6 (c)2. CID. 3. MID) TAKINGS(FID. Let us now look at our solution to the cinema problem which contained the relations FILM(FID. 4.DELNOTE CITY_COUNTRY DEL_PROD PRODUCT Fig.

15 . 4. Num is the key and. 3.6.c. if there is more than one screen. CustName.1 (c) discussed the design of screens and forms. Fig. CINEMA LINK_ENTITY FILM If you now look at Fig. you will see that the link entity is TAKINGS. therefore. 3.2. City. it is easy to move between them. The main thing to remember when designing screen layouts is not to fill the screen too full.6 (c)3 shows a suitable form. Let us consider a form that will allow us to create a new entry in DELNOTE which has the attributes Num.CINEMA MANAGER TAKINGS FILM Fig. Form Design Section 2. data amendments and for queries. Many-to-many relationships are removed by using a link entity as shown here. All that was said in that section applies to designing forms for data entry. You should also make sure that the sequence of entering data is logical and that. 3.6 (c)2 In this problem we actually have the relationship CINEMA shows many FILMs FILM is shown at many CINEMAs That is CINEMA FILM But this cannot be normalised to 3NF because it is a many-to-many relationship.6 . it should be created by the database system.

3. is to enter the customer's name. 4. In this case we shall need to identify the customer before entering the order details. If the City exists in the database.Entered by the system Appears automatically when City is completed if in database. This is best done by entering the customer's ID.6(c)4 shows a form that is in two parts. Can use drop down lists to complete Add details to database Cancel and leave blank form on the screen Fig.6 .16 . this is not always known. then Country will appear automatically. in this case.6 (c)3 Close the form With this form. However. The upper part is used to identify the customer and the lower part allows us to enter each item of data that is on the customer's order. Now let us design a form to allow a user to input a customer's order. An alternative. Fig. 3. The data entry form should allow us to enter either of these pieces of data and the rest of the details should appear automatically as a verification that the correct customer has been chosen. if a new City is input the user can input the Country and the City_Country table will be updated.

4.Enter either the customer's number OR the customer's name. Again the user can choose from this list. town and county details are displayed and the user is asked for the house number.17 . In this case. In order to be consistent.6 . because the form requires a customer ID (Number). the positions of the boxes for customer details is the same on the Order Entry form as on the Add New Delivery Note form. Customer details Entered by the user Order details Entered by the system Add item to order and clear the order detail part of the form Clear all boxes ready for a new customer Fig. 3. It is usual for both these forms to be password protected. This is a very simple example. This ensures that only authorised personnel can enter data into the database. Some systems allow the post code to be entered in order to identify the address. Other systems allow the user to enter a dummy ID such as 0000 and then a list of customers appears from which the user can choose a name. The other three boxes will then be completed automatically by the system. Also. orders can only be taken for customers whose details are on the database. Alternatively. This ensures the entry of customer details before an order can be entered. the street. part of the name can be entered and then a short list of possible names is displayed.6 (c)4 Close the Order Entry form Notice how certain boxes are automatically completed. We have seen one way of overcoming this which satisfies the needs of the problem given. Suppose the customer's ID is not known.

Deletion and modification screens are similar, but must be password protected as before so that only authorised personnel can change the database. A query screen should not allow the user to change the database. Also, users should only be allowed to see what they are entitled to see. To see how this may work, let us consider a query requesting the details of all the cinemas in our second example. The view presented to the users will give details of cinema names. locations, manager names and film names as shown in Fig, 3.6 (c)5. Cinema Odeon Embassy Palace Odeon Embassy Palace Classic Roxy Odeon Odeon Odeon Roxy Location Croyden Osney Lye Croyden Osney Lye Sutton Longden Croyden Sutton Croyden Longden Manager Smith Smith Jones Smith Smith Jones Allen Allen Smith Allen Smith Allen Film Jaws Jaws Jaws Tomb Raider Tomb Raider Tomb Raider Tomb Raider Tomb Raider Cats & Dogs Cats & Dogs Colditz Colditz

Fig, 3.6 (c)5 However, another user may be given the view shown in Fig. 3.6 (c)6. Cinema Odeon Embassy Palace Odeon Embassy Palace Classic Roxy Odeon Odeon Odeon Roxy Location Croyden Osney Lye Croyden Osney Lye Sutton Longden Croyden Sutton Croyden Longden Manager Smith Smith Jones Smith Smith Jones Allen Allen Smith Allen Smith Allen Film Jaws Jaws Jaws Tomb Raider Tomb Raider Tomb Raider Tomb Raider Tomb Raider Cats & Dogs Cats & Dogs Colditz Colditz Takings £350 £180 £220 £430 £200 £250 £300 £290 £390 £310 £310 £250

Fig. 3.6 (c)6 Another user may be given all the details, including the cinema and manager IDs. Notice that the columns do not have to have the same names as the attributes in the database. This means that these names can be made more user friendly. In order to create the query a user will normally be presented with a data entry form. This form may contain default values, as shown in Fig. 3.6 (c)7, which allows a user

4.6 - 18

to list cinemas that have takings for films between set limits. This film allows users to choose all the films, all the cinemas and all locations or to be more selective by choosing from drop down lists. When the user clicks the OK button a table, such as those given above, will appear. Fig. 3.6 (c)7 In this Figure, the boxes are initially completed with default values. In this case, if the OK button is clicked, all cinemas and films would be listed. However, suppose we want to know which films at the Odeon, Croyden took less than £400. The user could modify the boxes, using drop down lists, as shown in Fig. 3.6 (c)8. Fig. 3.6 (c)8 When the OK button is clicked, a report like that shown in Fig. 3.6(c)9 would appear together with a button allowing the user to print the results or return to the query form.

4.6 - 19

Fig. 3.6 (c)9

4.6 - 20

3.6 (d)

Advantages of Using a Relational Database (RDB)

Advantage Control of data redundancy

Notes Flat files have a great deal of data redundancy that is removed using a RDB. Consistency of data There is only one copy of the data so there is less chance of data inconsistencies occurring. Data sharing The data belongs to the whole organisation, not to individual departments. More information Data sharing by departments means that departments can use other department's data to find information. Improved data integrity Data is consistent and valid. Improved security The database administrator (DBA) can define data security – who has access to what. This is enforced by the Database Management System (DBMS). Enforcement of standards The DBA can set and enforce standards. These may be departmental, organisational, national or international. Economy of scale Centralisation means that it is possible to economise on size. One very large computer can be used with dumb terminals or a network of computers can be used. Improved data accessibility This is because data is shared. Increased productivity The DBMS provides file handling processes instead of each application having to have its own procedures. Improved maintenance Changes to the database do not cause applications to be re-written. Improved back-up and recovery DBMSs automatically handle back-up and recovery. There is no need for somebody to remember to back-up the database each day, week or month. Disadvantages are not in the Specification for this Module.

4.6 - 21

6 (e) The Purpose of Keys We have used keys in all our earlier examples to uniquely identify tuples (rows) in a relation (table). Name. An attribute is a foreign key in a relation if it is the primary key in another relation. CINEMA(CID. In some cases more than one attribute.6. In this case we say that EmpID and NINumber are candidate keys. MID) MANAGER(MID. 4. Address) Clearly. NINumber. MName) We see that MID occurs in CINEMA and is the primary key in MANAGER. A key may consist of a single attribute or many attributes. Now look at these two relations that we saw in Section 4.3. Loc. Cname. could act as the primary key.6 . NINumber could also act as the primary key as it is unique for each employee.22 . If we choose EmpID as the primary key. The key used to uniquely identify a tuple is called the primary key. In CINEMA we say that MID is the foreign key. Suppose we have the relation EMP(EmpID. EmpID could act as the primary key. Foreign keys are used to link relations. in which case it is called a compound key.4. then NINumber is called a secondary key. or group of attributes. However.

23 . While this is taking place users must not be able to access the database. However. For example. One is to only use the database for querying prices and to create a transaction file of sales which can be used later to update the database. In this case the DBMS will recognise the different password and give a higher level of access to the nurses that to the receptionists. In this case the one user will be able to change the contents of the database while the other will only be allowed to query the database. even if the 4. This can be achieved by giving nurses a different password to the receptionists. All three categories of user of the database. So far we have only mentioned the use of passwords to give levels of security.3. When a receptionist logs onto the network the DBMS will check the password and will ensure that the receptionist can only access the appropriate data. users will not be able to use a cash point. Now the terminals on the wards will be used by nurses who will need to see what drugs are to be administered. in a banking system. nurse and consultant. This can be done by means of passwords. must only be allowed to see the data that is needed by them to do their job. This can be done by giving them another password. receptionist. they may not have access to the patients' medical histories. Now suppose they want to see a patient's record. Both consultants have the right to see all the data that is in the database but the terminal is in a public place and patients and receptionists can see the screen.6 . the receptionist should not have access to the drugs to be administered nor to the patient's medical history. accounts must be updated with the day's transactions. Therefore nurses should have access to the same data as the receptionists and to the information about the drugs to be given. suppose two consultants are discussing a case as they walk through reception. the consultants will want to access all the data. All the terminals have access to the patient database which contains details of the patients' names and addresses. This means that. Thus.6 (f) Access Rights Sometimes it must not be possible for a user to access the data in a database. Consider a large hospital that has a large network of computers. drugs to be administered and details of patients' illnesses. Similarly. while a database system is checking stock for re-ordering purposes. at certain times of the day. However. Finally. There are terminals in reception. on the wards and in consulting rooms. the POS terminals will not be able to use the database as each sale would change the stock levels. Incidentally. Another occasion is if two people have a joint account and one of them is withdrawing cash from a cash point. That is. However. there are ways in which the POS terminals could still operate. It is often important that users have restricted views of the database. the receptionists' passwords will only allow access to the information to which receptionists are entitled. It is important that when a patient registers at reception the receptionist can check the patient's name and address.

24 .consultants enter the correct password. the system should not allow them to access all the data. This is a hardware method of preventing access.6 . All terminals have a unique address on their network cards. 4. refusing to supply the data requested. This can be achieved by the DBMS noting the address of the terminal and. because the terminal is not in the right place. This means that the DBMS can decide which data can be supplied to a terminal.

indexed and fully indexed files.3. The internal view of the data occurs at the internal level. EXTERNAL LEVEL (Individual users) User 1 User 2 User 3 CONCEPTUAL LEVEL (Integration of all user views) Company Level INTERNAL LEVEL (Storage view) DISK/FILE organisation Fig. The DBMS is a piece of software that provides the following facilities. by the database designer.6 (g) Database Management System (DBMS) Let us first look at the architecture of a DBMS as shown in Fig. A DBMS such as Microsoft Access allows the user to avoid direct use of a DDL by presenting the user with a design view in which the tables are defined. The DDL cannot be used to manipulate the data.25 . 3. Application programs will use a data manipulation language (DML) to create these views. At the conceptual level there is one view of the data. The DBMS contains a data definition language (DDL). to define the tables of the database. This view is an abstract representation of the whole database. tables are created that hold data about the data in the database.6 (g)1. When a set of instructions in a DDL are compiled.6 (g)1 At the external level there are many different views of the data. This is hidden from the user by the DBMS. This view represents the total database as actually stored.6 . The Structured Query Language (SQL) contains facilities to do this. The DDL is used. It allows the designer to specify the data types and structures and any constraints on the data. the attributes in a relation and 4. it holds information about the data types of attributes. That is. 3. Each view consists of an abstract representation of part of the total database. It is at this level that the data is organised into random access.

Data about data is called meta-data.any validation checks that may be required. These tables are stored in the data dictionary that can be accessed by the DBMS to validate data when input. This language allows the user to insert.6 . The other language used is the data manipulation language (DML). 4. SQL includes this language. Access allows a user to avoid directly using the DML by providing query by example (QBE) as was mentioned in Section 3. The data dictionary contains tables that are in the same format as a relational database. modify and retrieve data. The DBMS normally accesses the data dictionary when trying to retrieve data so that it knows what to retrieve.26 . This means that the data can be queried and manipulated in the same way as any other data in a database.5 (j). delete. Again. update.

4.27 . A company employs engineers who service many products. When engineers service products they complete a repair form. A customer may own many products but a customer's products are all serviced by the same engineer. Each form has a unique reference number. one form for each product repaired.6 . In order to do this.Appendix: Designing Databases Although not stated as part of the syllabus. When a repair is complete. one form for each product repaired. you must first analyse the problem to see what entities are involved. The form contains details of the customer and the product that has been repaired as well as the Engineer's ID. The form contains details of the customer and the product that has been repaired as well as the engineer's ID. A company employs engineers who service many products. This suggests the following entities. particularly when normalising a database. When an engineer has repaired a product. the customer is given a copy of the repair form. one form for each product repaired. Each form has a unique reference number. When engineers service products they complete a repair form. This is done here. The easiest way to do this is to read the scenario again and to highlight the nouns involved. the customer is given a copy of the repair form. These can usually be established by highlighting the verbs as done here. Each form has a unique reference number. Consider the following problem. The form contains details of the customer and the product that has been repaired as well as the Engineer's ID. A customer may own many products but a customer's products are all serviced by the same engineer. engineer product customer repair form Now we look for the relationships between the entities. When a repair is complete. When engineers service products they complete a repair form. The task is to create a database for this problem. These are usually the entities involved. A customer may own many products but a customer's products are all serviced by the same engineer. This suggests the following relationships. students may find the following to be of value. the customer is given a copy of the repair form. A company employs engineers who service many products.

Which leads to the entity relationship diagram (ERD). Only one product can be on a form but a product may be on many different forms. services ENGINEER completes serviced by PRODUCT owned by completed by FORM given to CUSTOMER owns is given There are two many-to-many relationships that must be changed to one-to-many relationships by using link entities. many customers own washing machines. For example. For example. 4. This is shown below. A customer may receive many forms but a form is given to only one customer. A customer may own many products and a product can be owned by many customers.6 .Relationship engineer services product Type many-to-many customer owns product many-to-many engineer completes form customer is given form product is on form one-to-many one-to-many one-to-many Notes An engineer services many products and a product can be serviced by many engineers.28 . An engineer completes many forms but a form is completed by only one engineer. many engineers service washing machines.

… ) CUST_PROD(CustomerID.5 (c)). but you should always check that they are. EngineerID. The next diagram shows the life history of an engineer in our previous problem.29 . … ) FORM(FormID. Name.services ENGINEER completes ENG_PROD serviced by PRODUCT owned by CUST_PROD completed by FORM given to CUSTOMER owns is given This suggests the following relations (not all the attributes are given). Another useful diagram shows the life history of an entity. This simply shows what happens to an entity during its life. Description. … ) ENG_PROD(EngineerID.6 . An entity life history diagram is similar to a JSP diagram (see Section 3. Name. … ) These are in 3NF. CustomerID. ENGINEER(EngineerID. ProductID) PRODUCT(ProductID. 4. ProductID) CUSTOMER(CustomerID.

Similar diagrams can be created for the other entities. When the engineer leaves the Company. he/she may change their name. A new record for an engineer is created when an engineer joins the Company.Engineer Starts work Works for Company Leaves Company 12 months elapse Detail * changes Name change Address change Telephone number change This tells us 1. address or telephone number as many times as is necessary (hence the use of the *).30 . the main life-cycle ends and the engineer's record is updated to indicate they no longer work for the Company. While the engineer is working for the Company. 2. 12 months after the engineer has left the Company his/her record is archived and removed from the database. 3. 4.6 . 4.

TEACHERS (6) Explain what is meant by a foreign key. (3) 4. 4. 3.6 1. Every student in a school belongs to a form. TUTOR. (4) Explain what is meant by a table being in second normal form. Describe the advantages of storing this data in a database rather than in a series of flat files. 2.31 . FORM. Every form has a form tutor and all the form tutors are members of the teaching body. Draw an entity relationship diagram to show the relationships between the four entities STUDENT.6 .3. Example Questions A large organisation stores a significant amount of data.

In order to do this. If the sales figures are only used once a week to update the stock database. Indeed. If the organisation also keeps data showing the rates of sales of products. Keeping data about previous borrowers. 6. the stock situation is always up-to-date. First it means that the organisation should rarely run out of stock which would cause a loss of sales if it were to happen and. data about products in stock and rates of sales is valuable as they improve the profitability of the organisation.7 (a) The Value of Data and the Use of Databases Data can be very valuable to an organisation providing it can be clearly analysed. This will lead to better sales campaigns in the future.1 . They offer mortgages. as soon as the amount in stock falls below a reorder level. how does the senior executive in one country know what is happening in other countries? Modern companies keep databases that can be accessed on a worldwide basis. value added network services (VANS) are used. improving the profitability of the company. This automatic stock reordering has two cost effects. many systems trigger the reordering automatically as soon as the number in stock falls below its reorder level.Chapter 3. Another example is of an international company that has run two advertising campaigns in two different countries. As the data about stock can be updated each time a stock item is sold. However. insurance and business support. it is important that the bank is aware of the risks involved. the stock levels are soon out of date and the data have little value. It also means that the organisation should not need to store large quantities of stock which would lead to high inventory costs. The one was much more successful than the other. This means that. the data used is very valuable to the bank.7 (c). In order for data to be of value they must be accurate and up-to-date. This is often done by the system sending the order to the supplier using electronic data interchange (EDI). and comparing the data for a potential new borrower with the historical data can help to determine whether or not to make the loan. banks offer services other than banking. These simplify the exchange of data between users of the service by using computer networks. Thus.1 . an order can be placed. This is discussed in Section 3. An early example of the value of data is the use of stock control systems. hence. the system can recognise changes in these rates and so change its ordering patterns. If a bank is considering a loan. such as age.7 Use of Systems and Data 3. It is important that the company keeps data about the two campaigns in order to determine why the one campaign was more successful than the other. This is often done using artificial intelligence (AI) techniques and leads to fewer people reneging on their loan. Thus. Often data are inaccurate due to them not being frequently updated. income and social background. These days. loss of income.

A great deal of work is being done on data mining as many companies can make use of the results. This system is also used by solicitors having access to local authority databases for conveyancing purposes. estate agents may share a VANS in order to match potential buyers with sellers over a much wider area than is possible if each estate agent only has access to their own data. A VANS may operate in a single company or may be of use to several companies. This means that the data have increased in value. some companies sell lists of people who may be valuable customers to other companies.1 .2 . The ability to sift through data to find patterns such as • • • finding people who are most likely to respond to 'junk mail'. For example. Eventually VANS will operate on a world-wide basis. users plug into the interface provided by the VANS operating company and the software does everything else.In these systems. This is often achieved using data mining techniques. A lot of work is going on to develop sophisticated data mining software which looks for patterns in vast quantities of data. which products (such as bread and milk) are most often sold together in a supermarket. 6. Thus data that was only of value to a small number of users is now of value to many more. which people are likely to live longest. Indeed. One of the problems with so much data being available is trying to sift the data for useful information. can lead to much better targeting of customers with the result that there are better returns on investments.

there are many different formats that store sound in digital form. The method of transferring data over a wide area is usually by means of ISDN (integrated services digital network) connections. They are not common outside the UK education market. These are used to transfer tabular data between applications. CDs sample at the rate of 44. It is these techniques that allow pictures to be quickly transferred over the Internet. Picture files. if two computers need to communicate. Most homes use analogue connections to the local exchange but after that ISDN is used as shown in Fig. Thus 3 minutes of music requires 3 x 60 x 96. Each field is separated by a tab character. There are many different formats such as BMP (bit mapped). They include information about fonts.6 in the AS text. A typical DVD can hold 4. Not only must file formats be standardised but also communication methods. These are used to transfer tabular data between applications. it is essential that both are sending and receiving data in the same format.3 Gbytes or 13 hours of music.000 = 16Mbytes. Each field is separated by a comma. 3. WAV files are common on PCs. Rich Text Format files. Storing sound requires a great deal of memory. colour and styles. GIF (Graphical Interchange Format) and MPEG (Moving Picture Experts Group). These are a complex format used to store data from a word processor. Standard Interchangeable Data files.3 . receive and interpret the data correctly. Tab Separated Variable files. Text files are used to transfer data between application packages. JPEG (Joint Picture Experts Group).000 samples/sec.1 . MPEG has also allowed the introduction of many more television channels through a more efficient use of the bandwidth available over the media used. Sound files. These are used to hold characters represented by the ASCII code. As with picture files. Without standards there would be a proliferation of formats and it would not be possible to move data electronically. JPEG and MPEG involve compression techniques. As communications are world-wide and there are a multitude of computer manufacturers. sizes. Comma Separated Variable files. ISDN is used by telephone companies to connect digital exchanges.3. It is useless if one computer sends in one format and the other is expecting the data in a different format. These are used to represent sound/pictures in digital format. These are used to transfer tabular data between applications.7(b)1.100 samples/sec and DVD (Digital Versatile Disk) at 96.7 (b) Standardisation In order to be able to share data successfully some form of standardisation is needed so that users can send. The data consists of individual characters and there is no formatting applied to the characters. 6. it is essential that standards are set for consistency. Text files. Some mention of this was made in Chapter 1. Some typical standards used for files are given below. For example.

one type for transmission from the network to the terminal and the other for transmission from the terminal to the network. This system can use the same wires as in current telephone networks. The difference is the number of channels and the methods used to deliver the services to the user. The three channels are multiplexed onto a single communications medium. There are two standard ISDN services known as primary rate access (ISDN 30) and basic rate access (ISDN 2).4 . The standard used is Open Systems Interconnection 6. 3. It is necessary to package this data into some standard format first.1 . it is not sufficient to package data into a format that can be sent along ISDN connections. Data is packaged into frames. This ensures that the data can be reassembled properly when received. pictures. ISDN 30 provides 30 B-channels and one D-channel. The data may represent sound. Each type of frame consists of 48 bits that have to be in a prescribed order. ISDN 2 will probably be used by most small business and individual users. Its operation is basically the same as ISDN 2 but 30 channels are multiplexed instead of two. It provides two channels at 64kbps (B-channels) and a signalling channel of 16kbps (Dchannel).Digital links Digital Exchange Digital Exchange Digital Exchange User Analogue links Fig. text or many other things. In order that data are understood when received.7(b)1 User ISDN has a standard format that is used world-wide. It is used by large customers and is usually delivered by fibre optics.

only one of the subdivisions (actually called ‘layers’) needs to be altered. the whole protocol would need to be altered. The OSI model is simply a set of rules (protocol) for the transmission of data from one piece of hardware to another. In all the OSI model has 7 subdivisions (other models have more or fewer. The point being that if the whole protocol was treated as a single entity then every time a small change was necessary.Reference Model usually simply called the OSI model. but all work on the same basic principle). 6. but these can also be subdivided. in the OSI system. However. This is an obvious subdivision for the rules that are needed.1 . perhaps a different peripheral being added to a system or a different software being used. These rules will have to cover the medium used for the transmission and then rules about the software itself.5 .

Originally. These methods of communication have reduced travel costs as meetings can be held without people leaving their desks. Mobile phones rely heavily on computers to route calls. An extension of this is EDI (electronic data interchange). Because computers can maintain very large databases. It differs from email in that the data is highly structured into fields such as sender's name. access their own accounts at any time and see what calls they have made and the costs of these calls. This is no longer necessary as videoconferencing can now be done using standard PCs and a video camera. Many companies insist on using this method of ordering and invoicing. 3. Retailer Order Payment Customer Computer Invoice Delivery Note Price List Computer Fig.7 (c) Computers and Communication Computers are now used to aid communication between many devices and to provide extra facilities that were not available with the old telephone networks. EDI allows users to send and receive order details and invoices electronically. Electronic commerce (e-commerce) is becoming more popular. These systems also allow the use of voicemail. Voice mail digitises spoken messages and stores them on disk. using the Internet. product code. quantity.7 (c)1 shows how this works. it is possible for users to have itemised bills. Digital telephone systems provide many facilities. When recipients access the messages they are converted back into sound. whereas email is completely unstructured in that it is simply text. recall stored numbers and to have accurate timing of calls. order number.3. recipient's name. In this system whiteboards can be used to produce drawings that can be transmitted electronically. It is quite common to order goods over the Internet. Many companies use computers to maintain large databases that can be queried by customers online who may then place orders.6 .7 (c)1 Teleconferencing allows a group of people to communicate. 6. special rooms were required for videoconferencing. Fig. Although itemised bills can be sent out on a regular basis. users can. throughout the world.1 . Video conferencing is similar to teleconferencing but also allows users to see one another. 3. simultaneously using telephones and group email.

The main problem is security of information and people are needed to create secure systems for EDI. It is also worth reading Business @ the Speed of Thought by Bill Gates published by Penguin Books (ISBN 0140283110). goods on the Internet. For example. 6. Estate agents can set up sites that enable them to sell property throughout the world. doctors can request advice using the WWW.7 (d) New Business The Internet allows communication on a world-wide basis. This means that people will be needed to create Web sites.3. Organisations can advertise all round the world from a single site.7 . The applications are endless and you should keep abreast of modern developments as they are published in the media. The use of the Internet by media reporters can mean that news can be quickly updated and that information is in electronic form. This means that advertising can be relatively cheap. Users can transmit their details and orders over the Internet at very little cost. medical advances can be posted on the WWW that can then be accessed world-wide. It is also possible to allow users to order. and pay for. Organisations can create Web sites that advertise their goods and let users have access to their product databases. This means that it can be manipulated for use on other media. to keep them upto-date and to manage large databases of goods and customers.1 . It also means that it is easier to sell goods throughout the world. Another area of expansion is in providing information. Indeed. There is no need to advertise in each individual country.

In future a lot of this help will be provided electronically by means of databases that hold data about frequently asked questions (FAQs). This speeds up the work. Application packages are continually being upgraded and new applications are being created daily. most of these help desks involve large numbers of people. Young people are growing up in an IT environment and receive basic training in its use. insurance and other services. older generations find using IT daunting and need careful and appropriate training. Also. They have had to be retrained as sales persons as banks now sell mortgages. This is because they need to look at their work and their notes at the same time. at a later date. 6. However. This means that all workers on a project know the current stage of development of that project. Bank clerks used to add up columns of figures. say. It is also important that courses provide sufficient time for the learners to practise new skills and to be provided with sufficient notes to enable them to redo tasks. It is very easy to alienate learners by teaching them how to use software facilities that they will never use. Organisations are setting up help desks for customers to contact when they have a query. Online help is not enough. IT is an ever-changing subject. what is to be done with the people who used to do the welding? They will have to be retrained to do a different job. At present. training is needed in these new working methods. learners like to flick back and forth through their notes and this is much easier when the notes are on paper. the packages taught need to be pertinent to the jobs carried out by the learner. now they press keys on a keyboard. This means that the operators of the help desks will have to be retrained to create these databases. However.7 (e) Training Training in the use of IT is essential if users are to make the best use of it. set during the course. This may be as simple as switching on a PC and loading software or may involve the use of particular packages. In the latter case. once a week. which means that users continually need retraining. Adjusting the size of windows so that the work and the notes are both on the screen at the same time is often unsatisfactory. However.8 .3. Training in the use of IT is not sufficient in itself. the workers can keep one another informed of progress when it happens.1 . Employees can be trained to use email but also need training in how email can be used to enhance their work. particularly to prevent an overloading of email communications. Robots weld cars. they are now expected to provide new services to the customer other than handling cash and cheques. most people prefer to have their notes in printed form. Instead of groups of workers meeting. IT is changing the way things are done all the time.

The next step was to go back to the office and prepare a quotation which was then sent to the customer. This seems like a balance of job lost against jobs gained. to prepare a quotation on the spot. Stock levels are kept on computer databases and need to be checked occasionally in case stock is removed without passing through point-of-sale terminals. many of them intelligent and robotic. This book has been produced in electronic format so that you can read it on a screen and print it off for later use. 6. email it home and continue working on it later at home. The company payroll is fully computerised with money being transferred electronically from employer's bank to employees’ banks. Now a laptop and a modem can allow the sales people to access the company's database from customers' premises. People expect much higher quality in documents. It is quite common for people to work on a project in the office. Fewer people are needed in the assembly process because of more machines being used. This means that they can now book hotels for customers other than the one in which they work. the sales person had to go back to the office to get details.9 . Now. This allows them to spend more time with customers. Staff who work in stores only take stock a few times a year instead of weekly. more technicians are needed to maintain the automated plant. Like banks. (This may be due to products being damaged or stolen. with comments. At one time a sales person went to a customer with a catalogue and a price list. Students expect teaching materials to be of a higher standard. Hotel receptionists have access to a database for all the hotels in a group.1 . but it is more complicated because the jobs lost are normally low skill while the new jobs are high skill. Students then post their work to their tutors electronically. Tutors view the work on screen and return the marked work.7 (f) Changing Work Patterns These were mentioned in the previous Section. electronically. If a customer wanted something unusual. whether it is posters or letters. with suitable software. Office personnel use computers to produce invoices using databases of orders. factories have seen major changes in working patterns. This movement of skill levels in the work force has major implications for the education of people and also means that many who were employed may not be able to learn new skills and hence get new jobs.3. There is a consequent social problem in society of a whole new underclass of people who are unable to gain satisfactory employment. At one time someone went to the customer's house and measured all the windows.) Teachers and lecturers often set assignments using computer networks. No longer do wages clerks have to calculate wages and count money into pay packets. the sales person can use a laptop. A similar example is that of selling double-glazing. delivery notes and customers. This means that your school or college only has to have one copy of the book and it can be shared using a computer network. However.

This increase in accuracy has lead to an increase in quality. 6. Self. more consistent. quality. This increase in quality has led to fewer faults in end products such as motor cars.Products can be manufactured to a much higher standard because of the use of computerised machines and robots. However. mechanics spend more time servicing vehicles and less time correcting errors in manufacture. This means that.10 . Children's building toys look much better because the components are more accurately made and are of better.assembly furniture is easier to put together because the parts are made more accurately.1 . in the case of motor cars. the increase in quality has also led to a reduction in the need to service motor vehicles.

11 . As all the examiner comments have already been made.1 . any content here would simply be a repeat of what has gone before. 6.3.7 Example Questions Example questions are not offered here as all the work is either a repeat of previously visited work or is based on definitions that can be taken straight from the text.

8.1 These steps have been explained. The system may be manual. in Chapter 1.8.a.1 .7.1 shows the stages involved when using SSADM.2 .a. informally.8 (a) Techniques for Developing Computer Systems You have already used techniques such as entity models and normalization in Chapter 3.6. Implementation.8.1. Feasibility Study Requirements Analysis Requirements Specification Logical System Specification Physical Design Fig. In this Section we shall show how diagrams can help the development of the stages shown in Fig. Another useful technique is the Structured Systems Analysis and Design Method (SSADM).a.8 Systems Development. You do not need to know the techniques of SSADM but Data Flow Diagrams (DFDs) are important. 3. 3. Chapter 1. 6.7 discussed the system life cycle and techniques that can be used to develop computer solutions. DFDs provide a graphic representation of information flowing through a system. computerized or a mixture of both.Chapter 3. Management and Applications 3. Fig. 3.

8 (a)2 All names used should be meaningful to the users.2 .g. Customer) e. analysts and programmers. 6. is easy to understand by users. whether they are computer literate or not. 2 Accounts Dept Process Produce Invoices Data Flow e. gives an overview of the system. ensures quality. Order D1 Data Store e.g. is a good design aid. 3. D1 Customer Orders Fig.2 . 3.The advantages of using DFDs are that it • • • • • • • is a simple technique.g. can act as a checking device. clearly specifies communications in a system.g. These are shown in Fig. Entity Outside environment (e. DFDs use only four symbols.8 (a)2.

Production of invoices. 3. 5. Notes e. VDU screens.8 (a)1. e. phone messages.8 (a)1 Fig.4 Calculate net wage Fig.8 (a)3 shows the different levels that can be used in DFDs. 4. 10.g.1 Validate Data 2. documents.3 Calculate deductions 2.8 (a)3 6. 9.2 . Identify the external entities. Customer. Check that meaningful names have been used. 8. What is inside the system and what is not. Check that all processes have data flows entering and leaving. 7. Identify interactions. 0 Payroll System Level 1 (Top Level) 1 Get hours worked 2 Calculate wages 3 Produce wage slips Level 2 (Lower Level) Level 3 (Not always needed) 2.The steps to be taken when developing DFDs are given in Table 3. Fill in the details. Step 1. Identify the interaction between the data stores and the processes. individuals. Agree the system boundary. payroll production. 3.g. 6. Check with the user that the diagram represents what is happening now or what is required. 3. Identify functional areas. Table 3. Supplier e. delivery notes. e. Identify dataflows. Identify the paths taken by the dataflows identified in step 1. Departments. Determine which data are to be stored and where.2 Calculate gross wage 2. Identify data paths.g. 2. Validate the DFD. Identify the processes.g. Identify data stores.3 .

It also receives confirmation of bookings.4 . Customer Enquiry Drinks Bill Reply Confirmation of booking Final Bill Payment Receipt Customer Details D1 Customer Details Customer Details Food Bill 1 Food Order Restaurant Drinks Bill D2 Customer Accounts 1 Reception Drinks Order 1 Bar Customer Process bookings and accounts Customer's expenditure Process bookings and accounts Customer Food Bill Process bookings and accounts Fig.8 (a)4. any expenses incurred by the guest are entered into the database by the appropriate personnel. While a guest is resident in the hotel. they have to sign a bill which is passed to a receptionist who enters the details into the database. The flow of data in this system is shown in Fig. When guests leave the hotel they are given an invoice detailing all expenditure. When they pay. Most of these are by telephone.Now consider the following scenario. These are entered onto a computer database.2 . If guests purchase items from the bar or restaurant. 3.8 (a)4 6. A hotel reception receives a large number enquiries each day about the availability of accommodation. the database is updated and a receipt is issued. 3.

(If the project consisted of a single task it could hardly be called ‘major’). In data stores. 3. This does not mean that these symbols represent different customers. Usually there is more than one external entity. the customer. some may be possible at the same time. an external entity must be between the external entity and a process. as an example. 3. Data stores may also be duplicated. It may also be important to work out how long the project should take to complete. 3. Take. an external entity. or to. Also. Suppose we are dealing with a mail order company. has a diagonal line to indicate that it occurs more than once. the major project of building a bungalow.8 (a)5. one external entity is the customer. The example of the hotel system only shows one external entity. Major projects like this can be represented graphically to show the different tasks and how they join together. M1 Customer data Fig. or relate to each other. while with others it becomes important to do them in the correct order. This is done by having a double vertical line on the left hand side as shown in Fig.8 (a)4 were numbered D1 and D2. Clearly.8 (a)5 Notice this data store is numbered M1 whereas those in Fig. M indicates a manual store and D indicates a computer based data store.5 . Without this. It can be divided into a number of tasks.2 . another is the supplier. With a number of tasks.The symbol for Customer. It is simply used to make the diagram clearer. Note that although there are more than one customer and supplier. there would be too many flow lines between this symbol and the internal processes. there will be a number of different tasks to be carried out. in the diagram they are written in the singular. A Concreting the foundations takes 4 days B Building the walls takes 4 days C Making the doors and windows takes 7 days D Tiling the roof takes 2 days E Installing the plumbing takes 3 days F Doing the interior carpentry takes 4 days G Installing the electrics takes 6 days H Decorating takes 5 days 6. However. there can be no data flows between an external entity and a data store. The flow of data from. When a major project is undertaken.

but this is the method used by B and L Construction. 35 days. in days. it will only take as long as the longest task. needed to carry them out. 3.8 (a)6 shows when all the different tasks can start and when they must end. The circles represent stages and the arrows the tasks needed to reach that stage and the time.One way of deciding how long the bungalow takes to build is to add up all the separate times.8 (a)6 Fig. 7 days. 3. the decorating can’t be done before the roof is on! The real time for the project is somewhere between 7 and 35 days. and by how much.6 . This is silly. Finally. It shows which can overlap. H G F E D C B A 4 8 12 16 20 24 No of Days Fig. 6. On the other hand they are separate jobs so as long as enough people are working. it shows how long the project will take. (Your ideas of how a bungalow is built may be different.) Another type of graph might be similar to a flow diagram.2 .

node 3 could start immediately or wait a day without affecting the rest. Complex computing projects require effective management or they may get out of control. Node 1 must start immediately otherwise the walls (4) won’t be finished by day 8. Each node can have an optimum time worked out. Each node can also have a latest starting time before it holds up another node. The arrows show the order in which the tasks must be carried out. This is the critical path. There is now specialist project management software available that can take more complex projects than the one that we were considering and produce the type of analysis 6. It is also necessary to assess how long the different tasks will last so that other projects can book personnel. Different personnel will be needed for different tasks. so E (the plumbing) cannot be done before B (building the walls). Their time must be booked in advance so that they are free from working on other tasks or projects when they are needed. The bungalow cannot be built in a shorter time. This is the time to be sure of getting to node 6 whichever route you choose.4 1 3 A 2 7 C 4 B 4 2 D 5 3 E 6 G 4 F 6 1 2 3 4 5 6 7 Start Foundations finished Start making the windows and doors Walls finished Roof finished Interior finished Bungalow finished 5 H 7 There are many routes through the diagram.2 . Node 6 has an optimum time of 4+4+2+6 = 16 days. but can be done at the same time as tiling the roof (D). The one that gives the time taken to complete the bungalow is 1 2 4 5 6(G) 7 A total of 21 days. However.7 . This means that an accurate prediction of the start times of the various tasks must be made.

One possible answer is shown below. As an exercise try to draw a chart to help in the planning of the work for an A2 project.that we have been talking about. If the software is compatible with the diary software used by a firm then it can automatically book the workers when they are needed. Evaluation User documentation Technical documentation Implementation Testing Software development Design Analysis Nature of problem Time 6.2 .8 .

These diagrams help us to ask questions like Can a customer only have one product? Can a customer own many products? Can a student borrow many books? Thus. We can also ensure that we have included all the entities. the original specification must be accurate.3. in fact. as they should be very similar to those produced at the analysis stage. Indeed we should go back to the user to validate our design. This can cause problems. when we are asked to produce a solution. There is no code behind the interfaces to manipulate the data. At the design stage the diagrams.8 (b) The Purpose of Documentation It is important that the design of a solution is accurate BEFORE it is implemented. For the design to be accurate. will be modified to show exactly what we are going to produce. However.9 . A good way of doing this is to produce a prototype of your solution. Similarly. we can ensure that the relationships are correct. We can now design the user interfaces and check that they will allow the user to input the data required and output the results expected. An E-R diagram shows the relationships between entities so that we can check these relationships with the end user. Again these can be checked with the user. as each stage is developed. Fig. 3. This may be different from the analysis due to unforeseen constraints. This will appear to work but. we can move on to the design stage. When the interfaces have been designed they can also be checked against the ER and data flow diagrams. as often users think that they are seeing the real thing when there is still many months work needed to produce the final solution. we must make sure that we thoroughly understand the problem. One of the best ways of doing this is to use diagrams. it is checked against all previous stages.2 . This can only be achieved by checking our analysis with those who are going to use our system. our Data Flow Diagrams (DFDs) show how data is moving through the organization and we can ask questions like Are there any other data requirements? Are all data moving between the right departments? Are all the external entities present? Once we are sure that our analysis is complete and accurate. so far produced. This means that. This continual 6. by continually checking it with the end user. we can check that we have included everything required by the user. it only shows how the interfaces work.8 (b)1 shows that. Users are not usually technical people and so we require simple ways of showing our understanding of the problem. This continual cross-checking with previous steps is very important.

validation process is essential if we are to reduce the cost of maintenance due to errors and omissions. User Request Initial Study Feasibility Study Systems Analysis Systems Design Implementation Change Over Evaluation and Maintenance Fig. 3.10 .2 . The careful documentation also helps to maintain a piece of software when it is to be upgraded by adding extra facilities.8 (b)1 6.

So the speed of the processor is largely irrelevant to this particular task.2 .” This answer is a little bald.3. Strictly. The Art student decides that the images are too valuable to lose and opts for a DVD drive to act as a back up storage to the hard drive. on a computer with a 1. The English student has invested in an ink jet printer with a separate black cartridge because most of the work will be in black and white. 1.33 Gigahertz processor (1000 times faster) it would make no difference. My neighbour uses her computer in order to edit video material as part of a service that she offers to local industries.8 (c) Technical Requirements A quick look at any advert for computer hardware will make it obvious that different computer systems have different technical specifications. One will have 256 Megabytes of Ram while another will have 64 Megabytes. in her case she needs the faster processor. My computer would simply not be able to process the data quickly enough to produce satisfactory images without considerable jerking of the picture. a fast one so that it takes less time to produce each copy. the student can understand that the important thing is the need to satisfy the needs of the application rather than the need for the student to 6.11 . the answer that the examiner has put on the mark scheme will be out of date by the time the examination is marked. This is being typed. A student uses their computer to produce essays for their English course. I still can’t type any faster. there is no right answer to such a question.33 Megahertz processor. my neighbour’s digitised video is going to need all of the 70 Gigabyte hard drive that she has bought. The artist has a simple one cartridge printer because black will not be needed very often. One system will have a 700 Megahertz processor while another will have a 1. whilst another produces high quality colour pictures for an Art course. An examination paper cannot ask for the specification for a PC because everyone will have their own idea what specification will be appropriate and. What differences do the different specifications make? 2. and if so. anyway. If I had a 1. From these examples. The first student is storing relatively small text files while the other student is needing to store large quantities of data. “None. Is one of these systems preferable to the other. hopefully. What importance does it have for us when we are studying for an A level? To answer the second question first. but strictly true. My neighbour has clients who want large numbers of copies of the videos that she produces on CD’s to send to clients so she has invested in a CD writer. So the requirements of the syllabus come down to the first question – What specifications are important to allow the system to perform the operations expected of it? The speed of the processor is simply a measurement of the number of operations that are possible every second. which one? Two questions arise. using ‘Word’ word processing software. The English student will need to have a CDROM drive in order to load software to use.5 Gigahertz processor.

6.12 .memorise large quantities of data about system specifications which would be out of date very quickly anyway.2 .

alternatively the items can be held sequentially in an index and a program can be written to find the particular item by using a binary search of the index. The point being made is that different applications require different things from the computer system. All of these points are determined by the requirements of the application. Dependent upon the method of search the data needs to be stored differently. very much. If a single item needs to be found then a program can be written to find the details directly from the key field by using a hashing algorithm. a recap on work covered in the AS part of the course. The solution is to store the file in an indexed sequential format. just as they were expected to do in the AS part of the syllabus.2 . 6. and sequentially if the details are to be used for ordering of replacements.8 (d) Appropriate Response Times This section is.13 . At the point of sale the item required is identified by a laser scanner whereas at the head office the item name will likely be typed in at a keyboard. Students will be expected to be able to determine sensible types of hardware and software for particular applications dependent upon their characteristics.3. A classic example is the file of goods that needs to be accessed directly if it is to be used at the point of sale terminal.

2 .3.8 (e) Implementation Techniques The different methods for implementing new systems have all been explained before. and also to the notes on module 4. from the AS work. 6.14 . The attention of students is especially directed to Chapter 1. The inclusion here is simply to reinforce the ideas and forewarn students that they are likely to meet this topic in this examination as well as others in the past.7 the systems development life cycle. the project. for references to how to implement a system.

The outputs from systems should be studied to ensure that they are acceptable. rather there should be a continual process when managing a system. monitoring and maintenance of systems goes back to section 1. Software and hardware change on such a regular basis that. 6. In a subject like Computing. even if we are happy with our system. a lot of the work in this section refers to the work already covered in other sections. it is not reasonable to suggest that a thing has been done once and that it therefore does not have to be considered again.2 . This process of change should not be a static one. There are very few systems that are totally self-contained and when another system is updated our original system may no longer be compatible. where things are changing so very quickly.3. Monitoring and Maintenance of Systems As with so much of the work in this module. A firm should not sit back and wait for a change to be forced upon it. of measuring the system that is being used against what is currently available. the outside world is going to affect us and force change. a software (and hardware) audit.15 . The need for managing. but it should be up to date. this is quality control and the documentation must keep up with the rest of the system in order to provide the necessary information about the system to the various users.8 (f) Managing.7 in the AS text which was to do with systems analysis and the system life cycle. Not only should one be aware of the need for documentation.

Discuss the need for project management when a major project is being implemented.16 . Another system is designed for a graphic designer who sends work to clients electronically. (10) Describe how the forms of implementation: (i) Parallel running (ii) Phased (iii) Direct are carried out. (4) A computer system has been designed and produced for a person who works from home for a publisher of fiction books as a proof reader of manuscripts. Describe how the hardware specifications for the two systems would differ.3. 4. Example Questions Explain what is meant by the term entity model. 3. In each case describe one aspect of an application which would make that form of implementation appropriate in that case.8 1. 6. 2.2 .

Consider the case of the airline booking system. Notice that the rods moving is not immediate but will take place over a period of time. the computer makes an immediate decision and the graphite rods are now moved into place. When asked to describe a real-time application the first thing that needs to be described is the world of the application. A nuclear reactor may start to react too violently and sensors inform the computer controlling the reaction that this is happening. Many students would phrase their answer in the form of “The sensors spot that the reaction is too violent and the processor makes …”. . Everything else falls into place. In some real-time applications these comments may be reasonable.9 3. This is a real-time application. Students should then describe the hardware necessary to allow input and output from that world and the decisions that the software must take. the sensors are being credited with having processing power in that they can interpret the readings that are produced. Students should also be able to identify when a real-time system is appropriate as opposed to a system where the decision making is in some way delayed. A real-time system is one that can react quickly enough to data input to affect the real world. there is no hint at decision making on the part of the sensors.Chapter 3. Real-time Applications. the database must be updated before the next person has a chance to book a ticket. If this is true it implies that the output from the system must be produced quickly enough to produce the effect on the world outside the computer before that world has enough time to alter. however the decision was taken immediately. Here. Note also that the sensors simply report on the state of the world. Notice that the idea of working “incredibly fast” or “in billionths of a second” does not apply here. The use of a real-time system here refers to the concept that if a ticket is bought by a member of the public. but it depends on the ‘world’ that the application is concerned with.9 (a) Simulation and Real-time Processing. The computer takes the decision to insert the graphite rods to slow the reaction down. the input devices are the sensors that inform the computer of the state of the reaction. The “world” that we are talking about is the world of the database that contains all the booking details. The world of the application has been identified.

Never lose sight of the idea that the processor is limited in the amount of data that can be interpreted. The spring ones are like the pressure pad. A thermistor which is measuring the temperature for a chemical reaction will send different signals according to the temperature that it detects. A physical quantity is something that exists in the real world as opposed to the computer world. or that it has not. the switch would simply switch off the motor. Similarly. pressure. temperature. Examples would be length. Digital sensors produce an output that is digital. The signal is either that it has been trodden on. When the processor makes its decisions it must be able to take some action. it is this voltage which gives a measurement of the temperature. As the temperature increases the voltage produced by the thermistor increases. Most sensors are surprisingly simple. The idea of a sensor being a TV camera because it can show the processor what is going on in a large area is unrealistic because it would provide too much information. as is the software that the processor is running. held open by a spring which is overcome by the weight of the burglar. one is analogue whilst the other is digital. a burglar alarm may have a pressure pad by the front door which produces a signal if it is trodden on.9 (b) Sensors and Actuators A sensor is a device that measures physical quantities. but that the need to do so will be reported to the processor because it now has to make a decision about what to do next and the input from that sensor is going to be an important part of that decision. The question arises whether this is a sensor in the true sense of a sensor in computing. What would be possible would be a TV picture which could be scanned by a processor for any kind of movement in order to indicate the presence of a burglar.3. or a means of turning some reading into a variable voltage. Sensors can be divided into two groups. A thermistor. hence the reading is analogue. Notice that the digital sensors are really switches. relying on one of two methods to gain information. but their reports need to be kept as simple as possible to allow the processor to make decisions quickly. It cannot be half trodden on. light. One last point about sensors. In the type of scenario we are talking about it will probably be necessary to alter something in the . used to measure the room temperature for a central heating system converts the ambient temperature to a voltage so that a decision can be made by the processor. They either use some type of spring mechanism to physically change the position of something in the sensor. If the bumper around the robot is depressed is it necessary for a processor to make a decision? Probably not. There are as many different sensors as there are physical quantities that need measuring. For example. a bumper around a robot vehicle can be kept away from the body of the vehicle by springs which are overcome if the robot moves too close to something blocking its path. The computer will require the signals from such sensors to be passed through an analogue/digital converter because the computers with which we are dealing are digital computers and hence can only use digital signals as input. flow. The answer is that the action of turning the motor off required no decision and hence no processing. A light meter at a cricket match converts the available light to a voltage so that the processor can decide whether there is enough light for play. Note that any temperature may be reported. time.

it may be a matter of switching on some lights or telephoning the police station to report an intruder on the premises. Such movement involves the use of an actuator. however. Some of these are simple electric circuits that the computer can trip by itself. This may involve making the robot move in a different direction. .physical world. An actuator is the device that can accept a signal from the computer and turn it into a physical movement. making the robot change direction is rather more complex.

for instance the inside of a nuclear reactor. the second is the cost of running the system. It stops to have the wheels fitted but must then make a decision to go to the correct area for a 1700cc engine. . Now imagine the same system but at the start of the production line the computer controlling the flat bed is told the parameters for that particular car. These are natural environments for a robot to work in because there is no human equivalent.3. This flat bed is not a robot it is simply a machine following a preset course. There is no need for light or air in a factory. Why are robots used? The first thing to consider is cost. but maintenance must still be carried out. from there it must go to the area that has the correct body shell for a 3 door coupe. This machine is now making decisions and can be considered a robot. A robot is a mechanical device which is under the control of a processor. There is no need for a canteen or for restrooms or for a transport infrastructure to get the workers to work and home again.9 (c) The Use of Robots The first thing to understand is what constitutes a robot. They are extremely expensive. There is no need for a car park or for an accounts department to work out the pay for all the workers. Notice the need for a human workforce has not disappeared but the workforce is made up of different types of worker. The first is the capital cost of buying the equipment. Never say that robots are used because they are cheaper. A robot does not need the peripheral things that a human being needs. Imagine a car production line. It stops at the area where the wheels are fitted. They are not. Each car is built on a flat bed which is on wheels and runs along a track from one building process to the next. There is a need. What must be considered are two types of cost. however. then moves again to have the doors fitted and so on. There are some places that are particularly hazardous for human beings. generally more skilled than was previously the case. it is consistent. it is not as adaptable and therefore may produce worse results) however. it is here that savings will probably be made in relation to the cost of employing a person. then it moves along the track to have the engine put in. to employ technicians to service the machines and programmers to program every task that they need to undertake. It never gets tired. People can get tired and when they do get tired the work that they produce can be of a poorer quality than it otherwise would have been. This is to be a 3 door coupe with the 1700cc engine. The robot will not necessarily do a better job than the human (indeed.

One way of testing different designs is to build prototypes and take them out in different conditions to test how they work.3. The rate of growth of a sunflower is known from observations taken over many years. It is not possible to fly through the rings of Saturn. If a physical action can be portrayed as the result of a series of formulae and their results. the computer can play the part of the sunflower and show how a real one can be expected to react. In this way the effects of different growing conditions can be shown in seconds rather than waiting 6 months for the sunflower to grow. The effects of different combinations of the chemicals are not known. pretend to be carrying out the physical action. by doing the calculations. One can imagine that in the course of a day a programmer can come up with a suitable cocktail of additives to allow sunflowers to grow on the fringes of a desert and consequently create a cash crop for farmers. Program a computer to pretend and a virtual reality world can be created to make it seem possible. The computer can be set up to simulate the conditions and give evidence to either support or contradict the hypothesis. A computer system has the ability to perform a large number of calculations in a short space of time. Some things are impossible. This is very expensive. What will happen when a certain critical condition is exceeded in a nuclear reactor? I don’t want them to try it on the one down the road from where I live and I’m sure no one else does either. in such conditions. at a fraction of the cost. If the computer is programmed with all the relevant formulae dictating how it should grow in certain circumstances. The same simulation can be made to vary the conditions under which it operates. The effects of different chemicals on the growth of sunflowers are known from simple experiments using one chemical at a time. An engineer may design a new leaf spring for a suspension system. as well as time consuming. It can be used to provide information about past performance of the various criteria being measured or it can be set up to predict what will happen in the future. The hypothesis is that the spring will give more steering control when travelling on rough surfaces. People can have ideas which need testing to see if they are valid. If the graph of a particular measure is linear . A fairly simple change to the parameters of one of the formulae being used can simulate driving on a motorway or on a country lane. Program a computer to pretend to be a nuclear reactor and it is no longer necessary to do it for real. This is what is meant by a simulation. This is an example of the use of a computer simulation to speed up a process in order to give results in a more reasonable time scale. A financial package stores data concerning the economy.9 (d) Simulation. Simulation can be used to predict the results of actions. A computer can be programmed to take the characteristics of each possible system and report how well they will work. acting upon one another. A car company is planning a new suspension system for a range of cars. or model situations that would be otherwise too dangerous. then the computer can. where they had no cash crop before.

There should be an awareness that the values of these variables do not just appear by magic but must be collected and that sensible limits should be set within which the variable values must lie. for example the sun has been particularly violent recently and such sun storms have a pronounced effect on our weather. there should be an awareness that the results produced are subject to a degree of error. economic indicators do not exist in isolation. The values of the variables are arranged to be within sensible parameters. There should be an awareness that the results are going to be based on the use of these variables in specific formulae that relate the variables to one another. a student would be expected to understand that in a given situation there are a number of variables that control the outcome and the results that may be predicted. . so firms sell less. Generally. for example wind speed must be between 0 and 120mph. Description of a Simulation This is one of those requirements which is impossible to completely describe because there are an infinite number of possible scenarios that could be used. More importantly. However. from weather balloons and aircraft in order to make the model 3 dimensional. As an example consider the process of weather forecasting. there can always be unexpected problems. Finally. Data is collected about present weather conditions. A simple example would be that warm wind blowing off the sea becomes damp and there is more chance of rain. If the unemployment figures go up then there is less money in the economy. so people can buy less. so firms need to employ more people in order to put more goods in shops… When the relationships become intertwined like this the calculations of predictions become very complex and computers are needed. This involves a simulation and the use of predictions. However. but also the validity of the model that is used. The results are the best that can be expected for those data that are collected. Unless the bank of England brings down interest rates which will encourage people to borrow more and hence buy more. temperature must be between 0 and 110 degrees Fahrenheit. This was not a factor in the original simulation and consequently the reliability of the results is not as good as expected. More data is collected by satellite and it is all fed into a system together with relationships that the data is known to follow. so more people are laid off. not just the validity of the variable values and the relationships. if the graph is non linear the mathematics becomes more difficult. This is collected from weather stations across the globe. the size of which will result from.then extrapolation of what will happen in a year’s time is not difficult. in fact you certainly don’t need a computer to provide the prediction.

This simple example gives an illustration of how simple arithmetic can be significantly speeded up using parallel processing. There is a need for high speed calculation. the inter relationships and the consequent volume of calculations means that computer power becomes essential to giving a sensible result. they are useless. if the predictions are best on a simple linear relationship between two variables then there is little need for a computer because there is little to calculate and the calculations are simple. single processor. The 50 answers can be added in pairs in a second cycle to give 25 answers and so on. Indeed. This combination of the vast quantities of data.3. if tomorrow’s weather forecast takes two weeks to compute. . a need that is satisfied by the use of parallel processing. multiple. A computer with 50 processors can add the 50 pairs of values together in one cycle. computer will need 100 cycles to complete the calculation. If the predictions are based on a more complex relationship then the computer becomes useful but only in terms of a glorified calculator. ordinary computers are too slow. A total of 7 cycles are needed to add the set of 100 digits. If 100 digits need adding together a standard. and hence how parallel processing can be so important to simulations. with something like the weather forecast. if the predictions are based on complex. otherwise. if related to a time sensitive example like the weather.9 (e) The Need for Parallel Architecture As mentioned before. relationships the calculations become immense and must be done quickly. it doesn’t matter how accurate the results are. However.

the advantages of simulation to testing are that tests can be carried out safely. The previous sections have discussed problems associated with unpredicted events like the effect of the sun storms on the weather. this is impossible. there are some situations that are not predictable. perhaps by modelling the behaviour of the individual atoms inside the machine that chooses the balls. They are to do with events that are so complex that it is impossible to design a model for them. hence this is a fault of the model and not a suggestion that because of sun storms it is impossible to predict the weather. Mathematically. at a fraction of the normal cost and in a fraction of the time that the testing would otherwise have taken. In this context random events must be interpreted as unpredicted or unpredictable events. Those students with a mathematical background will know the difficulty of coming up with true randomness and particularly in relation to physical events. Briefly. If it were possible to predict accurately that human beings would all buy a particular song in preference to another. Limitations of Simulation The syllabus no longer expects the limitations to be taught as a separate topic. the behaviour of which does not normally follow easily interpreted relationships. If it were possible to predict the outcome of the lottery draw then there would be some very rich computer programmers. or to do with human beings. It is not suggested that the effects of these storms could not be included in our model. but the value of computer simulations cannot be appreciated without considering such limitations. Human behaviour is very difficult to predict. simply that it was not considered when the model was created. However.9 (f) Advantages of Simulation This has already been discussed in this section. then the record industry would not have to produce such a volume of material in order to have a single hit. However. certainly with present technology.3. . the outcome is not random and should be predictable.

(4) Explain why some applications require parallel architecture to carry out their processing and describe what is meant by parallel processing. Example Questions Describe the real time application of a computer used to control a burglar alarm system. 2. .3.9 1.

Section 3.Chapter 3. 3. From this exchange analogue signals must be used if the ordinary home telephone and modem are used by the receiver. LANs use digital signals to transfer data between nodes. therefore. This connection is analogue if a modem is used. Station Fig.10 (a) Organising LANs and WANs Most of this is covered in Chapter 1. This makes ring networks easy to install but limits bandwidth and. Connectivity and Security Issues 3.4 . The most common medium used in this type of network is unshielded twisted pair (UTP) as described in Section 3. Remember that questions may be asked on any part of the A Level Computing syllabus in the exam for module 3.7 (b) showed how analogue signals are used from your home PC (or network) to the local telephone exchange.10 (b). 3. From then on digital signals are used until the final local exchange.10 Common Network Environments. The rate of transmission of the data depends on the topology of the network and the transmission medium used to join nodes in the network. Fig.6 in the AS text.1 . the maximum speed of the network.10 (a)1 Repeater 6.10 (a)1 shows a ring network. In this Chapter you will learn how to connect LANs and WANs.

10 (b). However.10 (a)1. Number of Taps 10s 100s 1000s Table 3.10 (a)2 The limits on transfer rates given in the two tables are typical but they are being extended all the time as technology advances. Range km 2 2. are used in ring networks.10 (a)1 In bus networks the communication network is simply the transmission medium. you do need to remember the relative details. Number of Repeaters 72 260 250 240 Table 3. Medium UTP Baseband Coaxial Broadband coaxial Data Rate Mbps 1. Details of these media are given in Section 3.4 .10 (a)2. 6. Bus networks can use any medium and details are given in Table 3.5 30 Max. Medium UTP Shielded TP Baseband Coaxial Optical fibre Data Rate Mbps 4 or 16 4 or 16 16 100 Max.1 0.Media. other than UTP. Repeater spacing km 0.0 2.0 Max.2 .3 1. details of which are given in Table 3. 10 10 10 or 20 per channel Max. You are not expected to remember the exact transmission rates and other details.

3. giving different data rates as shown in Tables 3.3 . This is now being used in schools that have mobile classrooms. This has a central conductor enclosed in a plastic sheath which is surrounded by a copper sheath. four being common. 3. with other forms of media used to link other parts of a network together.10 (a).3. There are different types of UTP. 6.10 (b) Transmission Media Unshielded twisted pair (UTP) consists of two conductors. Fig.10 (b)2 The transfer rates for these media are given in the Tables in Section 3. Fig. The pair is contained inside another plastic sheath to keep them together. twisted together.10 (b)1 shows the arrangement of a single twisted pair.10 (b)1 The other main type of cable used in LANs is coaxial cable. This copper screen is surrounded by a plastic coating as shown in Fig.4 . Sometimes it is very difficult to lay cables so low-power radio may be used. This uses radio signals between networks and nodes. 3. enclosed in a plastic sheath. 3. Shielded twisted pair has a grounded screen around the conductors to shield the cable from extraneous electromagnetic radiation. Copper screen conductor Central conductor Plastic insulators Fig.10 (a)2.10 (a)1 and 3. sometimes known as demountables.10 (b)2. Often the outer sheath contains a number of twisted pairs.

10 (c)2. However.3.7 (d)). A router can alter packets of data so that two connected networks (LANs or WANs) need not be the same. A router is used to connect different types of network together. 3.4 . This means that routers must keep tables of addresses. each station has full speed access to the server. each connector has full network speed. Routers use network addresses and addresses of other routers to create a route between two networks. However. the increased local speed would be less useful because of sharing access to the main network. In a case like this. 3. 3. Stations S W I T C H To main network Server Fig.4 .10 (c) Network Components Switches use the same type of wiring as hubs (see Section 3. These tables are often copied between routers using routing information protocol (RIP).10 (c)1 If the number of stations is increased and they all want to access the main network. A typical layout is shown in Fig.10 (c)1. they would have to share the connection to the main network. it may be necessary to upgrade the link to the main network. Routers enable public networks to act as connections between private networks as shown in Fig. if any of these stations wish to access the main network. Here. LAN Router Public network Router LAN 6.

In order to route data round a network. when all nodes have sent data. 1. A bridge links two LANs which may.4 . 2. the destination address is the IP address. in the case of the Internet. 6. The two segments can work independently but. if data needs to go from one segment to another.5 . when the bridge receives data being sent from one node to another. 3. 3. It uses packets and the address information in each packet. Segment Bridge Segment Fig. Packet is sent to the appropriate network.10 (c)3 shows this situation. a router takes the following steps. the receiving node is on the same segment as the sending node. or may not. To route data efficiently. Fig. the bridge will know on which segment each node is. Eventually. 3. Router receives a network level packet.10 (c)3 The bridge has to learn where each node is situated. a bridge learns the layouts of the networks. Now. or not. Initially. Usually a router is slower than a bridge. The bridge stores a table containing the addresses of sending nodes and the segment from which the data was sent. The bridge will receive data that does not have to be passed from one segment to another. it can make a decision whether. any data the bridge receives is buffered and passed to both segments. Suppose a bridge is used to link two segments together that are not far apart. Network destination address is checked. Note that. be similar. say in the same building. the bridge will allow this.

2. pass data to other segment. However.This leads to the following algorithm.6 . A modem combines the data with a carrier to provide an analogue signal. 1. This means that ordinary telephone lines can be used to carry data from one computer to another. Sending node sends data onto its segment. Data arrives at the bridge and is buffered. 3. they improve manageability of the network. discard the data 4. the network is treated as a single LAN. bridges • • introduce delays. Modems are needed to convert analogue data to digital data and vice versa. they increase reliability because segments are separate. they enable connections between different types of network. 6. If destination is on same segment as sender then a.7 (b). This was explained in Section 3. Else a. they improve network security. Bridge checks destination address.4 . Bridges are very useful devices because • • • • • • they can increase the number of stations on a network. can become overloaded.

Domain names are held in an hierarchical structure.10 (d) Common Network Environments Probably the largest network in use is the Internet. wlv. to the destination computer. Sometimes the organisation allows the public to access certain parts of its intranet. the transfer of data between computers and the distribution of information. An intranet has to have very good security for confidential information. usually using telecommunications systems.10 (g)). Consider the domain name PC195-staff. As this is Wolverhampton University. The URL includes the transfer protocol to be used. file transfer.g.wlv. Those in charge of acadnet are responsible for PC195-staff.acadnet. Suitable software is required to make these systems work. The names in the various levels of the hierarchy are assigned by the bodies that have control over that area. Browsers allow a user to locate information using a universal resource locator (URL). This Internet access to an intranet is called an extranet. allowing it to advertise. i. for example http. it is responsible for all the parts prior to wlv. (In this case UKERNA). 3.10 (d)1 (on the next page) shows how data. Each name is for a location on the Internet. including electronic mail (see Section 3. Messages are passed from the source computer. In order for this system to work. The Internet provides • • • the World Wide Web. These providers then pass data between them and onto their respective clients.3. and other information such as an individual filename.bcs. Fig. It allows fast communications between people. http://www. The internet provides facilities to link computers world-wide. there are Internet Service Providers (ISP) who connect a subscriber to the backbone of the Internet. electronic mail. This authority would then assign the next part.uk The domain is uk and the ac would be assigned to a particular authority. Each location has a unique name. are passed from one computer to another.4 .org.e. An intranet is a network offering the same facilities as the Internet but solely within a particular company or organisation.uk/ will load the British Computer Society's home page.7 . e. 6.ac. This is the address for data on the Internet. through other computers. the domain name where the data is stored.

4 .Each computer linked to the Internet has a physical address. This numeric address uniquely identifies the physical computer linked to the Internet. The domain name server converts the domain name into its corresponding IP address.8 . a number called its IP (Internet protocol) address. 6.

org. databases. This one http://bbc. If a particular piece of data is required.9 . Fig.uk. This data may be in the form of text. In turn. However.co. the portion :// is a separator marking off the transmission protocol from the rest. However. 3.uk/ Here.10 (e)1 6.co. video. A typical URL is http://www. Smart Cards Contents Definitions Applications The Electronic Purse Home page Fig.10 (e)1 shows links to documents that are at the same site as the document containing the links.uk/weather/ loads a page from the directory weather at bbc. you can specify a folder to move to directly. This URL connects the user to the home page of the British Computer Society. this page will have links to other directories and pages. Links may be placed so that a user can quickly move around a document or to another document.4 . programs.10 (e) Hypertext Links The World Wide Web stores vast amounts of data on machines that are connected to the Internet. audio and so on. This means that there must be some protocol that allows all the computers to communicate and be able to pass the data from one computer to another.3. the URL starts http:// where http tells the browser which protocol to use. which may be at a completely different site. This means that the browser now knows where to look for the data. In order to view this data you must use a browser such as Internet Explorer or Netscape. 3. films. All the data is situated on computers all over the world.bcs. One of the protocols to do this is the hypertext transfer protocol (http) that is used by the browsers to receive and transmit data. such as a weather forecast. the browser will need to know how to retrieve and display this data. These computers have unique addresses and the data is held in folders on these computers. not all computers use the same hardware and software.

Pensioners insert their cards into a machine which is brought to Kangwane once a month. The cards can transfer 'cash' from one card to another.). Applications Electronic Purse Access Control and Security Travelling The Future Smart Card Contents Home Page Electronic Purse This acts like cash. South Africa is using smart cards to issue pensions to those entitled to them in Kangwane .10 (e)2 6. and checks it with the data on the card. Mondex is one of the largest suppliers of these smart cards and trials are taking place at Aston. (Try it. when you leave the pointer on a link. the URL will be displayed. the parent can transfer the child's pocket money from one card to the other. can provide secure trading on the Internet as well as facilities similar to those of Mondex.000 pensions. as it is called. Fig 3.a former black homeland. Start of Applications Access Control and Security The cards can be used to control access to buildings. They can hold personal details of the user including biometric data. Thus. rooms and facilities such as libraries. If you now click the mouse button you will be connected to the appropriate site and the data will be downloaded. When you place your pointer on a link. Dakator has now been bought out by FNB who have extended their services to Namibia and the Western Cape. each have a card. Exeter and York Universities as well as at Swindon. The card can be charged up at modified automatic teller machines (ATMs). The scheme is provided by Cash Paymaster Services (CPS). a company set up by First National Bank (FNB) and Dakator. they then pass their finger over a tiny scanner which reads the fingerprint. Fig. Visa Cash. Click here for more details. They produce both disposable and reloadable cards.10 (e)2 shows part of the page that is displayed when Applications is clicked on. such as a parent and a child. This method of payment has now spread to other provinces and is used to dispense about 400. Another large provider of smart cards is Visa. The difference being that 'cash' is being transferred from the card to the retailer. The card is loaded with electronic cash and it can then be used to pay for goods and services in a similar way to using a charge card. In this document.The links are usually displayed in a different colour to the rest of the text and are underlined.4 . if two people.10 . 3. the pointer becomes a pointing finger. modified BT payphones and at new points installed by the provider.

tabs and extra spaces are ignored. HTML uses tags to indicate how to display the data. Thus it is a good idea to include some keywords in the title. <I>This text is in italics. If you want these.10 (f) Hypertext Mark-up Language (HTML) Using http. you must use tags to do it. 3. This is because some search programs enter it in a database so that the search engine can find it if it contains what the searcher wants. One indicates the start point and the other the end point. the browser still needs to know how to display the data. This is because the browser has to fit the output to the display screen attached to the receiver. The heading tags <H1>…</H1> to <H6>…</H6> are used to create headings. These may be set up in many different ways. Some tags have two parts. Fig. For example <B>This is bold text. you may find it useful to remember a few examples in order to explain an answer to a question.</I> would produce This text is in italics. The layout is decided by the browser. For example <B>. In this piece of HTML the blank <HR> tags are used to insert blank lines because the Web browser ignores the carriage return and new line characters. However.11 . so blank lines.</B> would produce This is bold text.10 (f)1 shows a simple example of HTML.3. although some browsers will display a title if it is included in the HEAD. Tags are enclosed in angle brackets < and >. What is in the HEAD is not normally displayed. 6. An HTML document is in two parts called the HEAD and the BODY.4 . Similarly. You are not expected to be able to produce detailed HTML in the examination. your browser can transfer data between computers. However. This is done by using the hypertext markup language (HTML). Level 2 HTML requires users to include a title of up to 64 characters.

Fig. In Fig.10 (e)2 you will see many links.<HTML> <TITLE> An Example of HTML </TITLE> <HEAD/> <BODY> <HR> <H1>An Example of HTML </H1> <HR> This piece of text has been produced using HTML.4 . An Example of HTML This piece of text has been produced using HTML. some browsers do not recognise all tags. most of which link you to different sites around the world. the home page for Mondex who specialise in applications of smart cards. it should ignore it. it may not be when displayed by the browser. 3. Also. </BODY> Fig. but will be something like that shown in Fig.com. the Web browser decides the layout unless tags are used. Remember.10 (f)2 A line space and a thick line precede headings. For example. If a browser encounters an unknown tag. it may not be when displayed by the browser. the Web browser decides the layout unless tags are used. However. 3.10 (f)1 The result of a browser running this HTML will vary.12 . A line space and a thick line also follow them.10 (f)2. there is no guarantee of this. 3. Although this piece of text is on a new line here. 6. Exactly how the information is displayed will depend on the browser. Mondex links you to mondex. Remember. Although this piece of text is on a new line here. The text may be bold or italic. may not look very good on a different browser. The result is that a page that looks outstanding when you design it. 3. The text may be <B>bold</B> or <I>italic</I>.

You must specify where the image is stored known as the source (SRC). this will not create the link.mondex.To use links as shown in the previous Section. we can write <A HREF = "subdirectoryname/documentname. This points to where the document to be displayed is kept. we need to use <A>Smart Cards</A> in the HTML document. In this case we need only write <A HREF = "documentname. it only creates the hypertext.4 . Note this only shows the HTML necessary to create the link. However.com/"> Smart Cards</A> if you are interested.html> … </A> Links can also be created to points in the same document by using the NAME attribute. You will find more information on Smart Cards at <A HREF = "http://www. Images can be placed on Web pages to • • • improve the look of the page. Fig. Inserting an image for interest is done by means of the <IMG> tag which has no end tag.10 (f)3.gif"> 6.13 . you need to use the anchor tag <A>.10 (f)3 A shortened version can be used if the link is to a document in the same directory as the one being viewed. For example <IMG SRC = "mypicture. To create the link Smart Cards say. 3. 3.html"> … </A> If the document is in a subdirectory of the directory containing the page being viewed. A typical example is shown in Fig. This hypertext must now be linked to the site. using a hypertext reference (HREF). You do this by giving the anchor attributes. add to text provide a hyperlink.

4 . then use. say.uk/pictures/"> or you can write it out in full as <IMG SRC = " http://www.gif"> If you want the image to be a hypertext link.mysite.org.uk/pictures/mypicture.where the BASE has been set by using.mysite. <A HREF="hrefURL"> <IMG SRC="imageURL"> </A> 6. <BASE HREF = "http://www. for example.14 .org.

Users of email can also set message priorities and request confirmation of receipt. This book was created in this way. It is easy for them to pass their work to one another as an attachment so that others can make comments and revisions before retuning them. stored and replied to.10 (g) Electronic Mail (email) Electronic mail is a fast and cheap method of corresponding with others. These messages can also be forwarded. in many formats. The facilities offered by email are numerous as are their advantages. It is easy to reply to an email as you only have to click a Reply button and the original sender's address automatically becomes the address to which the reply is to be sent. The ability to attach all kinds of documents can prove very useful. 6. This is easy as there is a forward facility with all email services. In this case the spoken message is digitised and stored electronically on a disk. the digitised form is turned back into sound and the receiver can hear the message. Students can word process their work and send it as an attachment.3. if I wish to send a message to the whole of one of my classes I can do this. Suppose several people are working on different chapters of a book. students attach programs they have been asked to write and I can run them to see if they work! Often emails are sent to people who need to pass the message on to someone else. I can then mark it and return my comments. Electronic mail systems allow the user to compose mail and to attach documents. It is also possible to use voice mail in a similar way to email. enter the email address and press the Send button.4 . All that is necessary is for me to create a group by inserting in it the email addresses of all the students in the class. All the user has to do when an email is to be passed on to someone else is to click a button.15 . you do not have to consider that at 08:00 in London it is only 03:00 in New York. Another useful facility that can be used is the facility to send the same email (and attachments) to a group of people. When the recipient checks for mail. The author of this Chapter uses email to collect homework. Even better. email can be delivered when nobody is available to receive it. Also. I can then type the message once and send it to the whole group by means of a single click on Send. to the message. It does not matter what time you send it. For example.

However. There are two methods of doing this. An organisation may well wish that potential customers have access to their product database. This is not as secure as the proxy method because some data do pass through the firewall. This method tends to degrade network performance but offers better security than stateful inspection. However.16 . Another solution is to install firewalls. Stateful inspection tracks each packet and identifies it. A first step is to encrypt the confidential data and this is addressed in the next Section.3. The message does not pass through the firewall but is passed to the proxy. Another way of ensuring privacy of data is to use authorisation and authentication techniques. The firewall uses names.4 . 6. they are passed to the other side.10 (h) Confidentiality of Data Once an organisation opens some of its network facilities up. These sit between WANs and LANs. and so on that are in the incoming message to authenticate the attempt to connect to the LAN. To do this. there is a problem of confidentiality of data. These are explained in the next Section. Proxies stop the packets of data at the firewall and inspect them before they pass to the other side. the method uses less network resources. Internet Protocol addresses. the method uses tables to identify all packets that should not pass through the firewall. Once the packets have been checked and found to be satisfactory. they will not want them to have access to employee files. These are proxies and stateful inspection. applications.

Bob can use Alice's public key to encrypt messages.10 (i) Encryption. The predominant public-key algorithm is RSA.4 . which help combat repudiation. Authorisation and Authentication Encryption is applying a mathematical function. suppose Alice and Bob wish to send secure mail to each other: • First. Adi Shamir. so that only she can decrypt them. Authentication is used so that both parties to the message can be certain that the other party is who they say they are. both Bob and Alice need to create their public/private key pairs. Ron Rivest. and Leonard Adleman. to a message so that it is scrambled in some way. a digital signature is code that is attached to a message.17 . anything signed using that key can only have been signed by the owner. i. There are many techniques for this.3. Bob can then use his private key to digitally sign messages. In order to understand how public key cryptography works. and Alice can check his signature using his public key. • • • A primary advantage of public-key cryptography is the application of digital signatures. using a key value. which was developed in 1977 by. This can be done by using digital signatures and digital certificates. Basically. This is usually done with the help of a Certification Authority (CA). All these people need the key to unlocking the message. It also means that there is a problem of many people needing to decrypt a message. Since the owner keeps their private key secret. Alice and Bob then exchange their public keys. and named after. Digital signatures require encryption. The problem is to make it virtually impossible for someone to unscramble the message. This is done by exchanging certificates.e. One method of overcoming this is to use Public Private Key technology. The RSA algorithm is included as part of Web browsers from Netscape and Microsoft and also forms the basis for many other products. The problem is to make it very difficult for anyone to find the inverse of the original function. 6. whatever function is applied to the original message must be reversible. denial of involvement in a transaction. Clearly. This makes it highly likely that an unauthorised person will get hold of this key. This involves the sender having a public key to encrypt the message and only the receiver having the private key to decrypt the message.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.