week7-asg
TRANSCRIPT
-
7/31/2019 Week7-Asg
1/4
Question 1
What it means by programming language is machine independent is that the structure ofthe programming language would not rely upon the internal structure of a specified
compute. Regardless of whatever model or manufacturer of the machine, the programwritten in the programming language will be able to be executed (Rajaraman, V., 1998).
FORTRAN, COBOL and Pascal are some of the examples of machine independentprogramming languages. However a point to note is that although the given examples of
programming languages which are also called third generation programming languages aremachine independent; they do require a compiler to actually run the program effectively
(Webopedia, n.d.).
Question 2
"Paradigm" (a Greek word meaning example) is commonly used to refer to a category ofentities that share a common characteristic. A programming paradigm is an approach toprogramming a computer based on a coherent set of principles. Each paradigm supports a
set of concepts that makes it the best for a certain kind of problem (Roy, P.V. 2009).
Imperative there are a sequence of command. The variables are specified and changesare made via the control structures (flow of control). Example of imperative languages
Pascal, COBOL, Ada, FORTRAN; whereby data item are declared by indicating the variableusage by using meaningful name and the data type is also specified.
Functional - about having a program which specifies what has to be computed, rather than
how the computation is to be performed. Example of functional programming languages:Miranda, Scheme, LISP and Haskell - all which consist of functions. Basically programs inthis paradigm consist of nested functions.
Logic A program which doesnt tell you how to solve a program but only specifies it.Example of logic programming languages expert systems and PROLOG; which consists of
facts and other information about the issue (rules).
Object-Oriented provides an avenue to programmers to specify objects which are madeup methods and data which can be used on the object. Example of languages Java, Delphi
and C ++. In these languages the code has object which has control structures and variablebut it is further broken into objects which has their own methods.
Question 3
Machine Language: The machine language is the internal language of the computer and its
the only language which is understood by computers. Every computer has its own uniquemachine language. This language is very difficult to be handled by humans. This language is
made up of binary strings of 0s and 1s which is understood by the machine to follow anyinstructions. In fact, its suffice to say that machines are able to recognize only these 0s and
1s. So, it is a language of the lowest degree made for machines only.
For e.g:001010001110 could represent a 12-bit machine language instruction. This
instruction is divided into two parts an operation code (or op code) and an operand, e.g.:Op code 001, Operand 010001110. The op code specifies the operation (add, multiply,move.....) and the operand is the address of the data item that is to be operated on.
Besides remembering the dozens of code numbers for the operations, the programmer also
-
7/31/2019 Week7-Asg
2/4
has to keep track of the addresses of all the data items. Thus programming in machine
language is highly complicated and subject to error.
Assembly Language: Assembly language is a second generation programming language
which is used in the computer systems. In this language, symbolic instructions rather thanmachine language instructions are used by the programmers. Descriptive names for data
items and memory location are also used. Strict rules are required to be followed when anassembly language program is written. After being written it is then translated via an
assembler into machine code. It is not portable due to the fact it is very much machinedependent language. The various symbolic notations used in the assembly language are
called mnemonics (memory-aiding, alphabetic codes human readable abbreviation). The
assembler representation for hex 9588 is simply the abbreviation "SLEEP". In contrast to9588, SLEEP is much easier to remember (Schimdt, G., 2011).
Because assembler is closer to the hardware than any other language, it is often calledmachine language. This is not exact because the CPU only understands 16 bit instructionwords in binary form. The string "ADD R0,R1" cannot be executed. And assembler is much
simpler than machine language.
Question 4
a) If order on how to evaluate the expression is not stated, then the expression isevaluated based on the operator precedence.
Take for example, in the statement "6+3*9", the 3 will firstly be multiplied by 9 andthen the result will be added to 6. This is because multiplication normally has a higherprecedence than the addition. To avoid ambiguity in reading the program it is advisable
to use parenthesis to control the order of how the expression is evaluated. In thisexample, it is recommended that the statement is written as "6+(3*9)(MSDN, n.d.).
For example:
JavaScript
var result = 72 * 9 + 4;document.write(result);
document.write("
");result = 72 * (9 + 4);document.write(result);
// Output:// 652
// 936
There are three operators in the first expression: =, *, and +. According to the rules of
operator precedence, they are evaluated in the following order: *, +, = (72 * 9 = 648, 648+ 4 = 652).
-
7/31/2019 Week7-Asg
3/4
In the second expression the () operator is evaluated first, so that the addition expression isevaluated before the multiplication (9 + 3 = 13, 13 * 72 = 936).
b) 6 + 2 * 3
i) Using the rules of operator precedence; the expression is evaluated in thefollowing order: *, +, = (2 * 3 = 6, 6 + 6 = 12).
ii) However if () is used in the expression : (6+2) * 3 ; This means that the () isevaluated first before the multiplication: ( 6+2 = 8, 8 * 3 = 24)
Question 5
Structured programming enforces a logical structure on the program being written to make
it much easier to be understood, efficient and easier to be modified. It is also a subset of
procedural programming. The need of goto statement usage discouraged via structuredprogramming (Janssen, C., n.d.).
A top-down approach is used in structured programming where the overall programstructure is mapped out in compositional subsystems. Similar functions are coded into
submodels which allow the code to be loaded into the memory efficiently and it can be used
again in other programs. According to Rouse, M. (2005), object oriented programming iscounted to be a type of structured programming, as it uses its techniques for program flowand provides the data more structure.
Question 6
Strongly-typed programming language - In which each type of data (such as character,hexadecimal, integer and others) is predefined and one of the data types will need to beused to defined all variables or constants for the given program (Henke, F.W, 1984).
For example you need to convert a double to float then you need to write:
1. publicstaticvoid main(String[] args)
2. {3. float e = 0;
4. double g = 1;
5. e = (float) g;6. System.out.println(e);
7. }
In the example above, if the float is omitted then you will get an error thrown by the
compiler.
Also a point to note is that certain data types might only allow certain operations. The usescompliance and data typing is enforced via the language compiler. Although this type of
programming might provide some sort of consistent result as numerous rules are imposedon programmers; it actually do prevent programmers to get creative in using the provided
-
7/31/2019 Week7-Asg
4/4
data type. Also it also prevents programmers from inventing a data type which might not be
thought by the developers of the programming language
References:
Henke, F.W., 1998 A Strongly Typed Language for Specifying Programs Standford
University [Online] Available fromftp://reports.stanford.edu/pub/cstr/reports/csl/tr/84/258/CSL-TR-84-258.pdf (Accessed 23
October 2012)
Janssen, C., n.d., Structured Programming techopediA [Online]. Available from
http://www.techopedia.com/definition/16413/structured-programming (Accessed 22October 2012)
Laird, A., 2009, The Four Major Programming Paradigms Survey of ProgrammingLanguages [Online] Available fromhttp://alexlaird.name/content/uploads/2009/05/topicpaper17-
thefourmajorprogrammingparadigms.pdf (Accessed: 23 October 2012)
MSDN, n.d., Operator Precedence (JavaScript) MSDN Library [Online]. Available fromhttp://msdn.microsoft.com/en-us/library/z3ks45k7(v=vs.94).aspx (Accessed: 22 October
2012)
Rajaraman, V., 1998, Programming Languages A Brief Review, Resonance, 3(12), 43-54
[Online] Available from http://www.ias.ac.in/resonance/Dec1998/pdf/Dec1998p43-54.pdf
(Accessed 23 October 2012)
Rouse, M., 2005, Structured Programming SearchCIO-MidMarket, August 2005 [Online].
Available from http://searchcio-midmarket.techtarget.com/definition/structured-programming(Accessed: 22 October 2012)
Roy, P.V, 2009, Programming paradigms for dummies: What every programmer shouldknow New Computational Paradigms for Computer Music [Online]. Available fromhttp://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf(Accessed: 23 October 2012)
Schimdt, G., 2011, Beginners Introduction to the Assembly Language of ATMEL-AVR-Microprocessors [Online]. Available from http://www.avr-asm-download.de/beginner_en.pdf(Accessed 21 October 2012)
Webopedia, n.d. High-Level language Webopedia [Online]. Available fromhttp://www.webopedia.com/TERM/H/high_level_language.html(Accessed 23 October 2012)
ftp://reports.stanford.edu/pub/cstr/reports/csl/tr/84/258/CSL-TR-84-258.pdfftp://reports.stanford.edu/pub/cstr/reports/csl/tr/84/258/CSL-TR-84-258.pdfhttp://www.techopedia.com/definition/16413/structured-programminghttp://www.techopedia.com/definition/16413/structured-programminghttp://msdn.microsoft.com/en-us/library/z3ks45k7(v=vs.94).aspxhttp://msdn.microsoft.com/en-us/library/z3ks45k7(v=vs.94).aspxhttp://www.ias.ac.in/resonance/Dec1998/pdf/Dec1998p43-54.pdfhttp://www.ias.ac.in/resonance/Dec1998/pdf/Dec1998p43-54.pdfhttp://searchcio-midmarket.techtarget.com/definition/structured-programminghttp://searchcio-midmarket.techtarget.com/definition/structured-programminghttp://searchcio-midmarket.techtarget.com/definition/structured-programminghttp://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdfhttp://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdfhttp://www.avr-asm-download.de/beginner_en.pdfhttp://www.avr-asm-download.de/beginner_en.pdfhttp://www.avr-asm-download.de/beginner_en.pdfhttp://www.webopedia.com/TERM/H/high_level_language.htmlhttp://www.webopedia.com/TERM/H/high_level_language.htmlhttp://www.webopedia.com/TERM/H/high_level_language.htmlhttp://www.avr-asm-download.de/beginner_en.pdfhttp://www.avr-asm-download.de/beginner_en.pdfhttp://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdfhttp://searchcio-midmarket.techtarget.com/definition/structured-programminghttp://searchcio-midmarket.techtarget.com/definition/structured-programminghttp://www.ias.ac.in/resonance/Dec1998/pdf/Dec1998p43-54.pdfhttp://msdn.microsoft.com/en-us/library/z3ks45k7(v=vs.94).aspxhttp://www.techopedia.com/definition/16413/structured-programmingftp://reports.stanford.edu/pub/cstr/reports/csl/tr/84/258/CSL-TR-84-258.pdf