# [#10] – Planning the Computer Program – Questions If your teacher asked you to solve an arithmetic problem and you are not familiar with the steps involved in solving the problem, you will not be able to solve it. The same principle applies to writing computer programs also. A programmer cannot write the instructions for a computer to execute unless the programmer knows how to solve the program manually.

If you know the steps for solving a problem but while solving it, you forget to apply some of the steps or you apply the steps in the wrong sequence, you will get a wrong answer.

Similarly, while writing a computer program if the programmer leaves out some of the instructions for the computer or writes the instructions in the wrong sequence, the computer will produce a wrong answer.

Hence, to produce an effective computer program it is necessary to write every instruction in the correct sequence. However, the instruction sequence (logic) of a computer program may be very complex. Hence, to ensure that the instructions of a program are appropriate for the problem at hand and are in the correct sequence, we must plan the program before writing it.

Points To Remember:

• To ensure that the program instructions are appropriate for the problem at hand and in the correct sequence, programs must be planned before they are written.
• The term algorithm refers to the logic of a program. It is a step-by-step description of how to arrive at a solution to a given problem.
• An algorithm represented in the form of a programming language is a program. Hence, any program is an algorithm, although the reverse is not true.
• Other than programs, the use of flowcharts and pseudocodes is also common for representation of algorithms. They are frequently used by programmers for program planning.
• A flowchart is a pictorial representation of an algorithm. Programmers often use it as a program-planning tool for visually organizing a sequence of steps necessary to solve a problem using a computer.
• Pseudocode is a program-planning tool that allows programmers to plan program logic by writing program instructions in an ordinary natural language, such as English.
• Structured Programming is a more scientific approach to solving a programming problem by using only the three basic logic (control) structures namely, sequence logic, selection logic, and iteration (or looping) logic.
• Structured programming helps in producing programs that are easy to understand and maintain. It also helps in reducing program errors and the time spent in program testing.
• Sequence logic is used of performing instructions one after another in sequence.
• Selection logic is used for selecting the proper path out of two or more alternative paths in program logic. It uses three control structures called IF…THEN, IF….THEN….ELSE, and CASE.
• Iteration (or looping) logic is used for producing loops in program logic when one or more instructions may be executed several times depending on some condition. It uses two control structures called DO…WHILE and REPEAT…UNTIL.

List of Questions

