Thursday, September 29, 2016

Data Types

Data Types

String
Strings can be a made up of a range of characters, this can include spaces it can also include other characters such as exclamation marks and question marks. Numbers can also be used in a string but it will only be seen as a character and would not be able to do mathematical sums if you added the strings it would just place the numbers side by side. Stings are usually placed in between single quotation marks.

Char
A character is a single letter this takes less space to store than a string, this would be good if it was a low memory based program that being said it is only able to store one character as oppose to a full word or a string.

Integer
An integer is commonly used feature within many programming languages there is a limit to using integers in the fact that they have to be a whole number and this means that it is unable to contain a decimal this would mean it is very restrictive if trying to add or subtract decimal numbers.

Float
A float is a number that is able to contain a decimal point this would be a lot more beneficial for storing decimals this would be very preferable when dealing numbers that leave a decimal number.

Boolean
The Boolean data type is a yes and a no function that would output true or false dependent on whether the criteria had been met.

Currency
Currency is also a data type; this allows the user to do financial calculations a lot more precisely it will also allow the use of currency signs such as the dollar sign and the pound sign. This will use more memory than a short integer but around about the same as a long integer.

Date
The date data type is used to store dates, this can contain just a date value, a time value and both of them together for example the date can be read and written in many different formats, when a user enters this information that have to be informed of which format that they have to use. For example this could be just day, month and year (DD/MM/YYYY) or it could also be displayed as:

0:00:00 (midnight) on January 9, 9999.

This would be more informative but would also need more space to be able to store.
Data type
Storage size
Range
Byte
1 byte
0 to 255
Boolean
2 bytes
True or False
Integer
2 bytes
-32,768 to 32,767
Long
(long integer)
4 bytes
-2,147,483,648 to 2,147,483,647
Single
(single-precision floating-point)
4 bytes
-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
Double
(double-precision floating-point)
8 bytes
-1.79769313486231E308 to
-4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
Currency
(scaled integer)
8 bytes
-922,337,203,685,477.5808 to 922,337,203,685,477.5807
Decimal
14 bytes
+/-79,228,162,514,264,337,593,543,950,335 with no decimal point;
+/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is
+/-0.0000000000000000000000000001
Date
8 bytes
January 1, 100 to December 31, 9999
String
(variable-length)
10 bytes + string length
0 to approximately 2 billion
String
(fixed-length)
Length of string
1 to approximately 65,400

Useful to have different data types
Data types all use different amounts of storage space to store the variable they are to contain, the computer needs to know how much space needs to be reserved and what output to expect from, this helps with the speed of the computer and also ensure that there isn’t too much data for the amount of memory that is available.
In addition to this without knowing the data type the compiler wouldn’t be able to determine what or how to deal with the data as it wouldn’t be in the correct format and wouldn’t be able to process it.
It is also important to have different data types as it demonstrates different information and they can all be manipulated in specific ways for example adding two integers together would output the two numbers being added together, whereas adding two strings together would just add the two sentences one after the other.
A currency data type would have a currency sign whereas a normal float or real wouldn’t be able to contain these types of symbols due it being in the wrong format and the computer wouldn’t be able to process it as it wasn’t expecting it.

Table Used From: https://msdn.microsoft.com/en-gb/library/47zceaw7.aspx


Tuesday, September 27, 2016

Factors that influence the choice of programming language

Factors that influence the choice of programming language

There are many factors that influence the choice of language which should be used, these are:
·         Time Constraints
·         Organisational Policies
·         Suitability
·         Available of trained staff
·         Reliability
·         Environment
·         Development and maintenance 
·         Expandability

Time Constraints
The amount of time a programmer has to finish a job will tend to dictate on what programming language that would have to be use, some languages take longer to create a program in this would mean if there was a short time period and shorter programming language should be used.

Organisational Policies
An organisation tends to have a policy in place this could mean that they have a contract with a specific company; this would mean that the organisation would have to use computers and operating systems that the organisation are allowed to use. This could determine what operating systems you would be able to use, this would also dictate what programming language can be used as some may not be compatible. The organisation may also be restricted to what programming languages they are able to use.
If there are no restrictions on which language that the organisation has to use then the programmer maybe able to pick a language that better suits the others factors, for example operating system and type of program. The programmer will be able to determine which language should be used for example Visual Basic would be able to be used to create a program on a Windows operating system but would cause a Linux operating system to crash and maybe not even run.
Suitability
The programmer would have to determine the program is suitable for the organisation, the programmer will need to see what is compatible with the system the organisation is already using to what would be best to fit the current system.

