Data and Flowcharts Session Deborah Becker
Agenda The programming process Data hierarchy Assigning values to variable The three basic structures Is my program structured Exercises
Programming Process Understand the problem Plan the logic Code the problem Test the program Put the program into production
Understand the problem! Programs satisfy users needs HR wants a list of employees who have been with the company over five years Understand what the users wants This is the probably the most important step in planning your program. Does HR want a list of full time employees or should the list include part-time as well? Should the list include contract employees? What starting date should be used to begin the query? Do they want only those who worked for the company continuously for five years or should you include those employees that may have taken family leave but returned? The programmer must not make assumptions about what the user wants. What do they want the report to look like? What data should the report include; first and last name, phone, ssn. Is all this data contained in one file or will several files need to be opened? You will need to ask the user for things link print layout and file specification data.
Plan the logic Develop your algorithm This is not the time to worry about the syntax of the language You can test the logic by creating several records to put through your logic structure manually The programming plans each task or step of the program. You also need to determine the execution order of each step. We will use our pseudocode and flowchart tools to help us plan the order of the instructions.
Code the Program This is where the programmer needs to worry about the syntax. If the planning stage was developed successfully the coding step will require less time.
Test and Retest Programs that are free of syntax errors are not necessarily free of logic errors. This step will require a set of test data
Production After the testing produces clean output the program will be ready to place into production Allow the user to use the program Any good user can find any unresolved bug in even the most error free code? Fixing bug problems and modifying the code is called maintenance programming. About half of your will go on to be maintenance programmers and you will become experienced documentation interpreters.
Six Basic Computer Operations Receives Information Outputs Information Performs Arithmetic Assigns value to variables Compares variables Repeat groups of instructions
Data Hierarchy Database File—(User defined type/Class) Record—(Class Instance/object) Field—(Attribute) The individual pieces of data that describe each instance of the file or class. Character Employee Class or file attributes strFirstName strLastName strAddress strPhone strSSN sngSalary
Problem! Write a program to read the instances of an employee class. Print employee class list report of those with 4 or more years of employment. Attributes to collect Name (First and Last) Address (Street, City, State, Zip) Social Security Number Phone Number Years of employment
Step 1 Do you Understand the Problem? Yes No Create your task list Define all the steps needed to solve the problem Don’t worry about the order of the steps until you feel that your list is complete. No Ask the user questions until your know the answer to all your questions. Do you have a copy of the report layout? Task list 1. Start 2. Open employee file 3. Process records while not EOF 4. Read first record 5. If years of employment >= 4 then add to report 6. If years of employment < 4 read next record 7. If end of file = true then Print report 9. Close data file 10. End
Step 2 Put the task in order of operations Construct your flowchart Fill in your task list Fill in your flowchart symbols for each task Construct your flowchart
Step Three Draw the User Interface Draw the objects from the tool box on the user interface that you need to solve the problem Write the object name beside each object Indicate Attribute name if a data file is going to be used REMEMBER CLASS IS ANOTHER NAME FOR DATA FILE ATTRIBUTE IS ANOTHER NAME FOR FIELD Generate Pseudocode, Flowchart
Steps Three cont. Code the problem Use Pseudocode, Flowchart Create project in coding editor When the runtime errors have been eliminated you are ready for step four.
Step Four Create Sample records Create two or three records. Desk check your flow chart to make sure that your data and logic solve the algorithm. Add any needed structure changes. Data records will usually be supplied with the problem definition sheet.
Structures There are three basic structures from which all logic flows Sequences Selection (decisions) Loops (repetition) Diagram a sequence on the boars Diagram a selection on the board Diagram a loop structure on the board
Structures Selection Loop Sequence IF While
Solving Algorithms All problems can be solved using only these three structures They can be combined in infinite ways Each must have one entrance and one exit This make the program structured Attaching the structures end to end is called stacking
Other steps Use your Flowchart Form and write your pseudocode to the right of your flowchart. Remember there are no set rules—this is a tool to help you when you begin to code your solution. Use structured statement form and indentations to make the logic more apparent.
Example Pseudocode Do step A Do Step B If Condition C is true then Do Step D Else Do Step E Endif While condition F is true Do Step G Step a Step b If C Yes No You can have a sequence inside a selection structure or inside a loop. Programs can become very complicated but remember each structure must have one way in and one way out. Step e Step d Yes While F Step g No
Things that will help? Yeah! Your ready to turn on the computer. Completed task list (order your task) Draw your flowchart Desk check your data Does the data flow into and out of your structure correctly? Draw your User Interface and Name your objects Write your pseudocode Yeah! Your ready to turn on the computer.