27 March, 2000 CS1001 Lecture 9 Program Debugging Previews of Arrays, Functions, and Subroutines More Project Design and code segments.

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

Programming Types of Testing.
Chapter 10 Introduction to Arrays
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Performance Analysis and Monitoring Facilities in CPN Tools Tutorial CPN’05 October 25, 2005 Lisa Wells.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
27 March, 2000 CS1001 Lecture 7 Nested IFs Character Input IF and Input Validation Project Introduction.
Program Flow Charting How to tackle the beginning stage a program design.
13 April, 2000 CS1001 Lecture 17 One-Dimensional Arrays Using 1-D arrays in Project.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Software Engineering Principles and C++ Classes
Programming Fundamentals (750113) Ch1. Problem Solving
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
CS102 Introduction to Computer Programming
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Programming Translators.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
General Programming Introduction to Computing Science and Programming I.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction. 2COMPSCI Computer Science Fundamentals.
Programming Lifecycle
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Testing Methods Carl Smith National Certificate Year 2 – Unit 4.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Computer Science 112 Fundamentals of Programming II Modeling and Simulation.
Chapter 2 – Fundamental Simulation ConceptsSlide 1 of 46 Chapter 2 Fundamental Simulation Concepts.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
The Hashemite University Computer Engineering Department
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
 Simulation enables the study of complex system.  Simulation is a good approach when analytic study of a system is not possible or very complex.  Informational,
CS1010: Programming Methodology
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
ALGORITHMS AND FLOWCHARTS
Introduction to Computing Science and Programming I
5.01 Understand Different Types of Programming Errors
Testing and Debugging.
Lecture 2 Introduction to Programming
Lecture2.
Computer Programming.
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Problem Solving Skill Area 305.1
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Review of Previous Lesson
CHAPTER 6 Testing and Debugging.
Presentation transcript:

27 March, 2000 CS1001 Lecture 9 Program Debugging Previews of Arrays, Functions, and Subroutines More Project Design and code segments

27 March, 2000 Errors in program development Common errors: –syntax or compiler errors -- errors discovered during compilation; e.g., punctuation, unbalanced ( ) –Run-time errors -- errors detected during execution of the program; e.g., division by zero, overflow –Logic errors -- errors in design of algorithms and in coding the algorithms System error messages help solve syntax and run- time errors Programmers must debug and solve logic error by using their knowledge of the problem, the algorithm and the coding.

27 March, 2000 Range of noise level example Text pages LargestLevel = 0 SmallestLevel = 999 DO Print * “Noise level?” Read *, NoiseLevel IF (NoiseLevel > LargestLevel) THEN LargestLevel = NoiseLevel Else IF (NoiseLevel < SmallestLevel) THEN SmallestLevel = NoiseLevel END IF IF (NoiseLevel < 0) EXIT END DO PRINT *, LargestLevel-SmallestLevel Input data

27 March, 2000 Desk checking Trace Table - recording in a table, step by step, the important variables LoopNoiseLevelLargestLevelSmallestLevel First pass Second pass Third pass Fourth pass Therefore LargestLevel-SmallestLevel = 102- (-1) = 103 Use temporary print statement in code Use special system debugging software

27 March, 2000 Modify and retest LargestLevel = 0 SmallestLevel = 999 DO Print * “Noise level?” Read *, NoiseLevel IF (NoiseLevel < 0) EXIT IF (NoiseLevel > LargestLevel) THEN LargestLevel = NoiseLevel Else IF (NoiseLevel < SmallestLevel) THEN SmallestLevel = NoiseLevel END IF END DO PRINT *, LargestLevel-SmallestLevel Input data output is 14 What if? Input data

27 March, 2000 Desk Check of revision LoopNoiseLevelLargestLevelSmallestLevel First pass Second pass Third pass Fourth pass Therefore LargestLevel-SmallestLevel = (999) = -897 LoopNoiseLevelLargestLevelSmallestLevel First pass Second pass Third pass Fourth pass Therefore LargestLevel-SmallestLevel = 102- (88) = 14

27 March, 2000 Modify & Retest LargestLevel = 0 SmallestLevel = 999 DO Print * “Noise level?” Read *, NoiseLevel IF (NoiseLevel < 0) EXIT IF (NoiseLevel > LargestLevel) LargestLevel = NoiseLevel IF (NoiseLevel < SmallestLevel) SmallestLevel = NoiseLevel END DO PRINT *, LargestLevel-SmallestLevel

27 March, 2000 Desk Check of revision 2 LoopNoiseLevelLargestLevelSmallestLevel First pass Second pass Third pass Fourth pass Therefore LargestLevel-SmallestLevel = (88) = 14 LoopNoiseLevelLargestLevelSmallestLevel First pass Second pass Third pass Fourth pass Therefore LargestLevel-SmallestLevel = 102- (88) = 14

