Write an algorithm that will input a grade of a student and determine wether the grade is "passed or "failed". The passing grade is 75. Print the name, grades and remarks of the student
Answers
Answer:
Explanation:
Using our steps in problem solving, a typical programming task can be divided into two phases:
1. Problem solving phase
This phase is where you produce an algorithm ( an ordered sequence of steps) that describe solution of problem
2. Implementation phase
This phase is where you implement the program in some programming language, in this case, Pascal.
Steps in Problem Solving
First produce a general algorithm
An algorithm as a set or list of instructions for carrying out some process step by step until it reaches the end of the algorithm.
A recipe in a cookbook is an excellent example of an algorithm. So, the recipe includes the ingredients and the method of cooking until you (hopefully) end up with a nice dish!
An example of an algorithm people use would be a recipe:
4 extra large eggs, beaten
1&1/2 C. stock
1/2 teaspoon salt
1 onion, minced
1 C. tuna flakes
1 t. soy sauce
1 Tablespoon oil
Mix all the ingredients, except the oil, in a deep bowl
Put 1" water in wide pot, then place deep bowl of batter inside the pot
Cover pot tightly and steam 15 min.
Heat oil very hot and pour over custard
Steam 5 more min.
Serves 4 people
Examples of Algorithms
Algorithms can be represented as:
Pseudocode - English like words that specify the sequence of steps in an algorithm
Flowcharts - a graphical tool using standard symbols to show the sequence of steps in an algorithm
So whether you use pseudocode or flowcharts to expand your algorithm, here is why algorithm are so useful:
Every algorithm must have an end, so there must be a set of steps followed in that algortihm to reach the end. For example, you follow the steps of the recipe to reach the end which is your dish that is ready to eat!
Every instruction should therefore be clear, with short instructions and easily understood
The instructions should be in a sequence from top to bottom. Using the example recipe above, you follow the instructions from step 1 to step 5.
To illustrate how we use algorithms (pseudocode and flowcharts) to a programming problem, let us use an example:
Example 1:
Write an algorithm to determine a student’s final grade and indicate whether the student has passed or failed. The final grade is calculated as the average of four marks.
Pseudocode
Remember, pseudocode is very similar to everyday English, which helps programmers develop their algorithms.
Refine the pseudocode successively to get step by step detailed statements that are easy to understand
Pseudocode: First try
List the tasks that need to be performed. You can also use an IPO chart to help you:
INPUT PROCESSING OUTPUT
M1, M2, M3, M4
calculate GRADE (average)
as (M1+M2+M3+M4)/4
Compare GRADE (less than 50)
Print Message FAIL or PASS
Input a set of 4 marks
Calculate their average by summing and dividing by 4
if average is below 50
Print “FAIL”
else
Print “PASS”
Detailed Pseudocode
Input M1,M2,M3,M4
GRADE = (M1+M2+M3+M4)/4
If (GRADE < 50)
Then
Print “FAIL”
Else
Print “PASS”
Endif
Flowcharts
Now we can also transform the pseudocode to a flowchart.
A flowchart is a graphical representation of the algorithm (again, a sequence of instructions that reach an end). Different symbols are used to draw each type of flowchart.