Availability of Trained Staff
The employees of the company will need to be trained on the system that the programmer has created, in addition to this, the IT technicians that work within the company will also need to be able to support and fix any errors and bugs that may occur. It will not be very useful if the programmer designs and produces a program that the technicians are not able to fix.


Reliability
The organisation will want a program that is reliable and doesn’t crash, for example if the organisation takes orders, you will not want the program crashing every ten minutes, this would mean that orders may not be able to be saved, could have customers on the phone and would have to leave then on the phone whilst the system is fixed. Reliability is a key factor when creating a program as the organisation would be paying money for a program they can use.
Depending on the programmers time scale would determine how reliable the program will be, for example the larger time limit they have would ensure that the program would be less bug ridden and would run a lot smoothly as oppose to if the program is rushed it may not function as it should.

Environment
If a programmer was creating a program for an organisation with extra peripherals for example a barcode scanner, the programmer would have to see whether the current peripherals are able to be used on the new system or whether the hardware will need to be updated, this will need to be sorted before the programmer can start creating the program so that they know the environment that they have to match it to.

Development and maintenance
Most of the programming languages used and free to use and the programs to code the programs, a lot of the coding programs can be downloaded of the internet and nobody owns the rights to the language therefore it is free to use by all programmers. The costs that may occur will be if the hardware does need to be upgraded, also the IT technicians will need to have knowledge to be able to fix any bugs that may occur, otherwise this would also cost more money having to hire external help to fix the problems.
The quicker the business will want the program created may affect how much maintenance they may need in the long run the higher development time, any upgrades to the hardwarte after the program has been finished will then need to be altered in the future this may also cost the business more money.

Expandability
If a business is happy with the finishing product and the program works, they may want the programmer to load it up to all of the other computers this will allow the programmer to expand the program.

In addition to this the business may want the programmer to expand the program to a larger scale for example increase functionality and improve the program this will programmer to make a smaller program for the business and then upgrade it at a later date.

Describe the application and limits of procedural, object orientated and event drive programming


Describe the application and limits of procedural, object orientated and event drive programming

High Level programming languages
High level languages are able to be understood by the user with ease these are also powerful and allows the user to create a range of different programs. They are highly related to the English language such as they are able to be read for example the work “print” will tell the computer to print the specific value to the screen.

Imperative Programs
This is used in most programming languages, old ones and newer ones. Each line of code allows the program to handle the inputs, processing and outputs of the whole program.

Procedural Programs
Procedural programming languages have significant starting and ending points this type of programming was very popular before the use of graphical user interface operating systems, they tend to have a starting point then follow a specific sequence. Newer programming languages can respond to a specific event, this means the program can have many start points within the code.

Event Drive Programs
These types of programs respond to specific events from the user this could range from a mouse click to an input of a number or even scroll down the page, this will they trigger the piece of code to run. This is used in modern programming a lot due to the fact of graphical user interfaces this then means the program responds the events in which the user triggers.

Object Orientated Programs
This type of programming looks at programs as a group of objects; this could be for example database records and not a chain of tasks.  Each object is viewed as a separate independent object and will have its own responsibility; it could be in charge of receiving and sending messages and processing information.
These tend to be for the more experienced programmers and take a little longer and more understanding to learn.

The Procedural Paradigm
This type of programming uses step of procedures, this allows a program to perform a specific set of tasks, This is a fast process due to how simple it is, it uses simple logic and tends to be here beginners should be starting.
Complex software should not really be written using this type of programming this means, it would require many lines of code to be used thus making a lot more work for the programmer and would be very time consuming, it also may be very confusing sue to the fact there is too much code to read.

This paradigm can be used in the following languages:
·         C
·         C++
·         Fortran
·         Pascal
·         Basic


The Object Orientated Programming
This type of programming focuses on individual objects, rather than using logical procedures. This means that all of the objects can respond to the same instructions differently. This also allows the programming to narrow down and change specific objects rather than having to change the whole piece of code.

This type of programming can be very difficult to learn and has a steep learning curve; it requires a lot of planning to ensure the programming runs smoother. A programmer will also have to consider the relationships between the two objects and this can be difficult to get familiar with. OO programs, tend to have larger file size this could cause some issues when having to compile the program.
The languages that are used in this type are:

