Coe Research Paper
Short Description
COE112 Research with references...
Description
Mapúa Institute of Technology Muralla St., Intramuros, Manila 1002 Philippines
A Research Work in COE112
Submitted to: Professor Rafael G. Maramba
Submitted by: April Jem H. Saccuan CpE-I
MODULES Programmers most often break down the programming problem into small units, tackling one small task at a time. These reasonable units are called modules. They are also referred by programmers as subroutines, procedures, functions, or methods. This process of breaking down a large program into modules is called modularization. There are three reasons for doing such process. First is that modularization provides abstraction. It enables the programmer to see the big picture. It is also because abstraction is the process of paying attention to important properties while ignoring nonessential details, or is a selective ignorance. Second reason is that modularization allows multiple programmers to work on a problem. This enables programmers to develop new programs with lesser time by dividing large programs into modules assigning each module to an individual programmer or team. Last reason is that modularization allows programmers to reuse their work more easily. This is a feature of modular programs that allows individual modules to be used in a variety of applications. Most programs consist of a main program, which contains the basic steps, or the mainline logic, of the program. The main program then accesses modules that provide more refined details. A module includes a header, a body and a return statement. Naming a module is similar in naming a variable. The mainline logic of almost every procedural computer program can follow a general structure that consists of four individual parts: (1) Declarations, which include data types, identifiers, and sometimes initial values for global variables and constants; (2) Housekeeping tasks which include any steps that must be performed at the beginning of a program to get ready for the rest of the program. It include tasks such as displaying instructions to user, displaying report headings, opening any files the program requires, and inputting the first piece of data; (3) Detail loop tasks is the part which do the core work of the program. They execute repeatedly for each set of input data until there are no more; and (4) End-of-job tasks are the steps which are done at the end of the program to finish the application. They might include displaying totals or other final messages and closing any open files.
HIERARCHY CHARTS Programmers often use a program hierarchy chart, when a program has several modules calling other modules, which operates in a similar manner to show the overall picture of how modules are related to one another. A hierarchy chart tells only which modules exist within a program and which modules call others. This chart can be both a planning tool for developing the overall relationship of program modules before writing them and be a documentation tool to help others see how modules are related after a program is written.
STRUCTURES Structured programs do follow the rules of structured logic that is easy to follow. In the mid-1960s, mathematicians proved that any program, no matter how complicated, can be constructed using one or more of only three structures. A structure is a basic unit of programming logic. Each structure can be a sequence, a selection, or a loop. With sequence structure, programmers perform an action or task in order. A sequence can contain any number of tasks, but there is no option to branch off and skip any of the tasks. Once a series of actions in a sequence is started, it must continue step by step until the sequence ends. The second of the three structures is a selection structure or decision structure. With this structure, questions are asked and one of two courses of action is taken depending on the answer. Some people call the selection structure an if-then-else because it fits the statement for pseudocodes. The third of the three basic structures is a loop. In a loop structure, programmers continue to repeat actions while a condition remains true. These actions that occur within the loop are known as loop body. Other programmers refer to looping as repetition or iteration. Some other programmers call this structure a while…di, or more simply, a while loop, because it fits the statements in pseudocodes. Attaching structures end to end is called stacking structures. Besides stacking structures, individual steps in a structured flowchart diagram or pseudocode with additional or tasks can be replaced with other sequences, selections, or loops. Placing a structure within another structure is called nesting structure. Characteristics of Structured Program
A structured program includes only combinations of the three basic structuressequence, selection, and loop. Any structured program might contain one, two, or all three types of structures Each of the structures has a single entry point and a single exit point. Structures can be stacked or connected to one another only at their entry or exit pints. Any structure can be nested within another structure
Reasons for Structure
Clarity – As programs get bigger, they get more confusing if they are not structured. Professionalism – All other programmers expect your programs to be structured. It is the way things are done professionally.
Efficiency – Most of newer computer languages are structured languages with syntax that lets programmers deal efficiently with sequences, selection, and looping. Even programs that use older languages can be written in structured form. Newer languages such as C#, C++, and Java enforce structure by their syntax. Maintenance – You and other programmers will find it easier to modify and maintain structured programs as changes are required in the future. Modularity – Structured programs can be easily broken down into routines or modules that can be assigned to any number of programmers.
Difference of Structured Programs to Unstructured Programs A program in unstructured language consists of sequence of commands, or statements, usually one in each line. These lines may have labels. Labels help to jump any line in the program. Unstructured programming introduces basic control flow concepts such as loops, branches and jumps. They don't use concept of procedure and function. In contrast structured programs use procedures, subroutines and local and global variables. Yes an unstructured language uses labels and jumping statements example of unstructured are earlier language like assembly language. Structured languages are well equipped with control statements, procedures, functions etc. Examples of structured language are high level language like C# and C++. DESIGNING & WRITING A COMPLETE PROGRAM
As programs become larger and more complicated, the need for good planning and design increases. Without thorough planning and design, the components would never work together properly. Each program module to be designed needs to work well as a stand-alone module and as an element of larger systems for a computer-based application can be highly functional only if each component is designed well. Walking through the program’s logic on paper, or deskchecking, is an important step in achieving superior programs. Moreover, programmers can implement several design features while creating programs that can make the programs easier to write and maintain. A. Using Program Comments Programmers should use program comments where proper. Program comments are written explanations that are not part of the program logic but that serve as documentation for readers of the program. In other words, they are nonexecuting statements that help readers understand programming statements. The syntax used to create programming comments differs among programming languages.
In a flowchart, annotation symbol can be used to hold information that expands on what is stored within another flowchart symbol. This symbol is most often represented by a three sided box that is connected to the step it references by a dashed line. They hold comments, or sometimes statements that are too long to fit neatly into a flowchart symbol Well-placed comments are appreciated, when programmers modify a program written by another programmer, which explain complicated sections of the code. B. Choosing Identifiers The selection of good identifiers is an often-ovelooked element in program design. Choosing appropriate identifiers for variables, constants, and modules makes the programming job easier for others to understand your work. It usually makes sense to give a variable or a constant a name that is a noun or a combination of an adjective and a noun because it signifies a thing. Likewise, it makes sense to give a module an identifier that is a verb or combination of verb and noun, because module takes action. Names must be meaningful. Programmers refer to programs that contain meaningful names as self-documenting. This means that even without further explanation, the program code explains itself to readers. Usually programmers must use pronounceable names so that readers can read it meaningfully. Programmers are judicious in using abbreviations because some abbreviations might indicate other things rather than its real meaning. Digits are also avoided in a name because they must be get confused with the letter “O” and lower case “l”s are misread as the numeral 1. The system your programming language allows to separate words in long, multiword variable names is used. The form of the verb to be, such us is or are, in names for variables that are intended to hold a status are considered included. Many programmers follow the convention of naming constants using all uppercase letters, inserting underscores between words for readability. Organizations sometimes enforce different rules for programmers to follow when naming variables. It is the programmer’s responsibility to find out the conventions used in the organization and adhere to them. Some organizations use a variable-naming convention called Hungarian notation, in which variable’s data type or other information is stored as part of the name. C. Designing Clear Statements This design feature includes avoiding confusing line breaks and using temporary variables to clarify long statements. Most modern programming languages are free-form, meaning, programmers can arrange lines of code any way they see fit but must be ensured that the meaning is clear. With the free-form code, programmers are allowed to place two or three statements on a line. The latter, a temporary variable or a work variable is not used for input or output but instead is just a working variable that programmers use during a program’s execution.
D. Writing Clear Prompts and Echoing Input A prompt is a message that is displayed on a monitor to ask the user for a response and perhaps explain how that response should be formatted. Prompts are used both in command-line and GUI Interactive programs. When program input comes from a stored file instead of a user, prompts are not needed. But when a program expects a user response, prompts are valuable. Users also find it helpful when programmers echo their input. Echoing input is the act of repeating input back to a user either in a subsequent prompt or in output. E. Maintaining Good Programming Habits Programmers should continue to maintain good programing habits as they develop programming skills. If programmers maintain the habit of first drawing flowcharts or writing pseudocode their future programming projects will go more smoothly. If they desk-check program logic on paper before starting to type statements in a programming language, their programs will run correctly sooner. If they think carefully about variable and module names to be used and design the program statements to be easy to read and use, their programs will be easier to develop and maintain. MAKING DECISIONS Every decision made in a computer program involves evaluating a Boolean expression. It is an expression whose value can only be true or false. True/false evaluation is natural from a computer’s standpoint because computer circuitry consists of two-state-on-off switches, often represented by 1 or 0. A Boolean expression is used in every selection structure. The choices are mutually exclusive; that is, the logic can flow only to one of the two alternatives, never both. A selection structure is an if-then if it represents a single-alternative selection in which action is required for only one outcome of the question. The then clause is the part of the decision that holds the action or actions that execute when tested condition in the decision is true. LOOPING It is looping that makes computer programming both efficient and worthwhile. When you use a loop, you can write one set of instructions that operates on multiple, separate sets of data. Using a Loop Control Variable To make a while loop end correctly, programmers should declare a variable to control the loop’s execution and three separate actions should occur: The loop control variable is initialized before entering the loop; The loop control variable is tested and if the result is true, the loop is entered; and the body of the loop must take some action that alters the value of the loop control
variable. When writing a loop, the number of repetitions must be controlled. If not, you run the risk of creating an infinite loop. Programmers’ can control a loop’s repetitions in one of two ways: Using a counter to create a definite, counter-controlled loop and; using a sentinel value to create an indefinite loop. In using a definite loop with a counter, a loop is a counted loop or counter-controlled loop because the program keeps track of the number of loop repetitions by counting them. Within a correctly functioning loop’s body, you can change the value of the loop control variable in a number of ways. They can be altered by incrementing and others by reducing or decrementing. Many programmers prefer counted loops with a variable containing a 0 value for two reasons: (1) In many computer applications, numbering starts with 0 because of the 0-and-1 nature of computer circuitry and; (2) When you learn about arrays, you will discover that array manipulation naturally lends itself to 0-based loops. However in using an indefinite loop with a sentinel value, the value of loop control variable is not altered by arithmetic but by user input. Nested Loops Program logic gets more complicated when you must use loops within loops or nested loops. Outer loop is the loop that contains the other loop and the loop that is contained is the inner loop. You need to create nested loops when the values of two or more variables repeat to produce every combination of values. When creating nested loops, each loop has its own control variable. Avoiding Common Loop Mistakes The mistakes programmers most often make with loops are that they neglect to initialize the loop control variable, they neglect to alter the loop control variable, they use the wrong comparison with the loop control variable, and/or they include statements inside the loop that belong outside the loop. Using a Loop to Validate Data Loops are frequently used to validate date, that is, to make sure it is meaningful and useful. Validation might ensure that a value is the correct type, or that it falls within an acceptable range.
CONTROL BREAKS A control break is a temporary detour in the logic of the program. In particular, programmers use a control break program when a change in the value of a variable initiates special actions or cases special or unusual processing to occur. You usually write control break programs to organize output for programs that handle data records organized logically in groups based on the value in the field. To generate a control break report, your input records must be organized in sequential order based on the field that will cause the breaks. A control break program is one that reads a sequential file and performs special processing based on a change in one or more fields in each record in the file. ARRAYS An array is a series or list of values in computer memory which have the same name and data type but are differentiated with special numbers called subscripts. Usually, all values in an array have something in common. A subscript, also called an index, is a number that indicated the position of a particular item within an array. When arrays are declared, you declare a structure that contains multiple data items. Each item within an array has the same name and the same data type; each separate item is one element of the array. You can indicate the number of elements an array will hold – the size of the array – when you declare the array along with the other variables and constants. All array elements have the same group name, but each individual element also has a unique subscript indicating how far it is from the first element. After you declare an array, you can assign values to some or all of the elements individually. Alternatively, you can initialize array elements when you declare the array. Most programming languages use a statement similarly to declare a three-element array and assign values to it. After an array has been declared and appropriate values have been assigned to specific elements, you can use the elements in the same way you would use any other data item of the same type. Using an array provides an alternate approach to programming problem, which greatly reduces the number of statements you need. When you declare an array, you provide a group name for a number of associated variables in memory. Constants in arrays can hold the size of an array, can be the array values, or can be a subscript. Using a named constant for an array’s size makes the code easier to understand and less likely to contain an error. Array values are declared as constant when they should not change during the program execution.
Searching through an array to find a value you need involves initializing a subscript, using a loop to test each array element, and setting a flag when a match is found. With parallel arrays, each element in one array is associated with the element in the same relative position in the other array. When you need to compare a value to a range of values in an array, you can store either the low-or-high-end value of each range for comparison. When accessing data stored in an array, it is important to use a subscript containing a value that accesses the memory occupied by the array. When using a subscript that is not within the defined range of acceptable subscripts, the subscript is said to be out of bounds.
SORTING ALGORITHMS A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) that require sorted lists to work correctly; it is also often useful for canonicalizing data and for producing humanreadable output. More formally, the output must satisfy two conditions: The output is in nondecreasing order (each element is no smaller than the previous element according to the desired total order) and; The output is a permutation (reordering) of the input. Since the dawn of computing, the sorting problem has attracted a great deal of research, perhaps due to the complexity of solving it efficiently despite its simple, familiar statement. Sorting algorithms used in computer science are often classified by:
Computational complexity (worst, average and best behavior) of element comparisons in terms of the size of the list (n). For typical serial sorting algorithms good behavior is O(n log n), with parallel sort in O(log2 n), and bad behavior is O(n2). (See Big O notation.) Ideal behavior for a serial sort is O(n), but this is not possible in the average case, optimal parallel sorting is O(log n).Comparison-based sorting algorithms, which evaluate the elements of the list via an abstract key comparison operation, need at least O(n log n) comparisons for most inputs. Computational complexity of swaps (for "in place" algorithms). Memory usage (and use of other computer resources). In particular, some sorting algorithms are "in place". Strictly, an in place sort needs only O(1) memory beyond the items being sorted; sometimes O(log(n)) additional memory is considered "in place". Recursion. Some algorithms are either recursive or non-recursive, while others may be both (e.g., merge sort). Stability: stable sorting algorithms maintain the relative order of records with equal keys (i.e., values). Whether or not they are a comparison sort. A comparison sort examines the data only by comparing two elements with a comparison operator.
General method: insertion, exchange, selection, merging, etc. Exchange sorts include bubble sort and quicksort. Selection sorts include shaker sort and heapsort. Also whether the algorithm is serial or parallel. The remainder of this discussion almost exclusively concentrates upon serial algorithms and assumes serial operation. Adaptability: Whether or not the presortedness of the input affects the running time. Algorithms that take this into account are known to be adaptive
It is not always possible to say that one algorithm is better than another, as relative performance can vary depending on the type of data being sorted. In some situations, most of the data are in the correct order, with only a few items needing to be sorted. In other situations the data are completely mixed up in a random order and in others the data will tend to be in reverse order. Different algorithms will perform differently according to the data being sorted. Four common algorithms are the exchange or bubble sort, the selection sort, the insertion sort and the quick sort. The selection sort is a good one to use with students. It is intuitive and very simple to program. It offers quite good performance, its particular strength being the small number of exchanges needed. For a given number of data items, the selection sort always goes through a set number of comparisons and exchanges, so its performance is predictable. The selection sort marks the first element. It then goes through the remaining data to find the smallest number. It swaps this with the first element and the smallest element is now in its correct position. It then marks the second element and looks through the remaining data for the next smallest number. These two numbers are then swapped. This process continues until n-1 passes have been made. In bubble sort, the first two data items are compared and the smaller one placed on the left hand side. The second and third items are then compared and the smaller one placed on the left and so on. After all the data has been passed through once, the largest data item will have "bubbled" through to the end of the list. At the end of the second pass, the second largest data item will be in the second last position. For n data items, the process continues for n-1 passes or until no exchanges are made in a single pass. The insertion sort starts with the last two elements and creates a correctly sorted sub-list. It then looks at the next element and inserts it into the sub-list in its correct position. It takes the next element and does the same, continuing until the sub-list contains all the data. The quick sort takes the last element and places it such that all the numbers in the left sub-list are smaller and all the numbers in the right sub-list are bigger. It then quick sorts the left sub-list and then quick sorts the right sub-list. This is a recursive algorithm, since it is defined in terms of itself. This reduces the complexity of programming it; however it is the least intuitive of the four algorithms.
References 1. Baker, Mark (1999). MarkChrisSoft. Discussion of Sorting Algorithms. Retrieved from: http://atschool.eduweb.co.uk/mbaker/sorts.html 2. Anon (2001). Wikipedia the free Encyclopedia. Sorting Algorithms. Retrieved from: http://en.wikipedia.org/wiki/Sorting_algorithm 3. Anon (2012). Answers Corporation. What are structured and unstructured programs? Retrieved from: http://wiki.answers.com/Q/What_is_structured_and_unstructured_programs 4. Farell, Joyce et.al (2011) Computer Fundamentals and Logic Formulation, Second Edition. Pasig City, Philippines : Cengage Learning Asia Pte Ltd (Philippines Branch)
View more...
Comments