Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 110 PROGRAMMING LOGIC CHAPTER 2

Similar presentations


Presentation on theme: "CSC 110 PROGRAMMING LOGIC CHAPTER 2"— Presentation transcript:

1 CSC 110 PROGRAMMING LOGIC CHAPTER 2
PROGRAMMING TOOLS CSC 110 PROGRAMMING LOGIC CHAPTER 2 4/3/2019 Prepared by: Deborah Becker

2 Prepared by: Deborah Becker
Topics to Be Covered Program Development Cycle Program Planning Programming Tools Summary 4/3/2019 Prepared by: Deborah Becker

3 Prepared by: Deborah Becker
Computer Components Hardware & software Problem solving process Input Processing Output Storage The hardware and software makeup the computer system. Together the hardware and software are used by the programmer to accomplish four operations. Input, Processing, Output, Storage Devices used to perform inputs are Keyboards, mice, modems, CDs etc. We use these devices to enter data or facts into the computer. Processing the data can include organizing the data into reports or screen displays, checking the data for accuracy, or performing mathematical functions on the data. The processing is done by the CPU, through program instructions The resulting information is then output to a printer or the screen as output. Normally this data will be stored either on removable media (zip, floppy, CD) or secondary storage devices like hard drives or personal logical drives on a server. The software consists of the instructions that tells the system how the data will be input, how they are processed, and when the data will be output or stored. Input Processing Output 4/3/2019 Prepared by: Deborah Becker

4 Prepared by: Deborah Becker
Programming Programming languages are used to write instructions for the computer. Visual Basic, Cobol, C#, C++, Java Programming language all have similar capabilities Each language has its own set of rules governing its words and punctuations This is the languages syntax Instruction to bake a cake If you are speaking to an individual and your say: Rain it will by Sunday. Most people will be able to correct your syntax and understand what you are trying to convey. The computer is not that smart. Unless your use perfect syntax the program will fail to run correctly. Sometimes the program will execute but the output will be unpredictable. Each computer must translate your instructions into machine language in order to understand the instructions. Compilers or Interpreters are used to translate the instructions and they also tell you if your syntax is correct. Therefore syntax errors are fairly easy to find and correct. Logic errors are more difficult. Program instructions must be given to the computer in the correct order, and no step can be left out or the program may execute but the processing will not be handled correctly. Suppose you instruct someone to make a cake as the Following Stir --> Add two eggs--> Add 1 gallon of gasoline--> Bake at 350 degrees for 45 minutes--> Add 3 cups of flour Even though you have used English the instruction are not in the correct order and they are not the correct instruction to bake the cake. Good programming involves a Program development cycle and a Planning process. 4/3/2019 Prepared by: Deborah Becker

5 Program Development Cycle
Begin with the end in mind (Output) Read the assignment carefully Determine what the output should be Determine what data is required (Input) Determine if existing data files need modification Code the program to achieve the output (Process) Read the assignment or the problem carefully. If you have a copy of the desired output or the screen design it will be easier to envision the steps you will need to take to solve the problem. Even if you change the output design all the requirements of the problem must be met. Next determine if the data is available to solve the problem. Will you need to ask the user for additional data or is the data needed to solve the problem stored on the system? Finally determine how to process the input to obtain the desired output. This is our task list for the problem. The task list will assist you in creating your flowchart, or Pseudocode 4/3/2019 Prepared by: Deborah Becker

