All answers for all the 10 cases in Assignment Part II
All answers for all the 10 cases in Assignment Part II
Assignment Part II. Each case follows the same format as Case 1, including:
• Requirements Specification
• System Analysis
• System Design
• Implementation (with a sample Python code snippet)
• Testing (with positive and negative test cases in table form)
# Example call:
print(convert_temperature(100, "C to F"))
1.5 Testing
Positive Test Cases
Test Case ID Input Value Conversion Type Expected Output
TC01 0 C to F 32.0
TC02 100 C to K 373.15
TC03 212 F to C 100.0
2.5 Testing
Positive Test Cases
Test Case ID a b c Expected Output
TC07 1 -3 2 (2.0, 1.0)
TC08 1 2 1 (-1.0, -1.0)
TC09 1 0 -4 (2.0, -2.0)
o Combinations:
• Outputs: Calculated values for permutations and combinations
3.3 System Design
• User Interface: Input fields for n and r.
• Validation: Check for non-negative values and ensure r≤nr \leq nr≤n.
• Calculation Logic: Use the factorial function for calculations.
3.4 Implementation (Python Example)
import math
if n < 0 or r < 0:
return "Error: Inputs must be non-negative"
if r > n:
return "Error: r cannot be greater than n"
3.5 Testing
Positive Test Cases
Test Case ID n r Expected Output
TC13 5 2 (20, 10)
TC14 6 3 (120, 20)
TC15 4 0 (1, 1)
A = P * (1 + r/n)**(n*t)
interest = A - P
return A, interest
# Example call:
print(compound_interest(1000, 0.05, 5, 12))
4.5 Testing
Positive Test Cases
Test Case ID P r t n Expected Output
TC19 1000 0.05 5 12 (Approx. 1283.36, 283.36)
TC20 5000 0.04 10 4 (Approx. 7401.96, 2401.96)
# Example call:
print(calculate_distance(0, 0, 3, 4))
5.5 Testing
Positive Test Cases
Test Case ID x1 y1 x2 y2 Expected Output
TC24 0 0 3 4 5.0
TC25 -1 -2 2 2 5.0
if x2 - x1 == 0:
return "Error: Undefined slope (vertical line)"
# Example call:
print(calculate_slope(1, 2, 3, 6))
6.5 Testing
Positive Test Cases
Test Case ID x1 y1 x2 y2 Expected Output
TC28 1 2 3 6 2.0
TC29 -2 3 2 11 2.0
# Example call:
print(calculate_grade([85, 92, 78, 88, 95]))
7.5 Testing
Positive Test Cases
Test Case ID Scores Expected Output
TC32 [90, 92, 88] (90.0, A)
TC33 [70, 75, 80, 65] (72.5, C)
SI = (P * R * T) / 100
return SI
# Example call:
print(simple_interest(1000, 5, 2))
8.5 Testing
Positive Test Cases
Test Case ID P R T Expected Output
TC36 1000 5 2 100.0
TC37 2000 4 3 240.0
o Categorize BMI:
▪ Underweight: BMI < 18.5
▪ Normal: 18.5 ≤ BMI < 25
▪ Overweight: 25 ≤ BMI < 30
▪ Obese: BMI ≥ 30
• Outputs: BMI value and category
9.3 System Design
• User Interface: Input fields for weight and height.
• Validation: Ensure inputs are numeric and greater than zero.
• Calculation Logic: Apply BMI formula and determine category.
9.4 Implementation (Python Example)
def calculate_bmi(weight, height):
try:
weight = float(weight)
height = float(height)
except ValueError:
return "Error: Invalid input type"
# Example call:
print(calculate_bmi(70, 1.75))
9.5 Testing
Positive Test Cases
Test Case ID Weight (kg) Height (m) Expected Output
TC40 70 1.75 (Approx. 22.86, Normal)
TC41 50 1.60 (Approx. 19.53, Normal)
•
Outputs: The factorial of nnn
10.3 System Design
• User Interface: Input field for the integer.
• Validation: Check that the input is an integer and n≥0n \geq 0n≥0.
• Calculation Logic: Use a loop or recursion to compute factorial.
10.4 Implementation (Python Example)
def factorial(n):
try:
n = int(n)
except ValueError:
return "Error: Invalid input type"
if n < 0:
return "Error: Input must be a non-negative integer"
result = 1
for i in range(1, n+1):
result *= i
return result
# Example call:
print(factorial(5))
10.5 Testing
Positive Test Cases
Test Case ID Input n Expected Output
TC44 5 120
TC45 0 1
NOTE:
• All implementations are provided as Python examples; you may use any
language as required.
• Ensure that you replace placeholders (like [Your Matric No] and [Your
Name]) with your actual details before submission.