Tuesday, September 3, 2013

TOPIC 2: LOGIC BUILDING USING PSEUDO CODE

2.2 Selection Control Structures


Assignment 2.2.1: Pseudo code - Selectional pattern (1)


Objective: Write pseudo code for selectional pattern problems

Problem Description: The problem given in Assignment 2.1.2 should be extended to check whether the Number of Hours accepted from the user is less than or equal to 0. If so an appropriate error message should be displayed.

The problem given in assignment 2.1.2 is here.
The pseudo-code with required changes can be written again as :


Calculate-Gross-Pay

1. input No_of_Hours, Pay_Rate

2. if  No_of_Hours < = 0 then
3. Display " The Number of hours are invalid."
4. else
5. Gross_Pay = No_of_Hours * Pay_Rate
6. Display "Gross Pay is : ", Gross_Pay
7. end



Assignment 2.2.2: Selectional pattern (2)

Objective: To develop pseudo code writing skills for a given problem using certain logic.

Case study: An institution offers several programs. Each program has several courses. There 
are students who have opted for these courses. There are Educators who offer these courses.



Problem 1:
At a given point of time we need to allocate a course to an educator for a given
period. Before allocating a course to an educator the following conditions are to be checked.
1. Enough number of students have registered for the course
AND
2. The course is added into the educator’s skill set
AND
3. Educator’s calendar is free for the given period
AND
4. Educator is not on leave for the given period
And
5. Educator has not yet completed his delivery targets Or There is no other alternative

SOLUTION :

COURSE_ALLOCATION
1. input course
2. input num_of_students
3. input educator's_skill_set, spare_time, is_on_leave, delivered_targets, allocation
4. if ( (num_of_students > min_number_students) && (educator's_skill_set = course) && (spare_time = true ) && (is_on_leave = false) && (delivered_targets = true ) ) then
5. set allocation = true
6. end if
7. display "Course is allocated. "
8. end


Problem 2: For a student, following is the course qualifying criteria.
1. Student has registered for the course
2. Attended at-least 80% of the classes
or attended at-least 60% of the classes and submitted medically unfit certificate
3. Submitted all the assignments
4. Completed project
5. Scored 80% marks in the test or the retest

QUALIFYING_STUDENT
1. input classes_attended, min_score
2. input course_reg, medical_certificate, submitted_assignments, completed_project
3. if ( ( course_reg = true ) &&(classes_attended >= 80 || (classes_attended >= 60 && medical_certificate = true ) ) && (submitted_assignments = true ) && (completed_project = true) && ( min_score >= 80)) then
4. set course_qualification = true
5. end if
6. display "Congratulations, course has been qualified. "
7. end 



Assignment 2.2.3: Selectional pattern (3)


Objective: To use the problem solving techniques learnt so far in a real life application.

Problem 1: Take marks of a trainee in a module as input and calculate the grade and
grade points. The grade table is given below:




SOLUTION :

CALC_GRADE
1. input marks_obtained
2. if ( marks_obtained >= 80 ) then
3. grade_point = 5
4. grade = A
5. elseif ( marks_obtained >= 73 && marks_obtained <=79 ) then
6. grade_point = 4.5
7.  grade = B+
8. elseif ( marks_obtained >= 65 && marks_obtained <=72 ) then
9. grade_point = 4
10. grade = B
11. elseif ( marks_obtained >= 55 && marks_obtained <=64 ) then
12. grade_point = 3
13. grade = C
14. elseif ( marks_obtained >= 0 && marks_obtained <=54 ) then
15. grade_point = 2
16. grade = D
17. end if
18. display " The grade points obtained are equal to: ", grade_point
19. display " The grade awarded is : ", grade
20. end


Problem 2 :
Take marks of a trainee in all generic modules (listed below)as input and calculate the
Generic GPA. The method for calculating Generic GPA is as follows:


Grade points for marks are given in previous problem and credit points are as follows:





SOLUTION :

CALC_GPA
1. input marks_obtained
2. if ( marks_obtained >= 80 ) then
3. grade_point = 5
4. grade = A
5. elseif ( marks_obtained >= 73 && marks_obtained <=79 ) then
6. grade_point = 4.5
7.  grade = B+
8. elseif ( marks_obtained >= 65 && marks_obtained <=72 ) then
9. grade_point = 4
10. grade = B
11. elseif ( marks_obtained >= 55 && marks_obtained <=64 ) then
12. grade_point = 3
13. grade = C
14. elseif ( marks_obtained >= 0 && marks_obtained <=54 ) then
15. grade_point = 2
16. grade = D
17. end if
18 GPA = ( marks_obtained * grade_point ) / marks_obtained
19. display " The grade points are : ", grade_point
20. display " The GPA obtained : ", GPA
21. end

No comments:

Post a Comment