6 Prepared by: Deborah Becker
Program Planning Analyze Be sure you understand what the program should do before you begin Design the solution to the problem Task list Fill out the user interface and property sheet Professional programmer write programs to satisfy the needs of others. You may be writing a report processing program for the HR that will show a complete list of all employees and their addresses. You may be writing a program in gather data about a companies customers. Make sure that you under stand the instruction completely before you being the next step. Design a complete sequence of steps called the Algorithm, that will solve the problem. In your Packet use the Task Sequence form to list a complete set of steps that your will take to solve the problem. To the left of each step indicate the flow chart symbol that represents that activity. In the packet you will see a sheet of paper called the Interface Design Planning Sketch. It looks mostly blank. This is where you will sketch out your intended user interface. The Interface will contain objects from the toolbox that will be used to gather the needed data and or display the desired output to the screen. Next fill out the property sheet for the user interface. In our packet look at the form Titled Objects and Properties Plan Form. On this sheet you will list all the objects on your user interface. You will also indicate any properties for that object that you change from the default, and the value that the property is changed to. On both forms indicate the name of the Form that the sheet is describing. 4/3/2019 Prepared by: Deborah Becker

7 Prepared by: Deborah Becker
Program Planning Code Translate the Algorithm into code Test & debug Make sure your code is user-proof Complete the Documentation Once the programmer has developed the logic of the program, only then can they write the program in one of more than 400 programming language. This is the step where the programmer translates the tasks that have been identified into the syntax of the chosen language. In this step you must worry about whether the words are spelled correctly, the correct punctuation is used and the logic is entered in the correct order. After the program has been coded into the coding screen and the syntax errors have all been corrected it is time to test the program to solve any logic problems that may have been introduced into the program during the coding phase. We call this testing and debugging. The programmer should also develop a set of test data to test the logic of the program to make sure that all processes are preformed correctly. Once the program is thoroughly debugged, you should complete both the internal and external documentation. This means placing comments or remarks inside the procedures of the code to help jog your memory if the program should require updating at a later date. All the form that your filled out in your planning stage are part of your external documentation. And just as your would correct a letter or paper for an English class your should also go back to your planning sheets and indicate any changes that were made to the program during the coding and debugging phase. 4/3/2019 Prepared by: Deborah Becker

8 Prepared by: Deborah Becker
Structure There are three basic structures from which all logic flows Sequences Selection (decisions) Loops (repetition) We use flowcharting symbols to represents these structures Diagram a sequence on the boars Diagram a selection on the board Diagram a loop structure on the board 4/3/2019 Prepared by: Deborah Becker

9 Prepared by: Deborah Becker
Flowchart Symbols Flow Lines Terminals Input/Output Terminator Reading, Printing Flow lines (Arrows) are used to connect the other symbols in the order in which they are to be executed. The also indicate the logic flow of your program. Terminators: Represents the beginning and the End of the program or algorithm. They usually contain the words start, stop or end but may also contain the name of the algorithm. The input/output symbol indicates that data will be entered or retrieved or that the processed data will be output to a report of screen display. 4/3/2019 Prepared by: Deborah Becker

10 Prepared by: Deborah Becker
Flow charts Processing Decision Connector Off-Page Connector Used for Math and Data manipulation Logic/comparison Both connectors are used to join flow lines & pages YES NO The processing symbol indicated computer processing of the information. The nature of the processing is described within the block. The decision symbol indicate a computer decision selecting between two alternate logic paths in the algorithm. It is characterized by two arrows leaving the block showing the two alternate logic paths. Connector – the connector symbol represents a junction of two or more parts of the flowchart. They join flow lines or indicate the connection of two flowcharts. The off-Page connector indicates that the flowchart will continue on another page. 4/3/2019 Prepared by: Deborah Becker

11 Prepared by: Deborah Becker
Flow Charts Calculate the Payroll Print Payroll register Print Payroll checks Print Withholding Checks Predefined Process Annotation The predefined process symbol represents computer processing which is complex enough to require a separate flowchart to describe it. The block contains the name of the separately charted routine. It may also contain the a group of statements that perform one processing task. Such as a routine that will be executed each time a record is read or a decision block is processed. Annotation is used to provide additional information about other flowchart symbols. It can also be used to provide additional documentation for the program. 4/3/2019 Prepared by: Deborah Becker

