Programming fundamentals 2

Post on 12-Jan-2017

119 views 2 download

transcript

Lecture 1

Programming FundamentalsTutor: Bilal Janjooa Assistant Professor The University of Lahore MS Telecom. Eng. From The University of Sunderland UK1Bilal Janjooa bilal.janjooa@yahoo.co.uk

1

Programming FundamentalsLecture No. 22Bilal Janjooa bilal.janjooa@yahoo.co.uk

OutlineA computer is a useful tool for solving a great variety of problems.To make a computer do anything (i.e. solve a problem), we have to write a computer program.In a computer program we tell a computer, step by step, exactly what want to do.3Bilal Janjooa bilal.janjooa@yahoo.co.uk

What is programA precise sequence of steps tosolve a particular problem

4Bilal Janjooa bilal.janjooa@yahoo.co.uk

Following each step mechanically, to accomplish the end goal.The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.Flowchart is a graphical or symbolic representation of an algorithm. It is the diagrammatic representation of the step-by-step solution to a given problem.

5Bilal Janjooa bilal.janjooa@yahoo.co.uk

Concept of Languages

Languages are used for Communication between Users and Computers.6Bilal Janjooa bilal.janjooa@yahoo.co.uk

Program Design ProcessProgram Design consists of the steps a programmer should do before they start coding the program in a specific language. Proper program design helps other programmers to maintain the program in the future.7Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving

8Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving is easy if you follow these steps

Understandtheproblem9Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 Understand the problemRead the problem carefully.Find the important information.Write down the numbers.Identify what the problem wants you to solve.Ask if your answer is going to be a larger or smaller number compared to what you already know.10Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 - Understand the ProblemRead the problem carefully.Ahmed earned 14 Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?11Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 - Understand the ProblemFind the important information.Ahmed earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

12Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 - Understand the ProblemWrite down the numbers.Ahmed earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

Total = 311st week =1413Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 - Understand the ProblemIdentify what the problem wants you to solve.Ahmed earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

Total = 311st week =142nd week = ?14Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 1 - Understand the ProblemAsk if your answer is going to be a larger or smaller number compared to what you already know.Total = 311st week =142nd week = ?It will be smaller than the total but may or may not be smaller than the first week.15Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving is easy if you follow these steps

Decide howyoure going to solve theproblem 16Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 2 - Decide how youre going to solve the problemChoose a methodUse a graphUse formulasWrite an equationMake a listFind a patternWork backwardsUse reasoningDraw a pictureMake a tableAct it out

17Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 2 - Decide how youre going to solve the problemWrite your equationSince I know both weeks total 31 I write14 + s = 31Total = 311st week =142nd week = ?18Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 2 - Decide how youre going to solve the problemWrite your equationI can use the inverse operation to solve for s14 + s = 31 31 14 = sTotal = 311st week =142nd week = ?19Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving is easy if you follow these steps

Solve TheProblem 20Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 3 - Solve the problem 3 1 1 4Total = 311st week =142nd week = ?

217121Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving is easy if you follow these steps

LookBack &Check 22Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 4 - Look Back & CheckReread the problemLuis earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

Total = 311st week =1423Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 4 - Look Back & CheckSubstitute your new numberLuis earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

Total = 311st week =142nd week = 1724Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 4 - Look Back & CheckSubstitute your new numberLuis earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

14 + 17 = 3125Bilal Janjooa bilal.janjooa@yahoo.co.uk

Step 4 - Look Back & CheckDid your new number work?Ahmed earned 14 Accelerated Reading points the first week of November. At the end of the following week he had a total of 31 points. How many points did he earn the second week?

14 + 17 = 31Yes!26Bilal Janjooa bilal.janjooa@yahoo.co.uk

Program Design Phases

Program Design Process Include:Problem Solving PhaseImplementation Phase27Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem Solving PhaseProblem solving is a skill which can be developed by following a well organized approach.Programming is also a problem solving activity.Programmer use software development method to solve problems.28Bilal Janjooa bilal.janjooa@yahoo.co.uk

