03 iec t1_s1_plt_session_03

29
Installing Windows XP Professional Using Attended Installation Slide 1 of 29 Session 3 Ver. 1.0 Programming Logic and Techniques In this session, you will learn to: Use the dry run table Identify repetitive processes Identify modular approach to programming Objectives

Upload: niit-care

Post on 22-May-2015

1.382 views

Category:

Technology


0 download

DESCRIPTION

NEW Slides

TRANSCRIPT

Page 1: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 1 of 29Session 3Ver. 1.0

Programming Logic and Techniques

In this session, you will learn to:Use the dry run table

Identify repetitive processes

Identify modular approach to programming

Objectives

Page 2: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 2 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Helps you 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

Using Dry Run

Page 3: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 3 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:All candidates have to take three tests. A candidate is selected for the interview round based on the scores of all the three tests. The individual score in each test has to be greater than 75 and the average score across the three tests should be a minimum of 80. The call letter for the interview is to be sent to candidates who have been selected and a rejection letter is to be sent to the rest. Represent the logic for the above process by using a flowchart.

Using Dry Run (Contd.)

Page 4: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 4 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Flowchart to select a candidate

Using Dry Run (Contd.)

Start

Stop

Declare Variables

Accept Values and Calculate nAverage

IsnAverage>= 80 AND nTest1 > 75 AND nTest2 > 75 AND nTest3 > 75 ?

No

Yes

Display “Interview call letter to be sent”

Display “ Rejectionletter to be sent”

Page 5: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 5 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Dry 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

Using Dry Run (Contd.)

Page 6: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 6 of 29Session 3Ver. 1.0

Programming Logic and Techniques

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

Iteration

Page 7: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 7 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:Flowchart to display the sum of ten numbers

Iteration (Contd.)

Start

Stop

numeric nNum, nSum, nCounter

Accept nNum

Is nCounter<10 ?

NoYes

nCounter=0 nSum=0

nSum=nSum+nNum

nCounter=nCounter+1

Display nSum

Page 8: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 8 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Dry Run Table:

Iteration (Contd.)

S. No. nNum nSum nCounter Output

0. - 0 0

1. 5 5 1

2. 12 17 2

3. 7 24 3

4. 6 30 4

5. 2 32 5

6. 10 42 6

7. 8 50 7

8. 3 53 8

9. 16 69 9

10. 4 73 10 73

Page 9: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 9 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:You have been assigned the responsibility of generating an 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 list containing the collated details.

Iteration (Contd.)

Page 10: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 10 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Flowchart segment to display employee details of 25 people

Iteration (Contd.)

No

Stop

nCounter = 1

Accept cName

Is nCounter<=25?

Yes

nCounter=nCounter+1

Display cName, cAddress, cTelno

Accept cAddress

Accept cTelno

Page 11: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 11 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:Let us look at the same example of preparing the test performance report in the decision-making section again. Now, apart from finding out whether a candidate has to be sent a call letter or a rejection letter, we also have to calculate the number of candidates who have been sent interview call letters and the number of candidates who have been sent rejection letters, using a flowchart.

Iteration (Contd.)

Page 12: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 12 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Process

Flowchart to calculate the total number of call letters and rejection letters sent

Iteration (Contd.)

Start

Variable Declaration

Accept Values

IsnAverage >=80 AND

nTest1 > 75 ANDnTest2 > 75 AND

nTest3 > 75 ?

No

Yes

nTotReject=nTotReject+1

nTotSelect=nTotSelect+1

A B

Page 13: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 13 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Flowchart to calculate the total number of call letters and rejection letters sent (Contd.)

Iteration (Contd.)

Is cChoice = “Y”?

Yes

No

Display nTotSelect Display nTotReject

A B

Accept cChoice

Display “Any more candidates (Y/N)? ”

Stop

Page 14: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 14 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Iteration (Contd.)

S. No. nTest1 nTest2 nTest3 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.

Dry Run Table:

Page 15: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 15 of 29Session 3Ver. 1.0

Programming Logic and Techniques

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 modularor structured programming techniques.

Modular 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.

Identifying Modular Approach to Programming

Page 16: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 16 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Long, continuous programs can be broken up into a series of individual modules that are related to each other in a specified manner.

Identifying Modular Approach to Programming (Contd.)

Module1 Module2 Module3

Main Program

Page 17: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 17 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Add

Return

Add

Start

Stop

Display nSum

numeric nNum1,nNum2, nNum3, nSum

nSum=nNum1 + nNum2 + nNum3Accept nNum1,

nNum2, nNum3

Example:Flowchart to show modular programming

Identifying Modular Approach to Programming (Contd.)

Page 18: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 18 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:Accept the test scores for 10 students and display their individual averages. The scores of the students cannot be negative.

The table shows the variables used in the flowchart.

Identifying Modular Approach to Programming (Contd.)

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

Page 19: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 19 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Flowchart to calculate average marks of 10 students

Return

Accept cStudentName

Average

nAverage=(nTest1+nTest2 +nTest3) / 3

Return

Accept

Accept nTest1

Accept nTest2

Accept nTest3

Display “Test score cannot be less than zero”

IsnTest1>=0 ANDnTest2>=0 AND

nTest3>=0 ?

No

Yes

Average

Display cStudentName, nAverage

Accept

Identifying Modular Approach to Programming (Contd.)

Page 20: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 20 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Example:The total expenditure on salaries for the month needs to be calculated. As per company policy an employee receives a minimum of $500. Depict the logic for automating the task by using flowcharts.

The table shows the variables used in the flowchart.

Variable Data Type Variable Name

Employee code character cEmpCode

Employee salary numeric nSalary

Total salary numeric nTotSalary

Choice character cChoice

Identifying Modular Approach to Programming (Contd.)

Page 21: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 21 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Flowchart to calculate total monthly expenditure on salaries

Summation

Accept

IscChoice = “Y” ?

No

Yes

Display ”Salary cannotbe less than $500”

Accept nSalary

Accept

IsnSalary >=500 ?

Yes

NoReturn

nTotSalary=nTotSalary+nSalary

Summation

Return

Identifying Modular Approach to Programming (Contd.)

Page 22: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 22 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Identifying Modular Approach to Programming (Contd.)

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

Dry Run Table:

Page 23: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 23 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Exercises

Page 24: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 24 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Draw a flowchart to print the product of the first 10 even numbers.

Exercise 1

Page 25: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 25 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Draw a flowchart to accept 50 numbers and also display the total number of odd and even numbers.

Exercise 2

Page 26: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 26 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Exercise 3

Draw a flowchart to display the highest of any 10 numbers entered.

Page 27: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 27 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Exercise 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.

Page 28: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 28 of 29Session 3Ver. 1.0

Programming Logic and Techniques

Summary

In this session, 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

Variable loops where the number of repetitions is not known

Page 29: 03 iec t1_s1_plt_session_03

Installing Windows XP Professional Using Attended Installation

Slide 29 of 29Session 3Ver. 1.0

Programming Logic and Techniques

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.

Summary (Contd.)