Question #3:
Write the logical steps (pseudo-code) to print the average age of allstudents in a class (class strength is not known). The input is name and age of eachstudent. To continue for the next input ask the user, answered as either yes or no. Draw aflowchart on the logical steps deduced.STEP 1: Initialize total_students by 0, total_age by 0, avg_age by 0, age by 0, name by““, continue by ‘y’STEP 2: Print ‘Do you want to enter the data of students, please enter
y
for yes and
n
for no’STEP 3: Read value in continueSTEP 4: Check;(b)if (continue is equal to ‘
y
’) theni)Move to Step 5(b)otherwiseii)Move to StepSTEP 5: Print ‘Enter name and age of student’STEP 6: Read value in name, ageSTEP 7: Check;(a)if (age are less than 0) theni)Move to Step 5(b)otherwiseii)Move to Step 8STEP 8: Add 1 in total_studentsSTEP 9: Add age in total ageSTEP 10: Move to Step 2STEP 11: Divide tota_age by total_students and assign the result in avg_ageSTEP 12: Print ‘Average age of students who are:’ total_students ‘ in strength is:’,avg_ageSTEP 13: Stop
Question #4:
Draw a flowchart for the logical steps (pseudo-code) to find out whether agiven triangle ABC is a right-angle triangle. Assume that the sides of the triangle aresupplied as input. Print the answer as ‘yes’ or ‘no’.STEP 1: Initialize side1, side2, side3 by 0 and sq_side1, sq_side2, sq_side3 by 0STEP 2: Print ‘Enter the three sides’STEP 3: Read value in side1, side 2, side3STEP 4: Perform square operation on three sides:(a)Perform multiplication of side1 with itself and assign the result in sq_side1(b)Perform multiplication of side2 with itself and assign the result in sq_side2(c)Perform multiplication of side3 with itself and assign the result in sq_side3STEP 5: Check;(a)if (sq_side1 is equal to sum of sq_side2 and sq_side3) theni)Move to Step 6(i)(b)otherwise check;
Leave a Comment