Understanding Iterations and ImplementingModular ProgrammingObjectivesIn this lesson, you will learn to: Use the dry run t...
Understanding Iterations and ImplementingModular ProgrammingDry Run Helps you to do a logic check Understand the flow of c...
Understanding Iterations and ImplementingModular ProgrammingDry Run (Contd.)ExampleAll candidates have to take three tests...
Understanding Iterations and ImplementingModular ProgrammingVariables        Variable           Data Type   Variable Name ...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Select a Candidate                      Start    ...
Understanding Iterations and ImplementingModular ProgrammingDry Run Table    S.No.   nTest1   nTest2   nTest 3   nAverage ...
Understanding Iterations and ImplementingModular ProgrammingIteration An important characteristic of a computer is its abi...
Understanding Iterations and ImplementingModular ProgrammingExampleFlowchart to Display the Sum of Ten Numbers            ...
Understanding Iterations and ImplementingModular ProgrammingDry Run Table                S. No.   nNum   nSum   nCounter  ...
Understanding Iterations and ImplementingModular ProgrammingExampleYou have been assigned the responsibility of generating...
Understanding Iterations and ImplementingModular ProgrammingFlowchart Segment to Display EmployeeDetails of 25 People     ...
Understanding Iterations and ImplementingModular ProgrammingExampleLet us look at the same example of preparing the testpe...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate the Total Number ofCall Letters and Rej...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate the Total Number of CallLetters and Rej...
Understanding Iterations and ImplementingModular ProgrammingDry Run Table S. No.   nTest1   nTest2   nTest2   nAverage   O...
Understanding Iterations and ImplementingModular ProgrammingModular Approach to Programming A program needs to be amended ...
Understanding Iterations and ImplementingModular ProgrammingModular Approach to Programming (Contd.) Long, continuous prog...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Show Modular Programming                Start    ...
Understanding Iterations and ImplementingModular ProgrammingExampleAccept the test scores for ten students and display the...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate Average Marks of TenStudents           ...
Understanding Iterations and ImplementingModular ProgrammingExampleThe total expenditure on salaries for the month needs t...
Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate Total Monthly Expenditureon Salaries   ...
Understanding Iterations and ImplementingModular ProgrammingExampleDry Run          S. No.   nSalary   nTotSalary   Output...
Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.1Draw a flowchart to print the product o...
Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.2Draw a flowchart to accept 50 numbers a...
Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.3Draw a flowchart to display the highest...
Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.4        Draw a flowchart that accepts i...
Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.5How many names will the following flowc...
Understanding Iterations and ImplementingModular ProgrammingSummaryIn this lesson, you learned that: The concept of dry ru...
Understanding Iterations and ImplementingModular ProgrammingSummary (Contd.)        ® Variable   loops where the number of...
Upcoming SlideShare
Loading in …5
×

Sem1 plt xp_03

1,000 views

Published on