·         C++
·         Smalltalk
·         Java
·         C#
·         VB

The Event Driven Paradigm  
This type of programming is designed to react to user responses for example it will be able to detect specific button clicks or key presses, this allows for more interactive programs to be created, this is increasingly beneficial when creating graphical user interfaces. This allows easier communication between both hardware and software.
This tends to only be used when GUI’s are involved sue to the programming style being extremely interactive, this means that the programming is not very flexible.
Lists of languages which event driven programming can be used are:

·         FOCUS
·         Lisp
·         Perl
·         Ruby
·         SAS
·         COBOL

Advantages and disadvantages of different programming languages

Visual Basic
Positives
Negatives
Easy to learn
Only work in Windows operating systems
Integrated IDE as well as a language
A lot of memory used due to using a GUI
Obtained for free
Slower than other languages
A lot of help through the use of online tools
Unable to program complex programs
Has a toolbox, assists programmer, when creating a program
Not able to be used for web  development due to be used only for Windows

C++
Positives
Negatives
Very similar to other programming languages
Very difficult to learn as it is very complex
Can be used for multiple paradigms OOP etc.
Has difficulties when trying to create web applications
Obtained for free
Mostly used for platform specific programs
Fast language compared to others  languages
Unable to program complex programs
A very popular programming language a lot of online help from other people
Certain compilers, can cost money to compile the program

DarkBASIC
Positives
Negatives
Very easy to learn
DarkBASIC costs money to use without advertisements
Short amount of code needed to be able to create programs in comparison with other languages
Not multipurpose due to it being created solely for games not very flexible.
Obtained for free
Can be fairly slow to both program and run
Specifically for creating 2D and 3D games


JavaScript
Positives
Negatives
The language itself is very secure and con protect the user
Slow to develop and run
It is cross platform this means it can be used and ran on many different operating systems
Slow compiler
Obtained for free
Difficult to frame based applications
Very easy to learn compare to more complex programming languages
Needs C++within the program to allow it to create an .exe file extension
Multithreaded, this means that multi-tasking and performing different tasks at the same time
Can be difficult to grasp if not much experience

HTML
Positives
Negatives
Used plain text so is very easy to learn and understand
Limited security features
Easy to edit and read other developers programs
Can be classed as a static language
Obtained for free
Pages most be edited separately
Supported by most if not all browsers
Structuring can be very difficult to learn when using this language
Can use search engine optimizations within the code




Features of a programming language

Features of a programming language
There are many tasks that can be achieved with programming language; most have built in core features that allow programmers to create bigger and better programs. Some of the features that are included in programming languages are:
·         Sequence
·         Selection
·         Iteration
·         Variables
Sequence
A sequence tends to be standard program statements that are executed one after then other this will run in the sequence and will not differentiate the order. As python reads the program in will read it in the order in which it is written this will ensure the program loads step by step.
Selection
Selection statements are in essence what they say to do; they give the user a choice or a selection of answers so they can produce their own outcome. This best example of this would be a very basic calculator; in this instance you ask the user for two numbers, you then ask the user to make a selection from the pre-programmed selections, the code below shows this in a bit more detail.

‘ menu = "Welcome to the Python Calculator\n\ #Store menu text in a string
What calculation would you like to perform?\n\
1. Add\n\
2. Subtract \n\
3. Multiply \n\
4. Divide \n\
5. Square first number \n\
6. Square second number \n\
7. Calculate the power\n"

num1 = int(input("Enter the first number: ")) #important to cast as int
num2 = int(input("Enter the second number: "))
print(menu)
choice = int(input("Enter your choice: ")) #get user choice
if choice == 1:
print(num1 + num2)
elif choice == 2:
print(num1 - num2)
elif choice == 3:
print(num1 * num2)
elif choice == 4:
print(num1 / num2)
elif choice == 5:
print(num1**2)
elif choice == 6:
print(num2**2)
elif choice == 7:
print(num1**num2) ’
Iteration
Another word for iteration could be a loop; there are two types of loops that can be used to repeat certain sections of a programmer’s code. A fixed look would be continuously executed and would only be able to stop if there was an option to use “break;” within the code otherwise the program could continue to run until manually terminated. The other type of loop that can be used are conditional loops these loops will run until a condition has been met this could be either before or maybe ever after the loop has completed at least once.
Pre-Check Loops
A pre-check loop would have the condition placed at the beginning of the loop this would check that the condition is true before the code or loop is executed, if the condition equals false straight from the beginning this would cause the loop not to execute event once. In addition to this if the execution of the loop causes the condition to change it will again have broken the loop and will no longer run. An example of this is shown below:
for loopCounter in range(2,41,2):
    print(loopCounter)
