Advanced Programming 15 Feb 2003. The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

Python Programming Chapter 5: Fruitful Functions Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
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.
Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace.
Intro to USACO Strategy
Programming Types of Testing.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Programming recap. Do you know these? LOW LEVEL 1 st generation: machine language (110011) 2 nd generation: assembly language (ADD, SUB) HIGH LEVEL 3.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Program Design and Development
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Hash Tables1 Part E Hash Tables  
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
Computer Science 1620 Programming & Problem Solving.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2010SCM-CityU1.
1 Gentle Introduction to Programming Session 2: Functions.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
Group practice in problem design and problem solving
CS1101: Programming Methodology Aaron Tan.
Python quick start guide
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
General Programming Introduction to Computing Science and Programming I.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
A First Book of ANSI C Fourth Edition
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
1 ENERGY 211 / CME 211 Lecture 13 October 20, 2008.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
By the end of this session you should be able to...
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Program Errors and Debugging Week 10, Thursday Lab.
Chapter 5 Repetition and Loop Statements J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei.
Working with arrays (we will use an array of double as example)
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
CSC 107 – Programming For Science. The Week’s Goal.
CS101 Computer Programming I Chapter 4 Extra Examples.
Introduction to Programming
2. Program Development Intro Programming in C++ Computer Science Dept Va Tech August 2001 ©2001 Barnette ND & McQuain WD 1 Top-Down Design:A solution method.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Reactive and Output-Only HKOI Training Team 2006 Liu Chi Man (cx) 11 Feb 2006.
HKOI Programming HKOI Training Team (Intermediate) Alan, Tam Siu Lung Unu, Tse Chi Yung.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
The Hashemite University Computer Engineering Department
Simple algorithms on an array - compute sum and min.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Introduction to Computing Science and Programming I
Testing and Debugging.
Some Basics for Problem Analysis and Solutions
Programming Funamental slides
Programming Funamental slides
Our Environment We will exercise on Microsoft Visual C++ v.6
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Unit 3: Variables in Java
Incremental Programming
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Advanced Programming 15 Feb 2003

The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing the program

Reading… Read the problem statements carefully Note the constraints Meaningful Range of variables Execution time limit Do not “guess” the meaning of the problem statements.

Thinking What is the ‘type’ of the problem? DP? Graph? Maths? Others? Have you solved a similar problem before? How do you solve the problem without computer? Can the problem be further divided into some easier sub-problems?

Thinking (cont.) Drawing diagrams may be useful (especially for DP and Graph problems) Is the problem too simple? If yes, look for tricks ;-) Is the algorithm correct? Any special cases? Have you coded it before? What were the difficulties you faced?

Thinking (cont.) Is the algorithm feasible? How to code it in PASCAL? Is it easy to code? What is the approximate execution time? How to store the data? Integer? LongInt? String? Array of char? Array? Linked-List? Are there enough memory to store the data?

Thinking (cont.) Are there any (simple) ways to improve Program execution time? Ease of coding?

Coding Pre-processing (e.g. find primes) Input Process Part 1, 2, …, N Output Save and compile your code frequently

Coding (cont.) Avoid long and complex expressions a:=2*(x2-x1); b:=2*(y2-y1); c:=x1*x1+y1*y1-x2*x2-y2*y2; d:=2*(x3-x1); e:=2*(y3-y1); f:=x1*x1+y1*y1-x3*x3-y3*y3; x:=(b*f-c*e)/(a*e-b*d); y:=(c*d-a*f)/(a*e-b*d); r:=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)); x:=(2*(y2-y1)*(x1*x1+y1*y1-x3*x3-y3*y3)- 2*(x1*x1+y1*y1-x2*x2-y2*y2)*(y3-y1)) /(4*(x2-x1)*(y3-y1)-4*(y2-y1)*(x3-x1)); y:=((x1*x1+y1*y1-x2*x2-y2*y2)*2*(x3-x1)- 2*(x2-x1)*(x1*x1+y1*y1-x3*x3-y3*y3)) /(4*(x2-x1)*(y3-y1)-4*(y2-y1)*(x3-x1)); r:=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));

Coding (cont.) Copy-and-paste Make sure the “source” is correct Update all variables Double checking required

Testing When to test your program? After completing the whole program? After writing each statement? After coding each part? After making changes to a part?

Testing (cont.) Print all important variables to screen Print messages Use debugger, inspect program behavior by running step-by-step

Testing (cont.) Sample Output “A problem has Sample Output for two reasons: 1. To make you understand what the correct output format is 2. To make you believe that your incorrect solution has solved the problem correctly ”

Testing (cont.) Hand-made Input Boundary Case “Large” Input Execution Time Overflow

Debugging Some short-cut keys F4 – Goto Cursor F7 – Trace into F8 – Step Over Ctrl-F7 – Add Watch Ctrl-F2 – Program Reset Ctrl-F8 – Add BreakPoint Alt-F5 – Screen Output

Finalizing Check I/O filename Check Output Format Trailing spaces? Correct source/executable name? Is the executable updated?

Demostration HKOI2003 Junior Q3 – Goldbach’s Conjecture Read the problem statements, and think about the algorithms now ;-)

Reading… Given an integer N, find two primes p 1,p 2 such that p 1 +p 2 =N p 1 ≤ p 2 Minimize (p 2 -p 1 ) Minimum N = 4 Maximum N = 10,000,000 (wow!) Can N be odd?

Thinking… Find two primes… if M mod p i = 0, where p i is a prime, then M is not prime. So….the first step is to find some small prime numbers (up to ) Then, write a function that uses these prime numbers to check for larger primes Use a for-loop to find two prime numbers such that their sum is N Feasible? Easy to write?