12 Prepared by: Deborah Becker
Problem: Calculate and report the grade point average for the class. Average grade =  of all grades no of students Start program Open the data file Loop to read all grades Accumulate the total. Count the number of students Calculate Class Average Print the Class Average End program Take our a piece of paper and see if you can create a hierarchy chart for this algorithm. 4/3/2019 Prepared by: Deborah Becker

13 Prepared by: Deborah Becker
Flowchart Class Average 4/3/2019 Prepared by: Deborah Becker

14 Prepared by: Deborah Becker
Class Average Problem 4/3/2019 Prepared by: Deborah Becker

15 Prepared by: Deborah Becker
Hierarchy Charts Hierarchy charts are also call structure charts, or HIPO, top down charts, or VTOC. They look a lot like a company organizational chart. They indicate the organization of your program but omit the specific processing logic. They describe what each module of the program does and they show how the modules relate to each other. The chart is read from top to bottom, and the lines indicate the processes that are linked. So each process may have sub- processes. The program hierarchy chart begins with a main block or procedure that controls or calls other procedures that actually carry out the processing tasks. This serves are a sort of table of contents for your program and shows the main tasks that are to be preformed. The main benefit of hierarchy charts is in the initial planning of a program. The program is broken down into major processes so that the programmer can see what needs to be done. Then we can use flowcharts and pseudocode to add more details to our plans. 4/3/2019 Prepared by: Deborah Becker

16 Prepared by: Deborah Becker
Pseudocode English like phrases with some VB code Determines the flow of the program Should contain one statement or more for each procedure Can be general or detailed Pseudocode is often used in place of flowcharts to design and document program logic. Because of its similarity to English, pseudocode is sometimes referred to as structured English. Because it is not diagrammatic it is much easier to produce and modify the structured flowcharts. There is no universal version of pseudocode,but it must represent the three fundamental logic structures: sequences, selection, and iterations or sequences, decisions and loops. These will be covered in chapter 4,5, and 6. Input, output, and processing are described in English like phrases and indentation is used to show relationships among pseudocode statements. 4/3/2019 Prepared by: Deborah Becker

17 Example Pseudocode for Logic Structures
Sequences Increment days overdue counter by 1 Compute late charge as 5% on balance due Build customer statements for printing Decisions If hours worked is less than 40 Process regular payroll check Else Process regular pay plus overtime pay End if Each line in the sequence pseudocode is a process The pseudocode for the decision breaks the code up into areas that are preformed is a condition is true and another if the condition is false 4/3/2019 Prepared by: Deborah Becker

18 Prepared by: Deborah Becker
Pseudocode for Loops Loop (Iterations) Do while Customer balance is > 0 Process customer statements Loop An iteration is a complete execution of a set of instructions. Loops help us to make good use of logic to perform set of instructions until a condition is either true or false. 4/3/2019 Prepared by: Deborah Becker

19 Solve the following Problem
Do the planning steps for a program that calculates the number of lbs of grass seed needed to seed a lawn. The program will ask the user to enter the length and width of their yard. Assume that 40 ounces of seed is recommended for each 2000 sq.ft. of yard. Display results—the number of ounces of seed needed to seed the customers yard. Create a task list and a flowchart for the problem. Write the pseudocode for the algorithm. Get user input for length and width of yard Calculate number of sq. ft. in the yard Calculate number of units by Dividing the total number of sq. ft by 2000 Calculate total Ounces of seed needed (Multiply the number of units by 40 oz.) Divide the total ounces of seed by 16 (there are 16 oz to a #) start Get length and width Get total Sq. Ft. 4/3/2019 Prepared by: Deborah Becker Get total units needed Get total oz Of seed needed Get #’s Needed Display results end

20 Prepared by: Deborah Becker
Summary Planning Process Programming tools Flow charts Hierarchy Charts Pseudocode START Reading Chapter 3 for next week That’s all folks 4/3/2019 Prepared by: Deborah Becker


Download ppt "CSC 110 PROGRAMMING LOGIC CHAPTER 2"

Similar presentations


Ads by Google