Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.74 KB | None | 0 0
  1. Explain the key features of procedural programs (P1)
  2.  
  3. Functions / Procedures
  4. Procedural programming is a fundamental style of programming, also known as a programming paradigm; the basic concept in this paradigm is the procedure (also known as a function, a method, a routine or a subroutine.) A procedure holds a set of instructions to be executed by a computer one after the other, during a program’s execution, a procedure can call any other procedure, including itself.
  5. Using functions and procedures also creates modularization within the code, allowing it to be split down into smaller reusable segments increasing the overall efficiency of the program, saving memory whilst looking clean.
  6. Functions are almost identical to procedures regarding their practicality however share one distinct feature which contrasts the two. Procedures execute the code In the order which they are written, functions do the same although return a value at the end of the block, allowing the program to display any form of error codes to the user if the function was not successful. This one distinct feature is one of the only differences between the two
  7. Example:
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int add(int a, int b);
  12.  
  13. int main()
  14. {
  15. int x = 0;
  16. int y = 0;
  17. int sum = 0;
  18. cout << "Enter first number: ";
  19. cin >> x;
  20. cout << "Enter second number: ";
  21. cin >> y;
  22. sum = add(x,y);
  23. cout << "The sum of " << x << " and " << y << " is " << sum << endl;
  24.  
  25. return 0;
  26. }
  27. int add(int a, int b)
  28. {
  29. int c = a + b;
  30. return c;
  31. }
  32.  
  33. (Int main and int add are both functions)
  34. Pre-defied functions
  35. Pre-defined functions, are features built in to a programming language to make programming easier, examples of pre-defined functions are functions for string manipulation, mathematical operations and file access. Unlike standard functions the user has no input in the way that they execute.
  36. Example:
  37. Variables
  38. Procedural languages use variables to represent an address in memory and the data held in that address, variables can have the property of scope; scope refers to the sections of a program that can and can’t access the data a variable represents. A variable can be either local or global in scope
  39. Local Variables
  40. A local variable can only be accessed by the function it is initialised in, it cannot be called anywhere except its origins, doing so would create errors within the code.
  41. The below example shows the variables declared inside the function in which they are unique to, calling these variables within this function would be completely acceptable and would cause no errors, calling it in another function would not work.
  42. Example:
  43. void Circle()
  44. {
  45. int pi=3.141592
  46. int radius=0
  47. }
  48.  
  49. Global Variables
  50. Global variables are declared outside of all functions usually residing after the calling of libraries. Unlike local variables, global variables can be accessed anywhere in a program. The feasibility of global variables are somewhat similar to functions as they save memory from their reusability. However they do present problems when used in conjunction with local variables, for this reason they are usually a taboo to use.
  51. Example:
  52. #include <iostream>
  53. using namespace std;
  54. int a=3
  55. int main()
  56. {
  57. a++;
  58. }
  59.  
  60. Parameter Passing
  61. Variables can also be passed to other functions; variables that are passed to other functions are called arguments, a function has to be defined with variables called parameters in order to accept arguments. The passing of arguments to parameters is called parameter passing.
  62. Programming Libraries
  63. Programming libraries also allow a programmer to reuse code by writing subroutines that can be easily called on.
  64.  
  65.  
  66.  
  67. Modular Design
  68. Modular design is a method of designing procedural programs by separating individual functions so that each function carries out a specific task, this can make development and maintenance easier as well as allowing code to be reused. Procedural programming languages commonly feature a library of pre-defined functions for common operations.
  69. Control Structures
  70. Control structures are the basic elements in a program that dictate the direction a program takes, these elements include loops, statements, and conditional statements.
  71. Loops
  72. A loop is a type of control structure that contains a series of statements to be executed a specified amount of times or until a certain condition is met. There a few types of loops examples being for loops, while loops and do-while loops otherwise known as fixed, pre-check and post-check.
  73. -Fixed loop
  74. A for loop is a type of loop that executes until the loop counter meets the predefined value. Unlike a while loop or a do while loop, the number of iterations is known before the loop is executed
  75. -Pre-check
  76. A while loop is a type of loop that executes as long as a condition is true
  77. -Post-check
  78. a do-while loop is similar to a while loop, the difference is that a do-while loop executes at least once before evaluating a condition to see if it is true, this is known as a post-check loop
  79. Breakpoint ****
  80. Conditional commands****
  81. -The If Construct
  82. This is a type of conditional command used to control program flow in many programming languages, after the If, the computer evaluates a condition to determine whether it is true or false, if it is true, then conditions following the statement immediately are executed, if the condition evaluates as false, conditions following the next branch are executed. The If construct generally follows an if-then-else format, although not all languages may implement this explicitly, for example C and C++.
  83. Example:
  84. -Case and Switch
  85. This is another type of conditional command that is used to control program flow in many programming languages, a case and switch construct compares an inputted value to a set of predefined values and switch the flow of the program based on the first condition that matches, generally there is a default statement that is executed if there is no match found.
  86. Example:
  87. -Boolean operators
  88. A data type that can either be true or false is called a Boolean value *****
  89.  
  90.  
  91. Procedural programming languages
  92. Examples of procedural programming languages are C, Pascal, COBOL and FORTRAN.
  93.  
  94. Explain why modular elements are important for procedural programming (M1)
  95. Modular programming is the practice of breaking down each function of a program into separate pieces; this allows each element to carry out a specific task with as little external dependencies as possible. Modular elements are important for procedural programming because it increases code reusability, maintainability and allows easier collaboration between programmers. This is because each module can be developed separately and updated without affecting the rest of the system, another advantage of modular design is that a programmer does not need to know about other modules and thus need not worry about their code affecting the rest of the system, focusing on their module instead.
  96. Top down programming
  97.  
  98. D1 – Evaluate the suitability of procedural programs for graphical applications
  99. A long time ago, in the infancy of computers, computers were hooked to teletype machines which were essentially typewriters. These primitive machines were only capable of the most simple graphics; characters.
  100. Below is an example of the graphics you could get from one of these machines.
  101. |\_/| ************************************ (\_/)
  102. / @ @ \ * Jacob Knight * (='.'=)
  103. ( > º < ) * Professional cunt * (")_(")
  104. `>>x<<´ * (jacobknight101@hotmail.co.uk) *
  105. / O \ ************************************
  106.  
  107.  
  108. Its dominance was further enhanced by the rising popularity of graphical user interfaces, which rely heavily upon object-oriented programming techniques. An example of a closely related dynamic GUI library and OOP language can be found in the Cocoa frameworks on Mac OS X, written in Objective-C, an object-oriented, dynamic messaging extension to C based on Smalltalk. OOP toolkits also enhanced the popularity of event-driven programming (although this concept is not limited to OOP).
  109.  
  110. Are procedural languages suitable for graphical applications?
  111. Well, let’s have a look at some popular widget toolkits (native and cross platform). The majority of GUI libraries or APIs are written in an object oriented language, Qt, WxWidgets, MFC (Microsoft Foundation Classes, Windows Forms, Cocoa etc, therefore they must be interfaced with an object oriented language. The only non-object oriented GUI libraries or APIs are GTK+, Elementary and the Win API (which is notoriously complex to develop for, thus the existence of MFC and Windows Forms).
  112. So it seems pretty clear that object oriented languages are the preferred choice for GUIs, because in object oriented language there are constructs which simplify managing the many
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement