CSC 113 ASSIGNMENT ANSWERS (PROBLEM SOLVING)
CSC 113
USING THE FIRST THREE STAGES OF PROBLEM SOLVING,CALCULATE THE FOLLOWING AND LISTING OUT THE POSSIBLE PROBLEMS;
NOTE: biko (please) change the grammar/english/write-up a bit to avoid copied worked.
1. CALCULATE THE AVERAGE AGE OF ALL STUDENTS IN A CLASS
EXAMPLE 1
(1)
Understanding the problem: The problem is to find the average age of all
students in a class. We need to gather information about the ages of each
student in the class and find a way to calculate the average age.
- What
is the definition of "average age"?
- What
is the number of students in the class?
- What is the age range of students (e.g. 16-30)?
- Calculated the total number in the class.
- Collect
the age of each student in the class.
- Add
up all the ages to get the total age of all students.
- Divide the total age by the total number of students to get the average age.
(3)
Develop an algorithm: Based on the model we have formulated, we can develop an
algorithm for calculating the average age of all students in a class. Here is
an example:
Algorithm
for calculating the average age of all students in a class:
Step 1: Start.
Step 2: Collect the ages of all students in the class = age_1, age_2, ... age_n.
Step 3: Calculate the sum of all ages = age_1 + age_2 + ... + age_n.
Step
4: Calculate the total number of students in the class = N.
Step 5: Divide the sum of ages by the total number of students to get the average age = age_1 + age_2 + ... + age_n/N.
Step
6: Display the average age.
Step 7: Stop.
Possible problems that may arise during this stage include:
- Not having access to the ages of all students in the class.
- Some students might not be in school.
- Not knowing how to calculate the average age.
- Not being sure whether to include teachers or other staff members in the calculation.
- Using an incorrect formula for calculating the average age.
- Not accounting for missing or invalid data.
- Not properly collecting or inputting data.
- Not correctly carrying out the calculations or using the correct formula.
- Not properly displaying the output of the algorithm.
- Mtchew!! add your own.
EXAMPLE 2
(1) Understanding the problem: The problem is to determine the average age of all students in a class. We need to know the ages of each student in order to calculate the average.
- Not having access to the ages of all students in the class.
- Some students might not be in school.
- Not knowing how to calculate the average age.
- Not being sure whether to include teachers or other staff members in the calculation.
- Mtchew!! add your own.
(2) Develop or formulate a model: One possible model for calculating the average age of a group of numbers is to add up all the numbers and divide by the total count. In this case, we would add up the ages of all students and divide by the total number of students.
- Calculated the total number in the class.
- Collect the ages of all students in the class.
- Add up the ages of all students.
- Divide the sum by the total number of students in the class.
(3) Develop an algorithm:
Formal Algorithm:
Step 1: Start.
Step 2: Input the number of students in the class (N).
Step 3: Initialize a variable, total-age, to zero.
Step 4: For each student:
a. Input their age (A).
b. Add their age to total_age.
Step 5: Calculate the average age:
a. Divide total_age by N.
b. Assign the result to the variable, avg_age.
Step 6: Output the average age.
Step 7: Stop.
Informal Algorithm:
Step 1: Start.
Step 2: Count the number of students in the class.
Step 3: Set the total age to zero.
Step 4: For each student:
a. Get their age.
b. Add their age to the total age.
Step 5: Calculate the average age:
a. Divide the total age by the number of students.
b. Assign the result to the variable, average age.
Step 6: Display the average age.
Step 7: Stop.
Possible problems that may
arise during this process include:
- Input
errors: If the user inputs an invalid value for the number of students or
an invalid age, the algorithm may not work correctly.
- Data
inconsistency: If the data is incomplete or inconsistent, the algorithm
may produce incorrect results.
- Rounding
errors: If the average age is rounded to a certain number of decimal
places, there may be slight inaccuracies in the result.
2. CALCULATE THE AVERAGE GRADE OF ALL STUDENTS IN A CLASS
EXAMPLE
(1) Understanding the problem: The problem is to find the average grade of all students in a class. We need to gather information about the grades of each student in the class and find a way to calculate the average grade.
- What
is the definition of "average grade"?
- What
is the number of students in the class?
- What
is the grading system used (e.g. percentage, letter grades)?
- Mtchew!! add your own.
(2) Develop or formulate a model: One possible model for calculating the average age of the students in the class is;
- Calculated the total number in the class.
- Collect the grades of each student in the class.
- Add up all the grades to get the total grade of all students.
- Divide the total Grade by the total number of students to get the average grade.
(3) Develop an algorithm: Based on the model we have formulated, we can develop an algorithm for calculating the average grade of all students in a class. Here is an example:
Algorithm for calculating the average grade of all students in a class:
Step 1: Start.
Step 2: Retrieve the grades for all students in the class = grade_1, grade_2, ... grade_n.
Step 3: Calculate the sum of all grades = grade_1 + grade_2 + ... + grade_n.
Step 4: Count the number of students in the class = N.
Step 5: Calculate the average grade by dividing the sum of all grades by the number of students = grade_1 + grade_2 + ... + grade_n/N.
Step 6: Round the average grade to the nearest whole number
Step 7: Display the average grade to the user.
Step 8: Stop.
Possible problems that may arise during this stage include:
- Misinterpreting the problem statement or not fully understanding what is being asked.
- Incorrectly assuming the format of the input or output data.
- Overlooking constraints or limitations, such as using a specific programming language or tool.
- Using the wrong formula or method to calculate the average grade.
- Choosing inappropriate data structures for the input or output.
- Failing to consider special cases, such as empty lists or identical grades.
- Making errors in the steps or sub-steps of the algorithm.
- Overlooking edge cases or failing to test the algorithm on sample inputs.
- Not optimizing the algorithm for efficiency or accuracy.
- Mtchew!! add your own.
3. Calculate how a man, a lion, a goat, and a yam travelling, then come across a river with a single boat can cross-over, this boat can only contain a maximum of two items at a time i.e. the man and one other items or only the man, but if he leaves the lion with the goat the lion will eat up the goat and if he leaves the goat with the yam the goat will eat up the yam.
EXAMPLE
(1) Understanding the problem:
- They are four items (ownership): a man, a lion, a goat, and a yam.
- They need to cross a river using a boat.
- The boat can only carry a maximum of two items at a time.
- The man cannot leave the lion with the goat else the lion eat the goat.
- The man cannot leave the goat with the yam else the goat will eat the yam.
- How can all four items across the river safely with the boat.
- Maximum of two items
- Don't leave the lion with the goat.
- Don't leave the goat with the yam.
- Move all four items across the river.
- Transport all four items across the river safely.
Algorithm for calculating the possible boat rides that transport all items safely:
Step 1: Start.
Step 2: The man crosses the river with the goat.
Step 3: The man goes back alone.
Step 4:
Step 5: The man leaves the yam on the other bank and brings the goat back.
Step 6: The man leaves the goat on the original bank and takes the lion across.
Step 7:
Step 8: The man crosses the river with the goat.
Step 9: All items are safely crossed.
Step 10: Stop.
Possible problems that may arise during this stage include:
- Difficulty in determining the optimal sequence of boat rides.
- Time constraints.
- Safety concerns.
- Communication barriers.
- Difficulty in implementing the algorithm.
- Mtchew!! add your own.
This isn’t an assignment tho
ReplyDelete