The above snippet of code tells the computer to print all numbers in starting from 2 and ending in 41, the third digit tells the program to only print every second number hence the program counts up in twos like the two times table. The code above will result in the following output:
Post-Check Loops
These types of conditional loops check the condition at the end of the loop this means that the loop will always run at least once to see what the condition is that needs to be met, this would then determine whether or not the program should loop around again, with this being automatically looped there are risks that the program may go into an infinite loop.
height = int(input("Please enter your height (In Inches): "))

while height > 0:
    if height <= 48:
        print("You are the correct height for this ride")
    else:
        print("You are too big for this ride, Sorry!")
               
    height = int(input("Please enter your height: "))
The code above will ask the user their height in inches this will then allow the user to enter their height, and will tell them whether they are able to or are too big to ride the ride. The following screenshot is the result of the code:
Variable
A variable within a program can be classes as many things, for example both inputs and outputs will be stored as variables even if the variable gets changed at a later date. It is stored within the program for a certain period of time depending on which type of variable it is.
The data that can be stored within the variables are made up of numbers and words, when a programmer is coding a program they will have to declare which variable they should use  and the developer should also name the variable in relation to its value.
For example when dealing with numbers an “int” should be used this stands for integer and is a whole number. A string should be used declare words and writing, numbers can be put in this but just as a character and not to be able to do mathematical equations.
Local and Global Variables
Programs are usually made up from a collection of functions. A variable can be declared within a function and it can only be called upon in that function. On the other hand there are global variables these need to be declared at the top of the program this way they are able to be recalled all throughout the program and will save a developer from having to repeat them over and over again.
Input and Output
The input allows the user to interact with the program and input information to provide a different result. An output is the result after the user is has input the information and executed the program both of these will be shown in the screenshot below.
Logical Operators
A logical operator is used when an output or action is dependent on one to several conditions being met. The three operands that are to be used are the following:
·         OR
·         AND
·         NOT
This will only be able to be used to tell the user if the statement is true or false , this will then determine which path the program would then have to go down.
OR = ||
The program would choose a response if either on OR the other condition meets the correct criteria, if neither of them meet the criteria then the program would return false and thus sending the program down the false path. If one of the conditions are true then it would send the program down the true path.
AND &&
The program would again choose a response  but only if both of the conditions are met, for example if both of the conditions are met then the outcome would be true and it would send it on that pathway whereas even if one condition is true but the other is not then the overall outcome would be false and will send it down the false pathway.
NOT !=
This would execute a command or return a value when the condition is false.
Selection Operators
Selection operators tend to be used when if statements are used, when something is dependent on a statement. Depending on the answer will depend on how the program continues, for example:
The selection operator is “<” in this instance is means that if the answer is less than two it will select the first option whereas if the answer is above two it would then select the “else” option. The selection operators are show below:



Operator
Symbol
Purpose
Greater Than

> 
This would check to sell if the value on the left was bigger than the value on the right.
Less Than
< 
This checks to see that the value on the left is less than the value on the right.
Equal To
==
Checks to see if the two values are equal, if they are the condition would be true.
Greater Than Or Equal To
>=
Checks to see if the value on the left is equal to or greater than the value on the right.
Less Than Or Equal To
<=
Checks to see if the value on the left is equal to or less than the value on the right.
Not equal to
!=
Checks if the value is equal of not if they aren’t then the condition is true.

List / Array
A list or array is a variable with multiple of the same elements stored within is this allows a developer to add delete and recall the list throughout the program whenever they like, it also makes the code more light weight and will ensure the developer doesn’t have to declare every variable every time then want to recall them all instead they will only have to recall the one list variable.
Reading and Writing to and from a text file
Reading and writing allows a user to write and receive information to a text file, a program will need to have the ability to write to a file this allows the program to save and store variables for a later recall.  This will allow for tasks such as creating a log in to recall information from a username and would be able to compare the password to ensure the user is able to log on.
The code below will open a specified text file, anything that has been specified will then be written to the text file it will then be saved.