Click here to load reader

Programming fundamentals lecture 1 0f c

Embed Size (px)

Citation preview

  • 1. Lecture 1Introduction to Programming Tariq Ali, Room No 21

2. Outline A computer is a useful tool for solving a greatvariety of problems. To make a computer do anything (i.e. solve aproblem), we have to write a computer program. In a computer program we tell a computer, stepby step, exactly what want to do. 3. What is program A precise sequence of steps to solve a particular problem 4. Following each step mechanically, to accomplishthe end goal. The sequence of steps to be performed in orderto solve a problem by the computer is known asan algorithm. Flowchartis a graphical or symbolicrepresentation of an algorithm. It is thediagrammatic representation of the step-by-stepsolution to a given problem. 5. Concept of Languages Languages are used for Communication between Users and Computers. 6. Program Design Process Program 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. 7. Problem Solving 8. Problem Solving is easy if you followthese stepsUnderstand the problem 9. Step 1 Understand the problem Read the problem carefully. Find the important information. Write down the numbers. Identify what the problem wantsyou to solve. Ask if your answer is going tobe a larger or smaller numbercompared to what you already 10. Step 1 - Understand the ProblemRead the problem carefully.Luis 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? 11. Step 1 - Understand the ProblemFind the important information.Luis 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? 12. Step 1 - Understand the ProblemWrite down the numbers.Luis 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 =14 13. Step 1 - Understand the ProblemIdentify what the problem wantsyou to solve.Luis 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 = 31 1st week =142nd week = 14. Step 1 - Understand the ProblemAsk if your answer is going to be alarger or smaller number compared towhat 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. 15. Problem Solving is easy if you followthese stepsDecide howyoure going to solve the problem 16. Step 2 - Decide how youre going tosolve the problemChoose a methodUse a graphUse formulasWrite an equation Make a listFind a pattern Work backwardsUse reasoningDraw a pictureMake a tableAct it out 17. Step 2 - Decide how youre going to solve the problem Write your equation Total = 311st week =14 2nd week =Since I know both weeks total 31 I ? write 14 + s = 31 18. Step 2 - Decide how youre going to solve the problem Write your equationTotal = 311st week =14 2nd week =I can use the inverse operation to ?solve for s 14 + s = 31 31 14 = s 19. Problem Solving is easy if you followthese stepsSolve The Problem 20. Step 3 - Solve the problemTotal = 311st week =142nd week =? 3121 14 17 21. Problem Solving is easy if you followthese steps LookBack &Check 22. 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 = 31 1st week =14 23. 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= 31Total week? 1st week =142nd week = 17 24. 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 = 31 25. Step 4 - Look Back & CheckDid your new number work?Luis 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 = 31 Yes! 26. Write an equation to solve thisproblem.Jaylynn had $84.75 in her savings account. She made a deposit. Her new balance was $107.03. How much was her deposit?$84.75 + d = $107.03Inverse operation$107.03 $84.75 = d 27. Write an equation to solve thisproblem.Anthony has twice as many pokemon cards as Joshua. If Anthony has 124 cards, how many does Joshua have? 2 x d = 1242d = 124inverse operation d = 124/2 28. Write an equation to solve thisproblem.Vicki baked 90 cookies . If there are 15 cookies in each batch. How many batches did she bake? 15 x b = 9015b =90inverse operation b = 90/15 29. Write an equation to solve thisproblem.Navneet has 3 times as many CDs as Arlene. If Navneet has 36 CDs, how many does Arlene have? 3 x c = 363c = inverse operation c = 36/3 36 30. Write an equation to solve thisproblem.A square has a perimeter of 48 inches. What is the length of each side of the square.4 x s = 48 4s =48 operation s = 48/4 inverse 31. Write an equation to solve thisproblem.One year the city ambulance responded to emergencies on 293 days. How many days were there no emergencies? 293 + d = 365inverse operation d = 365 - 293 32. Credits Clipart from Broderbund ClickArt 125,000 Deluxe Image Pak Clipart from Corel Gallery by Corel Corp. 33. Program Design Phases Program Design Process Include: Problem Solving Phase Implementation Phase 34. Problem Solving Phase Problem solving is a skill which can be developedby following a well organized approach. Programming is also a problem solving activity. Programmer use software development methodto solve problems. 35. Software development activities The following steps can be followed to solve any kind of problem:1. Problem Identification2. Specify Requirements3. Analyze Problem4. Design algorithm and draw flowchart5. Write the program (Coding)6. Testing and Debug the program7. Implement the program8. Maintain and Update the program9. Document the program 36. Problem Identification At this stage the problem being solved isobserved carefully. Major area of concern are identified. Irrelevant information is filter out. 37. Specify Requirements This stage demands to make clear the usersrequirements so that a proper solution could besuggested. Requirements are documented here. 38. Analyze the problem Problem is decomposed into sub-problems. This lead to simple solution The technique is known is top down design (alsocalled divide and conquer rule). To approach the right solution we may ask certainquestions:- i. How many solutions are there to the given problem? ii.Which one is the best solution? iii. What are the input and output? iv.How can the bigger problem be divided into subproblems? 39. Design Algorithm and draw Flowchart Designing the algorithm requires to develop afinite list of steps to solve a problem. Once algorithm has been designed it should beverified through desk checking. Desk Checking is the process of carefully observing theworking of an algorithm, on the paper, for some test data. After designing the algorithm, the next step is todraw a flowchart. Flowchart in fact, maps the algorithm to a pictorialpresentation which helps in understanding theflow of control and data in algorithm. 40. Write the Program (Coding) Codinginvolves 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. 41. Test and Debug the program Testing requires evaluating the program to verifythat it works as desired. Debugging is the process of finding and removingerrors in the program. 42. Test and Debug the program There can be three types of errors:- Syntax Errors:- Occur when program violates one or moregrammatical rules of the programming language. Usually detected at compile time by the compiler. There can be many reasons such as typing wrongcommands or program statements. 43. Test and Debug the program Logical Errors:- Logical errors occur when program follow a wronglogic. The translator (compiler or interpreter) does notreport any error message for a logical errors. Can be identified by just looking at the wrong outputof the program. 44. Test and Debug the program Runtime Errors:- A runtime error occurs when the program directs thecomputer to perform an illegal operation such asdividing a number by zero. When runtime error occur, the computer will stopexecuting the program and may display a diagnosticmessage that helps in locating the error. 45. 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. 46. Maintain & Update the Program Program maintenance is ongoing process ofupgrading the program to accommodate newhardware and software. Regular maintenance is essential to thecontinued usefulness of a program. 47. Document the program Documentation is a detailed description of aprogramsalgorithm,design,codingmethod, testing and proper usage. A comprehensive documentation consists of thefollowing: 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). 48. l