Download presentation
Presentation is loading. Please wait.
Published byCharleen Peters Modified over 9 years ago
1
Logic Formulation
2
What is Logic Formulation? LogicFormulationLogicFormulation The process of coming out with the basic steps to implement a procedure in computer programming. This is usually resorted to when having top-down design. Flowcharts and pseudo codes are the two of most common output of the exercise. http://au.answers.yahoo.com/question/index?qid=20071110191353AABc dvH http://au.answers.yahoo.com/question/index?qid=20071110191353AABc dvH
3
Bringing the steps as required by the task in PROPER ORDER so that when it is executed procedurally the desired result is achieved according to the required output specification. Bringing the steps as required by the task in PROPER ORDER so that when it is executed procedurally the desired result is achieved according to the required output specification. - Nilo M. Padre What is Logic Formulation? ….
4
Basic Control Structures (logical constructs that specify how instructions in a program are to be executed) Sequence Sequence Selection Selection Repetition Repetition Unconditional Jump Unconditional Jump
6
Sequence Instructions are designed to be executed (performed by the computer) in the order they are written (i.e., one after another). This control structure provides the building block for computer programs. It is used to show a single action or one action followed in order (sequentially) by another. Actions can be inputs, processes, or outputs. Instructions are designed to be executed (performed by the computer) in the order they are written (i.e., one after another). This control structure provides the building block for computer programs. It is used to show a single action or one action followed in order (sequentially) by another. Actions can be inputs, processes, or outputs.
7
Example Go to the phone Go to the phone Dial the pizza place Dial the pizza place Order the pizza Order the pizza Hang up Hang up
8
Sequence Structure
9
Selection (conditional, branch, or decision) The program branches off to different instructions depending on whether a condition is met; or, one of several blocks of program code is executed based on a test for some condition. It is used to tell the program which action to take, based on a certain condition. When a condition is evaluated, its result is either true or false. If the result is true, one action is performed; if the result is false, a different action is performed. The program branches off to different instructions depending on whether a condition is met; or, one of several blocks of program code is executed based on a test for some condition. It is used to tell the program which action to take, based on a certain condition. When a condition is evaluated, its result is either true or false. If the result is true, one action is performed; if the result is false, a different action is performed.
10
Example Open your wallet If you have enough money, If you have enough money, THEN Go to the phone. THEN Go to the phone. Dial the pizza place. Dial the pizza place. Order the pizza. Order the pizza. Hang up. Hang up. ELSE Forget the whole thing. ELSE Forget the whole thing.
11
Selection Structure Single Selection Single Selection T F
12
Double Selection Double Selection TF Selection Structure...
13
Multiple Selection Multiple Selection T F T F T F Selection Structure...
14
Repetition (looping or iteration) The program repeats the same instructions over and over. It is used when a set of actions is to be performed repeatedly. The program repeats the same instructions over and over. It is used when a set of actions is to be performed repeatedly.
15
Example DO gobble down pizza DO gobble down pizza WHILE there is still pizza. WHILE there is still pizza.Or DO gobble down pizza DO gobble down pizza UNTIL none remains. UNTIL none remains.
16
Repetition While Structure While Structure T F
17
For Structure For Structure T F Repetition Structure...
18
Do/While Structure Do/While Structure Repetition Structure... T F
19
Unconditional Branch The program jumps from one place to another. Structured programming forbids this structure. The program jumps from one place to another. Structured programming forbids this structure.
20
A part of SDLC’s implementation phase and provides an organized plan for breaking down the task of program development into manageable chunks, each of which must be successfully completed before moving on to the next phase. A part of SDLC’s implementation phase and provides an organized plan for breaking down the task of program development into manageable chunks, each of which must be successfully completed before moving on to the next phase.SDLC’s An outline of each of the steps used to build software applications. An outline of each of the steps used to build software applications. Program Development Life Cycle
22
1. Analyze: Define the problem. Be sure you understand what the program should do. Be sure you understand what the program should do. What the output should be – that is, exactly what the task should produce. What the output should be – that is, exactly what the task should produce. Identify the data, or input, necessary to obtain the desired output. Identify the data, or input, necessary to obtain the desired output. Determine how to process the input to obtain the desired output – that is, determine what formulas or ways of doing things can be used to obtain the output. Determine how to process the input to obtain the desired output – that is, determine what formulas or ways of doing things can be used to obtain the output.
23
2. Design: Plan the solution to the problem. Develop the algorithm (a logical sequence of precise steps that solve the problem). Every detail, including obvious steps, should appear in the algorithm. Develop the algorithm (a logical sequence of precise steps that solve the problem). Every detail, including obvious steps, should appear in the algorithm.
24
Translate the algorithm into a logic plan using any of the popular methods – flowcharts, pseudocode, top-down charts. These design tools help the programmer break a problem into a sequence of small tasks the computer can perform to solve the problem. Planning also involves using representative data to test the logic of the algorithm by hand to ensure that it is correct. Translate the algorithm into a logic plan using any of the popular methods – flowcharts, pseudocode, top-down charts. These design tools help the programmer break a problem into a sequence of small tasks the computer can perform to solve the problem. Planning also involves using representative data to test the logic of the algorithm by hand to ensure that it is correct.
25
3. Choose the interface: Select the objects (text boxes, command buttons etc.) Determine how the input will be obtained and how the output will be displayed. Then create objects to receive the input and display the output. Also, create appropriate command buttons and menus to allow the user to control the program. Determine how the input will be obtained and how the output will be displayed. Then create objects to receive the input and display the output. Also, create appropriate command buttons and menus to allow the user to control the program. This step is used with Windows Application but not with Console Application.
26
4. Code: Translate the algorithm/flowchart/pseudocode into a programming language. During this stage, the program is written in a particular language (e.g., Visual Basic, C, Java) and entered into the computer. The programmer/coder uses the algorithm/flowchart/pseudocode devised in Step 2 along with a knowledge of the programming language, say, Visual Basic. During this stage, the program is written in a particular language (e.g., Visual Basic, C, Java) and entered into the computer. The programmer/coder uses the algorithm/flowchart/pseudocode devised in Step 2 along with a knowledge of the programming language, say, Visual Basic.
27
5. Test and debug. Locate and remove any errors in the program. As the program is typed, some code editors point out certain types of program errors. Other types will detected by when the program is compiled ( or interpreted) and/or executed; however, many errors due to typing mistakes, flaws in the algorithm, or incorrect usages of the language rules can be uncovered and corrected only by careful detective work. An example of such an error would be using addition when multiplication was the proper operation. As the program is typed, some code editors point out certain types of program errors. Other types will detected by when the program is compiled ( or interpreted) and/or executed; however, many errors due to typing mistakes, flaws in the algorithm, or incorrect usages of the language rules can be uncovered and corrected only by careful detective work. An example of such an error would be using addition when multiplication was the proper operation.
28
6. Complete the documentation: Organize all the material that describes the program. Documentation is intended to allow another person, or the programmer at a later date, to understand the program. Internal documentation consists of statements in the program that are not executed, but point out the purposes of various parts of the program. Documentation is intended to allow another person, or the programmer at a later date, to understand the program. Internal documentation consists of statements in the program that are not executed, but point out the purposes of various parts of the program.
29
Documentation might also consist of a detailed description of what the program does and how to use the program (for instance, what type of input is expected). Documentation might also consist of a detailed description of what the program does and how to use the program (for instance, what type of input is expected). Documentation…
30
For commercial programs, documentation includes an instruction manual and on-line help. Other types of documentation are the flowchart, pseudocode, and top-down chart that were used to construct the program. Although documentation is listed as the last step in the program development cycle, it should take place as the program is being coded. For commercial programs, documentation includes an instruction manual and on-line help. Other types of documentation are the flowchart, pseudocode, and top-down chart that were used to construct the program. Although documentation is listed as the last step in the program development cycle, it should take place as the program is being coded. Documentation…
31
Flowcharting Symbols
32
Some Application Flowcharting Symbols Direct Access File Card File Computer Program Document (such as hard copy from a computer system
33
Some Application Flowcharting Symbols… Display Multidocument Manual Input Preparation Manual Operation
34
Some Application Flowcharting Symbols… Punched Tape Collate Sort Extract
35
Some Application Flowcharting Symbols… Merge Sequential Access Storage Magnetic Disk Direct Access Storage
36
Application Flowcharting The purpose of an application flowchart is to use symbols to give a general picture of what functions the computer system should perform. The purpose of an application flowchart is to use symbols to give a general picture of what functions the computer system should perform. It reveals how many program are to be written, what reports or documents are to be produced, and the form and source of the input data. It reveals how many program are to be written, what reports or documents are to be produced, and the form and source of the input data. It gives an overall picture of the application. It gives an overall picture of the application.
37
Program Flowcharting Symbols
38
Documentation…
40
Example Problem Suppose you are asked to determine the number of stamps to place on an envelop with the rule or policy that one stamp will be used for every five sheets of paper. Suppose you are asked to determine the number of stamps to place on an envelop with the rule or policy that one stamp will be used for every five sheets of paper.
41
Problem Analysis
42
Program Design
43
Documentation…
46
Choosing the Interface Form Layout Form Layout
47
Properties Table
48
Properties Table…
49
Coding the Program
50
Coding the Program…
54
Problem Given a street number of a one-way in New York, decide the direction of the street, either eastbound or westbound. Even-numbered streets run eastbound. Given a street number of a one-way in New York, decide the direction of the street, either eastbound or westbound. Even-numbered streets run eastbound.
55
Thank you for listening!
56
Arrays
57
Array An ordered set of values associated with a single variable name. – Shelly, Cashman, Dorin, Quasney An ordered set of values associated with a single variable name. – Shelly, Cashman, Dorin, Quasney A list of data items that all have the same type and the same name. - Ferrel A list of data items that all have the same type and the same name. - Ferrel A data structure whose elements are accessed by means of index positions. – Lambert & Osborne A data structure whose elements are accessed by means of index positions. – Lambert & Osborne A collection of a fixed number of variables of the same data type or a list (or table) of variables of the type. - Goldstein A collection of a fixed number of variables of the same data type or a list (or table) of variables of the type. - Goldstein
58
Declaring an Array Arrays are declared in a variable declaration section. Arrays are declared in a variable declaration section. General Syntax in C/C++ General Syntax in C/C++ component type arrayname[sizeN]…[size1];
59
Dimension The number of subscripts required to describe an array. The number of subscripts required to describe an array. The subscript or index is the item’s position in an array. It is an integer enclosed within the brackets (square or rounded).
60
Declaration Syntaxes For One-Dimensional For One-Dimensional type array_name[size]; For Two-Dimensional For Two-Dimensional type array_name[rows][columns]; For Three-Dimensional For Three-Dimensional type array_name[pages][rows][columns];
61
Examples double Department[7]; double Department[7]; The component of this array are: Department[0]Department[1]Department[2]Department[3]Department[4]Department[5]Department[6]
62
char Sign[25]; char Sign[25]; The components of this array are: Sign[0]Sign[1]Sign[2]...Sign[25]
63
typedef enum {Red, Green, Yellow} TrafficLight; TrafficLight Traffic[4]; The components are: Traffic[0]Traffic[1]Traffic[2]Traffic[3]
64
Assigning A Value to an Array The components of an array may be assigned values just like any other variables. The components of an array may be assigned values just like any other variables.Examples: FirstVisit[1] = Fri; Traffic[3]=Red;Department[5]=290.12;Sign[24]=‘*’;
65
Initializing an Array Syntax Syntax type-specifier array_name[sizeN]…[size1] = { value-list }
66
Examples Int num[7] = {1,2,3,4,5,6,7} Int num[7] = {1,2,3,4,5,6,7} char str[8]=“Laughter”; char str[8]=“Laughter”; which is the same as Char str[8]={‘L’,’a’,’u’,’g’,’h’,’t’,’e’,’r’} Char str[8]={‘L’,’a’,’u’,’g’,’h’,’t’,’e’,’r’}
67
int sqrs[7][2]= { int sqrs[7][2]= {1,1,2,4,3,9,4,16,5,25,6,36,7,49};
68
Unsized-Array Initialization char err1[12]=“read error\n”; char err1[12]=“read error\n”; char err2[13]=“write error\n”; char err2[13]=“write error\n”; char err3[18]=“cannot open file\n”; char err3[18]=“cannot open file\n”; which is the same as, char err1[]=“read error\n”; char err1[]=“read error\n”; char err2[]=“write error\n”; char err2[]=“write error\n”; char err3[]=“cannot open file\n”; char err3[]=“cannot open file\n”;
69
int sqrs[][2]= { int sqrs[][2]= {1,1,2,4,3,9,4,16,5,25,6,36,7,49};
70
Logic The grammar of correct thinking and reasoning. The grammar of correct thinking and reasoning. Two Elements: Two Elements: To think correctly and; To think correctly and; To reason out correctly. To reason out correctly. If one of the elements would be missing, then no logic can be derived from. If one of the elements would be missing, then no logic can be derived from. – Nilo M. Padre
71
Formulation An act or the product of formulating. An act or the product of formulating. - Merriam Webster (http://www.merriam- webster.com/dictionary/formulation) http://www.merriam- webster.com/dictionary/formulationhttp://www.merriam- webster.com/dictionary/formulation ● The act of creating something by thinking - The Free Dictionary (http://www.thefreedictionary.com/formul ation) http://www.thefreedictionary.com/formul ationhttp://www.thefreedictionary.com/formul ation
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.