bs stats
TRANSCRIPT
-
7/29/2019 bs stats
1/3
DHA Suffa University
Problem Solving and Computer Programming (CS 102)
Fall 2012
Submission Date: Thursday, 4th
October 2012 Start of class
Assignment #02: Designing Algorithms
Note: Make sure you submit your own work. You may discuss the algorithm logic with your
friends/classmates but copying others work is not allowed. Such form of collaboration will not
be tolerated and case will be forwarded directly to the Disciplinary Committee or in the best
case, -100 policy (Remember?). In case you discuss the solution with someone, mention their
Name(s) and Roll #(s) on the first page of the assignment as Collaborators.
To recall again, designing an algorithm includes:1. Identifying Output(s)2. Identifying Input(s)3. Expressing the Basic Idea in a Natural Language like English4. Condensing the Basic Idea into Pseudocode (i.e. sentences -> phrases & expressions)5. Visualizing the solution as Flow Chart (i.e. sentences -> symbols & expressions)
Design algorithms for the following problems. Each problem must follow the 5 steps stated
above.
Bonus: For each algorithm handle invalid inputs by keep taking input until the user gives a valid
input. You have to identify the invalid input cases for each problem yourself!
Problem 01: Find the sum of the least significant and most significant digits of a 4-digit number.
Problem 02: Find out whether the input number is even or odd and if the number is even,
display its square and if the number is odd display its cube.
Problem 03: Find whether an input number is divisible by x. (x can also be any number input by
the user).
-
7/29/2019 bs stats
2/3
Following is the DSU grading scheme according to the marks obtained in a particular course.
Semester Grade Point Average (SGPA) is the weighted average of grade points earned in a
semester. The weights are taken as the ratio of course credits to the total credits taken by the
student in the semester.
A student who takes four courses in a semester with credit hours of C1, C2, C3 and C4 obtaining
grade point of P1, P2, P3 and P4 respectively will score an SGPA of:
SGPA = P1 (C1/C) +P2 (C2/C)+P3(C3/C)+P4(C4/C)
Where C = C1+C2+C3+C4
Problem 04: The first semester at DSU ends Final marks have been displayed on Piazza.
Tayyab Ali (our imaginary student 12-2-CS-999) needs to find the GRADE corresponding to his
MARKS in CS 102. Design an algorithm which helps Tayyab to do so.
Problem 05: Using the Algorithm you designed in Problem 04 for the remaining courses as well,
Tayyab found the GRADE POINTS for all courses he took in the first semester (he took 5 courses
-
7/29/2019 bs stats
3/3
full semester load). He now needs to find his SGPA for the first semester. Design an algorithm
to help Tayyab in this.
Problem 06: Design an algorithm that takes a number as input till the sum of those inputs are
smaller than 10000 and will print sum at the end.
Problem 07: Rock, Paper and Scissor Game for n rounds between Player 1 and Player 2.
Good Luck!