1. Why it is advisable to plan the logic of a program before writing it?
2. What is an algorithm? What are the characteristics necessary for a sequence of instructions to qualify as an algorithm?
3. What are the commonly used ways to represent algorithms? Which of these can be used to solve the corresponding problem on a computer?
4. Any program is an algorithm, although the reverse is not true. Discuss this statement.
5. What is a program-planning tool? How it is useful? Name two commonly used program-planning tools.
6. What is a flowchart?
7. How does a flowchart help a programmer in program development?
8. Can a person draw a flowchart for a task if he/she does not know how to perform the task manually? Discuss.
9. What are the various basic symbols used in flowcharting? Draw their pictorial representation.
10. Describe the functions of the various basic flowcharting symbols.
11. What is a record? What is a trailer record?
12. What is a sentinel value? Discuss its use.
13. What is a process loop? What is an infinite loop?
14. Why it is necessary to avoid infinite loops in program design?
15. “A loop consists of a body, a test for exit condition, and a return provision.” Discuss this statement.
16. What is a generalized algorithm? Why should programs be general in nature?
17. Discuss the difference between loop control by counting and loop control by use of sentinel value. Which is preferable and why?
18. Illustrate the use of a counter to keep track of the number of times a loop has been executed.
19. Can there be more than one flowchart for a given problem? Write reasons for your answer.
20. What is the difference between a macro flowchart and a micro flowchart? Illustrate with an example.
21. What are the various guidelines to be followed while drawing a flowchart?
22. Discuss the advantages and limitations of flowcharting.
23. Why is proper documentation of a program necessary?
24. What are program bugs? What is debugging?
25. What is testing of a program? How it is done?
26. What is a pseudocode? Why it is so called? Write another name for pseudocode.
27. What are the three basic logic structures used in writing structured programs. Discuss the use of each.
28. What is structured programming? What are its main advantages?
29. Draw flowcharts for the two commonly used structures for selection logic.
30. What is the difference between IF…THEN and IF…THEN…ELSE structures?
31. Draw flowcharts for the two commonly used structures for iteration logic.
32. Both DO…WHILE and REPEAT…UNTIL are used for looping. Discuss the difference between the two structures.
33. What is the purpose of ENDIF and ENDDO statements?
34. What is indentation? Why it is used in writing pseudocodes?
35. Discuss the advantages and limitations of pseudocode.
36. Three numbers denoted by the variables A,B, and C are supplied as input data. Draw a flowchart for the logic to identify and print the largest one.
37. Draw a flowchart to print a list of all students over the age of 20 in a class. The input records contain the name and age of the students. Assume a sentinel value of 99 for the age field of the trailer record.
38. Draw a flowchart to print the name and age of the oldest student and the youngest student in a class. The input records contain the name and age of the students. Assume a sentinel value of 99 for the age field of the trailer record.
39. Draw a flowchart for an algorithm to read and print the first 20 records in a data set. Make sure that the processing stops after the twentieth record.
40. Input data of all employees of a company has been supplied. The first field of each input record contains the employee number (EmployeeNo). Assume that a trailer record having a sentinel value of 99999 for EmployeeNo terminates the input data of all the employees. Draw a flowchart for the logic to count and print the total number of employees.
41. For the problem of question 40, we want to count and print the number of only male employees in the age group of 25 to 30. Assume that the input records contain SexCode and Age fields to provide this information. Draw a flowchart for an algorithm to process this requirement.
42. A population survey has been carried out in a city and the collected information has been stored in a computer. Each record contains the name, address, sex, age, profession, etc., of one citizen. We want to print the details of all adults (aged 18 years or more) and finally the total number of adults. Assume a suitable sentinle value for any field in the trailer record, and draw a flowchart for an algorithm to process this requirement.
43. A set of examination papers graded with scores from 0 to 100 is to be searched to find how many of them are above 90. The total has to be printed. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for the trailer record.
44. Each paper in a set of examination papers includes a grade of A, B, C, D, or E. We want to have separate counts of the total number of papers having grade A and those having grade E. The total counts of both types have to be printed at the end. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for the trailer record.
45. A shopkeeper wants to have a general program for his personal computer that will prepare bills for each customer whenever he sells goods to them. His idea is that as soon as a customer purchases some goods from his shop, he will supply the description, unit price, and the quantity purchased for each item as input to the computer. He wants that with this information the computer should print each item along with its unit price, quantity purchased, and total price. Finally, the computer should also print the total cost of all the items purchased by the customer. Assuming a sentinel value of zero for the quantity purchased field in the trailer record, draw a flowchart for an algorithm to process this requirement.
46. An employer plans to pay bonus to each employee. Those earning Rs. 2000 or above are to be paid 10 percent of their salary and those earning less than Rs. 2000 are to be paid Rs. 200. The input records contain the employee number, name, and salary of the employees. The output to be printed should contain the employee number, name, and the amount of bonus to be paid to each employee. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for any of the fields in the trailer record.
47. An employee’s pay record includes hours worked and pay rate. The gross pay is to be calculated as hours worked times pay rate, and is to be printed for each employee. For the number of hours worked in excess of 40, overtime rate of 1.5 times the regular rate is to be paid. Draw a flowchart for an algorithm to process this requirement. Assume a suitable sentinel value for any of the input fields in the trailer record.
48. A data file contains a set of examination scores followed by a trailer record with the value of -1. Draw a flowchart for an algorithm to calculate and print the average of the scores.
49. The data file of Question 48 is expanded to include several sets of data each requiring calculation of its average. Each data set is followed by a trailer record with the value of -1, and the last data set is followed by a trailer record with a value of -2. Draw a flowchart for an algorithm to process this requirement.
50. Five numbers denoted by the variables A, B, C, D, and E are supplied as input. Draw a flowchart for an algorithm to print these numbers in descending order of magnitude.
51. Draw a flowchart for an algorithm to add up all the even numbers between 0 and 100 (both inclusive) and print the result.
52. Draw a flowchart for an algorithm to find out whether a given triangle ABC is isosceles. Assume that the angles of the triangle are supplied as input. Print the answer as yes or no.
53. Draw a flowchart for an algorithm to find out whether a given triangle ABC is a right-angled triangle. Assume that the sides of the triangle are supplied as input. Print the answer as yes or no.
54. Draw a flowchart for an algorithm to find out whether a given quadrilateral ABCD is a rectangle. Assume that all the four angles and four sides of the quadrilateral are supplied as input. Print the answer as yes or no.
55. Draw a flowchart for an algorithm to convert a number from base 10 to a new base using the division-remainder technique.
56. Draw a flowchart for an algorithm to convert a number form another base to base 10.
57. Write a pseudocode to solve the problem described in Question 37.
58. Write a pseudocode to solve the problem described in Question 38.
59. Write a pseudocode to solve the problem described in Question 41.
60. Write a pseudocode to solve the problem described in Question 44.
61. Write a pseudocode to solve the problem described in Question 45.
62. Write a pseudocode to solve the problem described in Question 46.
63. Write a pseudocode to solve the problem described in Question 47.
64. Write a pseudocode to solve the problem described in Question 51.
65. Write a pseudocode to solve the problem described in Question 52.