Old Slides

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,000
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
38
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sem1 plt xp_03

  1. 1. Understanding Iterations and ImplementingModular ProgrammingObjectivesIn this lesson, you will learn to: Use the dry run table Identify repetitive processes Represent complex conditions and iterations by using flowcharts Break down a problem into modules©NIIT PLT/Lesson 3/Slide 1 of 30
  2. 2. Understanding Iterations and ImplementingModular ProgrammingDry Run Helps you to do a logic check Understand the flow of control in a flowchart Evaluate the output of the program with a set of sample values Provides a step by step evaluation of values in the variables of the program©NIIT PLT/Lesson 3/Slide 2 of 30
  3. 3. Understanding Iterations and ImplementingModular ProgrammingDry Run (Contd.)ExampleAll candidates have to take three tests. A candidate isselected for the interview round based on the scores ofall the three tests. The individual score in each test hasto be greater than 75 and the average score across thethree tests should be a minimum of 80. The call letter forthe interview is to be sent to candidates who have beenselected and a rejection letter is to be sent to the rest.Represent the logic for the above process by using aflowchart.©NIIT PLT/Lesson 3/Slide 3 of 30
  4. 4. Understanding Iterations and ImplementingModular ProgrammingVariables Variable Data Type Variable Name Employee Name character cName Employee Address character cAddress Telephone Number character cTelno Counter numeric nCounter©NIIT PLT/Lesson 3/Slide 4 of 30
  5. 5. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Select a Candidate Start Declare Variables Accept Variables and Calculate nAverage Is nAverage= 80 AND No Display “ Rejection nTest1 75 AND letter to be sent” nTest2 75 AND nTest3 75 ? Yes Display “ Interview call letter to be sent” Stop©NIIT PLT/Lesson 3/Slide 5 of 30
  6. 6. Understanding Iterations and ImplementingModular ProgrammingDry Run Table S.No. nTest1 nTest2 nTest 3 nAverage Output 1. 95 90 88 91 Interview call letter to be sent. 2. 80 77 83 80 Interview call letter to be sent. 3. 90 92 74 85.33 Rejection letter to be sent. 4. 76 76 76 76 Rejection letter to be sent.©NIIT PLT/Lesson 3/Slide 6 of 30
  7. 7. Understanding Iterations and ImplementingModular ProgrammingIteration An important characteristic of a computer is its ability to execute a series of instructions repeatedly A loop is a sequence of instructions that will be repeated more than once A loop performs steps in a specified sequence There are two types of loops: Fixed loops where the number of repetitions is known Variable loops where the number of repetitions is not known©NIIT PLT/Lesson 3/Slide 7 of 30
  8. 8. Understanding Iterations and ImplementingModular ProgrammingExampleFlowchart to Display the Sum of Ten Numbers Start numeric nNum, nSum, nCounter nCounter=0 nSum=0 Accept nNum nSum=nSum+nNum nCounter=nCounter+1 Yes Is No nCounter10 ? Display nSum Stop©NIIT PLT/Lesson 3/Slide 8 of 30
  9. 9. Understanding Iterations and ImplementingModular ProgrammingDry Run Table S. No. nNum nSum nCounter Output 1. - 0 0 2. 5 5 1 3. 12 17 2 4. 7 24 3 5. 6 30 4 6. 2 32 5 7. 10 42 6 8. 8 50 7 9. 3 53 8 10. 16 69 9 11. 4 73 10 73©NIIT PLT/Lesson 3/Slide 9 of 30
  10. 10. Understanding Iterations and ImplementingModular ProgrammingExampleYou have been assigned the responsibility of generatingan address list of all the people working in your office.For each person, you will need to accept the name,address, and the telephone number and print a listcontaining the collated details.©NIIT PLT/Lesson 3/Slide 10 of 30
  11. 11. Understanding Iterations and ImplementingModular ProgrammingFlowchart Segment to Display EmployeeDetails of 25 People nCounter = 1 Is No nCounter=25? Yes Stop Accept cName Accept cAddress Accept cTelno Display cName, cAddress, cTelno nCounter=nCounter+ 1©NIIT PLT/Lesson 3/Slide 11 of 30
  12. 12. Understanding Iterations and ImplementingModular ProgrammingExampleLet us look at the same example of preparing the testperformance report in the decision-making section again.Now, apart from finding out whether a candidate has tobe sent a call letter or a rejection letter, we also have tocalculate the number of candidates who have been sentinterview call letters and the number of candidates whohave been sent rejection letters, using a flowchart.©NIIT PLT/Lesson 3/Slide 12 of 30
  13. 13. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate the Total Number ofCall Letters and Rejection Letters Sent Start Variable Declaration Accept Values Is nAverage =80 AND No nTest1 75 AND nTotReject=nTotReject+1 nTest2 75 AND nTest3 75 ? Yes nTotSelect=nTotSelect+1 A B©NIIT PLT/Lesson 3/Slide 13 of 30
  14. 14. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate the Total Number of CallLetters and Rejection Letters Sent (Contd.) B A Display “Any more candidates (Y/N)? ” Accept cChoice Is No cChoice = “Y”? Yes Display nTotSelect Display nTotReject Stop©NIIT PLT/Lesson 3/Slide 14 of 30
  15. 15. Understanding Iterations and ImplementingModular ProgrammingDry Run Table S. No. nTest1 nTest2 nTest2 nAverage Output 1. 95 90 88 91 nTotSelect is incremented by 1. 2. 80 77 83 80 nTotSelect is incremented by 1. 3. 90 92 74 85.33 nTotReject is incremented by 1. 4. 76 76 76 76 nTotReject is incremented by 1.©NIIT PLT/Lesson 3/Slide 15 of 30
  16. 16. Understanding Iterations and ImplementingModular ProgrammingModular Approach to Programming A program needs to be amended periodically to respond to changing conditions or requirements This encouraged programmers to adopt a more disciplined approach to program writing. The techniques that were adopted are known as structured programming techniques. Structured programming includes features that are designed not only to solve the problem at hand but also to make the logic clear to someone reading the program©NIIT PLT/Lesson 3/Slide 16 of 30
  17. 17. Understanding Iterations and ImplementingModular ProgrammingModular Approach to Programming (Contd.) Long, continuous programs can be broken up into a series of individual modules that are related to each other in a specified manner. Main Program Module1 Module2 Module3©NIIT PLT/Lesson 3/Slide 17 of 30
  18. 18. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Show Modular Programming Start numeric nNum1, Add nNum2, nNum3, nSum nSum=nNum1 + nNum2 Accept nNum1, + nNum3 nNum2, nNum3 Return Add Display nSum Stop©NIIT PLT/Lesson 3/Slide 18 of 30
  19. 19. Understanding Iterations and ImplementingModular ProgrammingExampleAccept the test scores for ten students and display theirindividual averages. The scores of the students cannotbe negative.The table shows the variables used in the flowchart. Variable Data Type Variable Name Student Name character cStudentName Score of Test 1 numeric nTest1 Score of Test 2 numeric nTest2 Score of Test 3 numeric nTest3 Average of Test Scores numeric nAverage©NIIT PLT/Lesson 3/Slide 19 of 30
  20. 20. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate Average Marks of TenStudents Accept Accept cStudentName Accept Average Accept nTest1 Average nAverage=(nTest1+nTest2 Accept nTest2 +nTest3) / 3 Display cStudentName, Accept nTest3 Return nAverage Is nTest1=0 AND Yes nTest2=0 AND nTest3=0 ? Return No Display “Test score cannot be less than zero”©NIIT PLT/Lesson 3/Slide 20 of 30
  21. 21. Understanding Iterations and ImplementingModular ProgrammingExampleThe total expenditure on salaries for the month needs tobe calculated. As per company policy an employeereceives a minimum of $500. Depict the logic forautomating the task by using flowcharts.Program Variables to be used are: Variable Data Type Variable Name Employee Code character cEmpCode Employee salary numeric nSalary Total salary numeric nTotSalary Choice character cChoice©NIIT PLT/Lesson 3/Slide 21 of 30
  22. 22. Understanding Iterations and ImplementingModular ProgrammingFlowchart to Calculate Total Monthly Expenditureon Salaries Accept Is No SummationcChoice = “Y” ? Accept nSalary Yes nTotSalary=nTotSalary+nSalary Is Yes Accept nSalary =500 ? Return Return No Summation Display”Salary cannot be less than $500”©NIIT PLT/Lesson 3/Slide 22 of 30
  23. 23. Understanding Iterations and ImplementingModular ProgrammingExampleDry Run S. No. nSalary nTotSalary Output 1. - 0 2. 4500 4500 3. 5500 10000 4. 3400 13400 5. 5600 19000 6. 3000 22000 7. 5000 27000 8. 450 27000 Salary cannot be less than $500 9. 9000 36000 10. 8900 44900 11. 4500 49400 49400©NIIT PLT/Lesson 3/Slide 23 of 30
  24. 24. Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.1Draw a flowchart to print the product of the first 10 evennumbers.©NIIT PLT/Lesson 3/Slide 24 of 30
  25. 25. Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.2Draw a flowchart to accept 50 numbers and also displaythe total number of odd and even numbers.©NIIT PLT/Lesson 3/Slide 25 of 30
  26. 26. Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.3Draw a flowchart to display the highest of any 10numbers entered.©NIIT PLT/Lesson 3/Slide 26 of 30
  27. 27. Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.4 Draw a flowchart that accepts input from a user and displays the result, depending on whether the user wishes to multiply or divide the numbers provided as input. The Multiply module of the program can multiply maximum of three numbers. The Divide module of the program should check that the denominator should not be zero.©NIIT PLT/Lesson 3/Slide 27 of 30
  28. 28. Understanding Iterations and ImplementingModular ProgrammingProblem Statement 3.P.5How many names will the following flowchart print? nCtr = 0 Accept cName Display cName No Is nCtr =10 ? Yes Stop©NIIT PLT/Lesson 3/Slide 28 of 30
  29. 29. Understanding Iterations and ImplementingModular ProgrammingSummaryIn this lesson, you learned that: The concept of dry run will help you perform a logic check and understand the flow of control in a flowchart. A loop is a sequence of instructions that will be repeated more than once A loop performs steps in a specified sequence There are two types of loops: ® Fixed loops where the number of repetitions is known©NIIT PLT/Lesson 3/Slide 29 of 30
  30. 30. Understanding Iterations and ImplementingModular ProgrammingSummary (Contd.) ® Variable loops where the number of repetitions is not known Statements within a loop will be executed repeatedly until the condition becomes false The structured programming technique is a disciplined approach to program writing. A large program can be divided into several modules, where each module performs a specific task. A module is also called a procedure. A procedure or a module is invoked from the main program and the control is returned from the procedure to the main program by using the return statement©NIIT PLT/Lesson 3/Slide 30 of 30

×