27 March, 2000 More Efficient Implementation Print * “Noise level?” Read *, NoiseLevel LargestLevel = NoiseLevel SmallestLevel = NoiseLevel DO IF (NoiseLevel < 0) EXIT IF (NoiseLevel > LargestLevel) THEN LargestLevel = NoiseLevel ELSE IF (NoiseLevel < SmallestLevel) SmallestLevel = NoiseLevel END IF Print * “Noise level?” Read *, NoiseLevel END DO

27 March, 2000 Preview of Arrays Primitive data types vs structured data types An array is a data structure –elements are of the same type –access to elements by index -- elements are subscript variables –Specification and declaration: REAL, DIMENSION(l:u) :: array-name –Example: INTEGER, DIMENSION(1:10) :: Input INTEGER :: Range, Choice DO Range=1, 10, 1 READ *, Input(Range) END DO

27 March, 2000 Array Preview Continued Why arrays? Because you can operate on the subscript. Example, continued: PRINT *, “Pick a box from 1 to 10” READ *, Choice PRINT *, “Box ”, Choice, “ contains number ”, Input(Choice) You can perform much more complex operations on the variable used for the subscript

27 March, 2000 Preview of Functions and Subroutines Fortran provides library functions for many common operations and functions. (Chap 2) User defined functions and subroutines –For large complex problems, divide the problem into a number of simpler problems. –Each subproblem can be considered separately, designed and coded separately. –These codes of subproblems are then combined to form the whole solution. –Each of these separate set of code -- functions and subroutines –Functions and subroutines are controlled by the main program

27 March, 2000 Project Introduction Checkout stations Servers check customers out at an average of average-service-time Customers arrival rate

27 March, 2000 Project Introduction (cont’d) Grocery Simulation Output StatisticsGet parametersRun Simulation Simulation Clock Generate Customers Checkout Customers Gather Statistics

27 March, 2000 Run Simulation At time zero, set parameters and initialize Simulation Clock Given Sim_Time: The simulation clock may be DO Time = 1, Sim_Time Generate Customers Checkout Customers Gather Statistics for time step Time END DO

27 March, 2000 Generate Customers Define a function to generate new customers: NArrivals = CustomerGeneration ( ) Put new customers into queue IF (NArrivals.NE. 0) then DO I = 1, NArrivals ! Find Shortest or appropriate queue ! Add to queue END DO END IF

27 March, 2000 Queue Represent each check_out station as a FIFO queue Should have 1.ways to have customers come in and go out 2.A idle_time counter to keep track of number of minutes when there is no customer in the queue. 3.At a time step (a minute), if no customer in queue, then we can increase idle_time counter by 1 minute. 4. Should we have a counter to see how many customers are in the queue? Probably more efficient.

27 March, 2000 Queue Same data type structure, at most 15 of them Represent some of its properties by arrays e.g., number of customers in queue INTEGER, DIMENSION(15) : Ncustomers Ncustomers(1) is the number of customers in queue 1, Ncustomers(2) is the number of customers in queue 2, etc. Given nstations as user input for the number of check out stations ==> number of queues needed

27 March, 2000 Queue (Ncustomers) initialization: DO I=1,nstations Ncustomers(I) = 0 END DO Finding the line with least number of customers: shortestline=1 DO I=2, nstations IF (Ncustomers(I).LT. Ncustomers(shortestline)) & shortestline=I END DO

27 March, 2000 Add_to_Queue Use Subroutine to implement this subproblem SUBROUTINE Add_to_queue ! *** coding details later ! You will have to tell this subroutine which ! queue to add the customer (i.e., pass in a parameter ! shortestline) ! *** you will be provided with a subroutine to add ! customer to a queue Call AddTo (shortestline) ! Other book keeping activities Ncustomers(shortestline) = Ncustomers(shortestline)+1 END SUBROUTINE Add_to_queue

27 March, 2000 Checkout Customers Use Subroutine to implement this subproblem SUBROUTINE Check_out ! *** coding details later ! *** you will be provided with a subroutine to remove ! customer from a queue DO I = 1, nstations IF (Ncustomers(I).NE. 0.AND. Finished) THEN Call POP_queue (I) Ncustomers(I) = Ncustomers(I)-1 END IF END SUBROUTINE Check_out

27 March, 2000 Gather statistics Idle_time can be handled the same way as Ncustomers INTEGER, DIMENSION(15) : Ncustomers, Idle_time Idle_time(1) is the number of idle minutes in queue 1, Idle_time(2) is the number of idle minutes in queue 2, etc. Initialization DO I=1,nstation Idle_time(I) = 0 END DO Track Idle_time DO I=1,nstation IF (Ncustomers(I).EQ. 0) Idle_time(I) = Idle_time(I)+1 END DO