Software development activitiesThe following steps can be followed to solve any kind of problem:

Problem IdentificationSpecify RequirementsAnalyze ProblemDesign algorithm and draw flowchartWrite the program (Coding)Testing and Debug the programImplement the programMaintain and Update the programDocument the program29Bilal Janjooa bilal.janjooa@yahoo.co.uk

Problem IdentificationAt this stage the problem being solved is observed carefully.Major area of concern are identified.Irrelevant information is filter out.30Bilal Janjooa bilal.janjooa@yahoo.co.uk

Specify RequirementsThis stage demands to make clear the users requirements so that a proper solution could be suggested.Requirements are documented here. 31Bilal Janjooa bilal.janjooa@yahoo.co.uk

Analyze the problemProblem is decomposed into sub-problems.This lead to simple solutionThe technique is known is top down design (also called divide and conquer(overcome) rule ).To approach the right solution we may ask certain questions:-How many solutions are there to the given problem?Which one is the best solution?What are the input and output?How can the bigger problem be divided into sub problems?32Bilal Janjooa bilal.janjooa@yahoo.co.uk

Design Algorithm and draw FlowchartDesigning the algorithm requires to develop a finite list of steps to solve a problem.Once algorithm has been designed it should be verified through desk checking.Desk Checking is the process of carefully observing the working of an algorithm, on the paper, for some test data.After designing the algorithm, the next step is to draw a flowchart.Flowchart in fact, maps the algorithm to a pictorial presentation which helps in understanding the flow of control and data in algorithm. 33Bilal Janjooa bilal.janjooa@yahoo.co.uk

Write the Program (Coding)Coding involves the conversion of an algorithm to a program, written in any programming language.

The programmer must know the syntax of the programming language chosen.

The grammatical rules of a programming language to write programs are referred to as syntax of that programming language.34Bilal Janjooa bilal.janjooa@yahoo.co.uk

Test and Debug the program

Testing requires evaluating the program to verify that it works as desired.Debugging is the process of finding and removing errors in the program.35Bilal Janjooa bilal.janjooa@yahoo.co.uk

Test and Debug the programThere can be three types of errors:-Syntax Errors:- Occur when program violates one or more grammatical rules of the programming language.Usually detected at compile time by the compiler.There can be many reasons such as typing wrong commands or program statements.36Bilal Janjooa bilal.janjooa@yahoo.co.uk

Test and Debug the programLogical Errors:-Logical errors occur when program follow a wrong logic.The translator (compiler or interpreter) does not report any error message for a logical errors.Can be identified by just looking at the wrong output of the program.37Bilal Janjooa bilal.janjooa@yahoo.co.uk

Test and Debug the programRuntime Errors:-A runtime error occurs when the program directs the computer to perform an illegal operation such as dividing a number by zero.When runtime error occur, the computer will stop executing the program and may display a diagnostic message that helps in locating the error. 38Bilal Janjooa bilal.janjooa@yahoo.co.uk

Implement the Program (deployment)

Once the program has been tested thoroughly, it must be installed or put into operation at the site where it will be used. 39Bilal Janjooa bilal.janjooa@yahoo.co.uk

Maintain & Update the Program

Program maintenance is ongoing process of upgrading the program to accommodate new hardware and software.Regular maintenance is essential to the continued usefulness of a program.

40Bilal Janjooa bilal.janjooa@yahoo.co.uk

Document the programDocumentation is a detailed description of a programs algorithm, design, coding method, testing and proper usage.A comprehensive documentation consists of the following:A description of what the program is supposed to do.A description of the problem solution (the algorithm).A description of the program design including any aids used (flowcharts, algorithms etc.).A description of the programs testing process, including test data used and result obtained.A description of all correctness modification and updates made to the program.A user manual (user guide).41Bilal Janjooa bilal.janjooa@yahoo.co.uk

Thank You

42Bilal Janjooa bilal.janjooa@yahoo.co.uk