Unit 6 Software & Development

Assignment 2Max Wade

P3 – explain sequence, selection and iteration as used in computer programming

P4 – outline the benefits of having a variety of data types available to the programmer

Task

In your role of Development Consultant at SNC PLC, your line manager Jane Fletcher has asked you to expand the information contained in the wiki you made for her previously to include some additional data.

1.  Taking the data types outlined on page 3 of this document, for each give an explanation of what each type may be used for, and what data can be validly contained within a variable for each type. (Background for P4)

Text; integer; floating point; byte; date; Boolean; other eg char, smallint

When making a program there are many different data types that are used for different types of data. Some of the main data types are String, Integer, Floating point, byte, date, Boolean and others are char and smallint. For each of these examples I will be telling you what they are used for and which types of data can be validly contained within them.

The data type String will normally be a sequence of characters that either literal constant or as some kind of variable. So sequences of unsigned 16-bit code points from the value 0 to 65525 can be held in this data type.

Integer, this data type will be able to hold 32-bit signed integers which range from the values -2,147,483,648 to 2, 147,483,647. It is a data type that provides an optimal performance on a 32-bit processor. The default value of integer is a 0.

Floating Point has data types, single and double. The single type will need 4 bytes of memory; it is able to store negative and positive values between. The negative values are will be between -3.402823 x 1038 and -1.401298 x 10-45 and the positive values are between 1.401298 x 10-45 and 3.402823 x 1038.

The double data type needs a bigger memory of 8 bytes but can store much more values in the positive and negative values.

The data type byte is used for containing binary data; binary data is typically data that could contain null bytes. This data type variables are stored in unsigned 8-bit (1-byte) numbers that can be 0 to 255.

Date data types are stored as 64 but integers that represent dates ranging from January 1 of the year to December 31 of the year. Date values must be within the format M/D/YYYY.

The Boolean data type is stored as 16-bit numbers, but they must be true or false. Boolean values can be compared to test for equality or inequality. You can also use Boolean column to store what a Boolean expressions returns.

The other data types are char and Smallint. Char data type is stored as 2-bytes numbers in value from 0 to 6555. Each of the numbers represents a single Unicode character. Smallint data type is a data type that is stores small whole numbers that range from -32,767 to 32,767.

2.  With the information from point 1 above, explain the benefits to the programmer of having different data types available. (P4)

By a programming having different data types available for programmers to use they will have many benefits when having to add data it their program e.g. it will allow for less waste when storing data, without having to re-implement standard data types you can write your application code and will enable code parameters to be more expressive.

Another one of the main reasons to why there are different data types is that each bit of data is aligned with the data type which has specifically the amount of memory it can be stored with, so it is more efficient with memory. Also data that have their own data is easier to secure as it is easier to tell when a pointer to block memory with data had be compromised, this is because by have specific data types for pieces data with exact limits for what data can be stored.

Data types will make the data less likely to make mistakes as the data types of behaviour are closely matched. Another advantage to having different data types is that because more errors are caught before it is put into binary code where they are harder to track down. They cause more errors before they are converted because specific types will be in small number of places in the programmer’s code.

3.  Explain the different control structures that are available within a programming environment (sequence, selection and iteration). You may give examples if it helps to make your explanation clearer. (P3)

One of the most important parts of programming is being about to control the execution of a program, so that lines of code are being executed at the right moments, or that some bits of code are being repeated. When you are within a programming environment it is important that you know what the different control structures are and what they do. I will explain the three main categories, Sequence, Selection and iteration, to help with pointing out the differences between.

So the first control structure that I will explain is Sequences. Sequences in terms of within a programming environment are the order of execution. It will normally be in reference to the order of which the code will be executed. The code will be done line by line. Most lines of code use this it is very boring, it is just following a given sequence, doing one instruction after the other.

Selection is the method of control to the execution of a sequence. Large blocks can be created by using statements testing a condition, or to switch statements evaluating a variable. This is done to control and change execution of programs depending on the environment and changing variables. So it basically where you select between two or more flows.

Iteration normally is used for referring to collections and arrays of data. It means to visit each item in a particular collection, each item can only be visited once, and they can either be order or in an irregular order. For example this being in an order just simply counting up from 1-5, you are iterating the first 5 numbers.

It can also be known for repetition, for some codes they can be executed many times or not at all. They can be executed to a fixed number of times or indefinitely for it to reach a condition.