Midterm answers
1. Context diagram for ShaftFree. [4 marks]
2. Process model and why [3 marks]
Process model selection [1 mark]
- V model
- Evolutionary / phased-delivery model
Justification [2 marks]
- V model:
--- Implement and test ShaftFree before integrating with external Grading System.
- Evolutionary / phased-delivery model:
--- Courses and colleges have many ways of computing grades (e.g. some have 5-point GPAs, some rely on doing well on some proportion or all assignments, etc.) so lots of future customization would be needed for a real commercial product.
- Other models with original reasoning consistent with Pfleeger worth 1 mark. (Or prototyping model if justification given is same as evolutionary/phased-delivery: 3 marks)
3. Function that computes a course grade based on assignment performance [4 marks]
The specification is vague on one point:
(1) "a sequential data structure in which the data items correspond to the grades for that assignment" should really say "a sequential data structure in which each data item corresponds to the grades for an assignment" if ComputeCourseGrade is intended to compute a course grade for a student from a set of assignment grades.
(2) But the apostrophe in "student’s" (i.e. of one student) could easily be misread as "students’" (i.e. of every student), in which case the input sequential data structure would consist of the assignment grades for all the students who took a specific assignment. Since ComputeCourseGrade wouldn’t be doing anything if it took in a sequence of GP equivalents and output the same data, the input in that case would either have to be one of the following:
(2a) Percentage marks for the assignment in question (in which case, the function is converting these to GP equivalents for all the students in the class, and therefore also requires grade thresholds and assignment weightings as input. This is not a very reasonable interpretation of the informal spec., because these additional inputs are not mentioned.
(2b) GP equivalents for the assignment in question (in which case the function is extracting from these the GP equivalent for the student of interest), and also possibly adding it to the student’s course grade so far .This, too, is not a very reasonable interpretation, because no mention was made of a student identifier.
(2c) GP equivalents for the assignment in question, but the function is accumulating everyone’s course grade and storing it internally. No mention, however, was made of a running grade total for the class, so this is probably not meant either.
Here is a model answers for #1:
ComputeFinalCourseGrade
Purpose: Computes a course grade for a student from a set of assignment grades.
Assumptions: The input grades are correct and correspond to all (and only) the assignments in the course. There are no special assignments or extra-credit grades. There is no pro-rata weighting of assignments for a student not taking all assignments (e.g. graduating senior missing a final assignment or student missing an assignment for instructor-approved reasons).
Input: AssignmentGPEs -- A sequence [or set, array, vector, etc.] of GP equivalents for one student’s assignments in a course.
Output: CourseGP -- A final grade for the student. [Could be numeric or letter grade].
Definition: The CourseGP is the sum of the the AssignmentGPEs.
Exceptions: The AssignmentGPEs set is empty. The AssignmentGPE contains any non-numeric item or numeric item less than zero. The CourseGP is greater than 4.0.
(2a) ComputeCourseGradeForAssignment:
Purpose: Computes a course grade for a student from a sequence assignment grades.
Assumptions: The input grades are correct and correspond to all (and only) the assignments in the course. There are no special assignments or extra-credit grades.
Input: AssignmentGPEs -- A sequence of GP equivalents for one student’s assignments in a course.
Output: CourseGP -- A final grade for the student. [Could be numeric or letter grade].
Definition: The CourseGP is the sum of the the AssignmentGPEs.
Exceptions: The AssignmentGPEs set is empty. The AssignmentGPE contains any non-numeric item or numeric item less than zero. The CourseGP is greater than 4.0.
Grading of question -- up to 4 marks from:
Precise wording [ 1 mark ]
Inputs adequate to support interpretation (e.g. converting %ages into GP equivalent would require additional threshold input unless thresholds were defined in specification) [1 mark]
Output corresponds to needed functionality [1 mark]
Definition is consistent with one of the interpretations above [1 mark]
Exceptions and/or assumptions clearly expressed [1 mark]
4. Triangle categorization pseudo-code.
(a) Prevent an integer overflow from occurring. [1 mark]
(b) Revise to check for RIGHT_TRIANGLEs. [2 marks]
// Categorize triangles, blah, blah, blah...
int function categorizeTriangle(int a, int b, int c)
{
// Ensure arguments represent valid side lengths
if ((a < 1) || (b < 1) || (c < 1))
{
// throw InvalidSide exception
}
// Equilateral?
if (a == b == c)
{
return EQUILATERAL;
}
// Feasible triangle?
// sort3 sorts three integers in descending order
max3(a, b, c);
// Should be sort3(a, b, c);
if ( a >= (b + c) )
// Q4(a) if (b+c) > MAXINT this will overflow
// better to say "if ( (a - b) >= c )"
// or, alternatively, convert or cast a, b and c to
// longints [1 MARK]
{
// throw InvalidTriangle exception
}
// Isosceles?
if ( b == c)
{
return ISOSCELES;
}
// Right triangle?
// Q4(b) Pythagorean Theorem [ 1 mark ]
// Must guarantee that squaring large integers
// and adding squares don’t overflow. [1 mark]
long aSquare = a**2;
long bSquare = b**2;
long cSquare = c**2;
if ( (aSquare - bSquare) == cSquare) )
{
return RIGHT_TRIANGLE;
}
else
{
return SCALENE;
}
// catch exceptions...
}
(c) Test cases for right-triangle functionality. [2 marks]
Any two of these three:
|
Input (examples) |
Expected output |
Equivalence class |
|
(3, 4, 5) |
RIGHT_TRIANGLE |
Normal right triangle [1 mark] |
|
(30,000, 40,000, 50,000) |
RIGHT_TRIANGLE |
Possible integer overflow [ 1 mark] |
There is (of course) no "pseudo-isosceles" right triangle test case, as a pair of identical integer-length adjacent sides cannot give an integer-length hypoteneuse. [1 mark]