0% found this document useful (0 votes)
5 views

All answers for all the 10 cases in Assignment Part II

The document contains detailed case studies for a software development assignment, covering various programs including temperature conversion, quadratic equation solver, permutations and combinations calculator, compound interest calculator, distance between two points, slope of a line, grade calculator, and simple interest calculator. Each case study includes requirements specification, system analysis, system design, implementation with Python code snippets, and testing with positive and negative test cases. The structure is consistent across all case studies, ensuring clarity and ease of understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

All answers for all the 10 cases in Assignment Part II

The document contains detailed case studies for a software development assignment, covering various programs including temperature conversion, quadratic equation solver, permutations and combinations calculator, compound interest calculator, distance between two points, slope of a line, grade calculator, and simple interest calculator. Each case study includes requirements specification, system analysis, system design, implementation with Python code snippets, and testing with positive and negative test cases. The structure is consistent across all case studies, ensuring clarity and ease of understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Below is the complete, detailed document for all 10 case studies for

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)

Software Development Process Case Studies


Matric No: [Your Matric No]
Name: [Your Name]
1. TEMPERATURE CONVERSION PROGRAM
1.1 Requirements Specification
• The program should convert temperatures between Celsius, Fahrenheit,
and Kelvin.
• Users must input a temperature value and select the conversion type.
• The system should validate user input to ensure correct values are
provided.
1.2 System Analysis
• Inputs: Temperature value, conversion type
• Processes: Apply the appropriate temperature conversion formula
• Outputs: Converted temperature value
1.3 System Design
• User Interface: Input field for temperature value and dropdown for
conversion type.
• Conversion Logic:
o Celsius to Fahrenheit: (C × 9/5) + 32
o Fahrenheit to Celsius: (F - 32) × 5/9
o Celsius to Kelvin: C + 273.15
• Error Handling: Ensure only valid numbers are processed.
1.4 Implementation (Python Example)
def convert_temperature(value, conversion_type):
try:
value = float(value)
except ValueError:
return "Error: Invalid input type"

if conversion_type == "C to F":


return (value * 9/5) + 32
elif conversion_type == "F to C":
return (value - 32) * 5/9
elif conversion_type == "C to K":
# Optionally, check for below absolute zero in Celsius (< -273.15)
if value < -273.15:
return "Error: Below absolute zero"
return value + 273.15
else:
return "Error: Invalid conversion type"

# 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

Negative Test Cases


Test Case Input Conversion Expected
ID Value Type Output/Behavior
TC04 -300 C to K Error: Below absolute zero
TC05 "abc" C to F Error: Invalid input type
TC06 100 "X to Y" Error: Invalid conversion
type
2. QUADRATIC EQUATION SOLVER
2.1 Requirements Specification
• The program should solve quadratic equations of the form ax² + bx + c
= 0.
• Users must input values for a, b, and c.
• The system should handle real as well as complex roots.
• Validate that coefficient a is not zero.
2.2 System Analysis
• Inputs: Coefficients a, b, c
• Processes:
o Calculate discriminant: d = b² - 4ac
o Compute roots using the formula:
▪ (-b ± sqrt(d)) / (2a)
• Outputs: Two roots (real or complex)
2.3 System Design
• User Interface: Input fields for a, b, and c.
• Calculation Logic:
o If a == 0, return an error.
o Use cmath for square root to handle negative discriminants.

2.4 Implementation (Python Example)


import cmath
def solve_quadratic(a, b, c):
try:
a, b, c = float(a), float(b), float(c)
except ValueError:
return "Error: Invalid input type"
if a == 0:
return "Error: 'a' cannot be zero"
d = (b**2) - (4 * a * c)
root1 = (-b + cmath.sqrt(d)) / (2 * a)
root2 = (-b - cmath.sqrt(d)) / (2 * a)
return root1, root2
# Example call:
print(solve_quadratic(1, -3, 2))

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)

Negative Test Cases


Test Case ID a b c Expected Output/Behavior
TC10 0 2 1 Error: 'a' cannot be zero
TC11 "a" 2 1 Error: Invalid input type
TC12 1 2 "b" Error: Invalid input type
3. PERMUTATIONS AND COMBINATIONS CALCULATOR
3.1 Requirements Specification
• The program should calculate permutations and combinations for given
numbers n and r.
• Ensure that n and r are non-negative integers and that r is not greater
than n.
3.2 System Analysis
• Inputs: Integers n and r
• Processes:
o Permutations:

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

def calc_permutations_combinations(n, r):


try:
n = int(n)
r = int(r)
except ValueError:
return "Error: Invalid input type"

if n < 0 or r < 0:
return "Error: Inputs must be non-negative"
if r > n:
return "Error: r cannot be greater than n"

permutations = math.factorial(n) // math.factorial(n - r)


combinations = math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
return permutations, combinations
# Example call:
print(calc_permutations_combinations(5, 2))

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)

Negative Test Cases


Test Case ID n r Expected Output/Behavior
TC16 -5 2 Error: Inputs must be non-negative
TC17 5 6 Error: r cannot be greater than n
TC18 "a" 2 Error: Invalid input type
4. COMPOUND INTEREST CALCULATOR
4.1 Requirements Specification
• The program should calculate compound interest.
• Inputs include principal (P), annual interest rate (r), time period in years
(t), and the number of times interest is compounded per year (n).
4.2 System Analysis
• Inputs: Principal (P), Rate (r), Time (t), Compounding frequency (n)
• Processes:
o Use the formula:
• Outputs: Total amount (A) and interest earned (A - P)
4.3 System Design
• User Interface: Input fields for P, r, t, and n.
• Validation: Check that inputs are numeric and positive.
• Calculation Logic: Direct application of the compound interest formula.
4.4 Implementation (Python Example)
def compound_interest(P, r, t, n):
try:
P = float(P)
r = float(r)
t = float(t)
n = int(n)
except ValueError:
return "Error: Invalid input type"

if P < 0 or r < 0 or t < 0 or n <= 0:


return "Error: All inputs must be positive"

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)

Negative Test Cases


Test Case ID P r t n Expected Output/Behavior
TC21 -1000 0.05 5 12 Error: All inputs must be positive
TC22 1000 "x" 5 12 Error: Invalid input type
TC23 1000 0.05 5 0 Error: All inputs must be positive
5. DISTANCE BETWEEN TWO POINTS (2D)
5.1 Requirements Specification
• The program should calculate the distance between two points in 2D
space.
• Users must input the coordinates of the two points: (x1, y1) and (x2,
y2).
5.2 System Analysis
• Inputs: x1, y1, x2, y2
• Processes: Use the distance formula:

• Outputs: The calculated distance


5.3 System Design
• User Interface: Input fields for x1, y1, x2, and y2.
• Calculation Logic: Apply the distance formula.
• Error Handling: Validate that all inputs are numeric.
5.4 Implementation (Python Example)
import math

def calculate_distance(x1, y1, x2, y2):


try:
x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
except ValueError:
return "Error: Invalid input type"

distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)


return distance

# 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

Negative Test Cases


Test Case ID x1 y1 x2 y2 Expected Output/Behavior
TC26 "a" 0 3 4 Error: Invalid input type
TC27 0 "b" 3 4 Error: Invalid input type
6. SLOPE OF A LINE BETWEEN TWO POINTS
6.1 Requirements Specification
• The program should calculate the slope of the line passing through two
points.
• Users must input the coordinates of the two points: (x1, y1) and (x2,
y2).
• Handle the case when the line is vertical (undefined slope).
6.2 System Analysis
• Inputs: x1, y1, x2, y2
• Processes:
o Calculate slope using:

• Outputs: The slope value or an error if x1 equals x2.


6.3 System Design
• User Interface: Input fields for x1, y1, x2, and y2.
• Validation: Check if x2−x1=0x2 - x1 = 0x2−x1=0 to avoid division by
zero.
• Error Handling: Return an error message if the line is vertical.
6.4 Implementation (Python Example)
def calculate_slope(x1, y1, x2, y2):
try:
x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
except ValueError:
return "Error: Invalid input type"

if x2 - x1 == 0:
return "Error: Undefined slope (vertical line)"

slope = (y2 - y1) / (x2 - x1)


return slope

# 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

Negative Test Cases


Test Case ID x1 y1 x2 y2 Expected Output/Behavior
TC30 1 2 1 5 Error: Undefined slope (vertical line)
TC31 "a" 2 3 6 Error: Invalid input type
7. GRADE CALCULATOR
7.1 Requirements Specification
• The program should calculate the final grade based on a set of scores.
• Users input individual scores, and the program computes the average.
• Based on the average, assign a letter grade (e.g., A, B, C, D, F).
7.2 System Analysis
• Inputs: List of scores (e.g., from assignments, tests)
• Processes:
o Calculate the average score
o Determine letter grade based on defined thresholds (e.g., A for 90–
100, B for 80–89, etc.)
• Outputs: Final average and corresponding letter grade
7.3 System Design
• User Interface: Input field to enter multiple scores (comma-separated
or via multiple inputs).
• Validation: Ensure all inputs are numeric and within a valid range (0–
100).
• Grade Mapping:
o 90–100: A
o 80–89: B
o 70–79: C
o 60–69: D
o Below 60: F
7.4 Implementation (Python Example)
def calculate_grade(scores):
try:
scores = [float(score) for score in scores]
except ValueError:
return "Error: Invalid input type"

if any(score < 0 or score > 100 for score in scores):


return "Error: Scores must be between 0 and 100"

average = sum(scores) / len(scores)

if average >= 90:


grade = 'A'
elif average >= 80:
grade = 'B'
elif average >= 70:
grade = 'C'
elif average >= 60:
grade = 'D'
else:
grade = 'F'

return average, grade

# 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)

Negative Test Cases


Test Case ID Scores Expected Output/Behavior
TC34 [105, 90, 80] Error: Scores must be between 0 and 100
TC35 [90, "eighty"] Error: Invalid input type
8. SIMPLE INTEREST CALCULATOR
8.1 Requirements Specification
• The program should calculate simple interest.
• Inputs include principal (P), rate (R in percent), and time period (T in
years).
8.2 System Analysis
• Inputs: Principal (P), Rate (R), Time (T)
• Processes: Use the formula:

• Outputs: The calculated simple interest


8.3 System Design
• User Interface: Input fields for P, R, and T.
• Validation: Ensure inputs are numeric and positive.
• Calculation Logic: Direct formula application.
8.4 Implementation (Python Example)
def simple_interest(P, R, T):
try:
P = float(P)
R = float(R)
T = float(T)
except ValueError:
return "Error: Invalid input type"

if P < 0 or R < 0 or T < 0:


return "Error: All inputs must be positive"

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

Negative Test Cases


Test Case ID P R T Expected Output/Behavior
TC38 -1000 5 2 Error: All inputs must be positive
TC39 1000 "x" 2 Error: Invalid input type
9. BMI CALCULATOR
9.1 Requirements Specification
• The program should calculate the Body Mass Index (BMI).
• Users must input their weight (in kilograms) and height (in meters).
• The program should output the BMI value along with a category
(Underweight, Normal, Overweight, Obese).
9.2 System Analysis
• Inputs: Weight (kg) and Height (m)
• Processes:
o Calculate BMI using:

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"

if weight <= 0 or height <= 0:


return "Error: Weight and height must be positive"

bmi = weight / (height ** 2)

if bmi < 18.5:


category = "Underweight"
elif bmi < 25:
category = "Normal"
elif bmi < 30:
category = "Overweight"
else:
category = "Obese"

return bmi, category

# 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)

Negative Test Cases


Test Case ID Weight Height Expected Output/Behavior
TC42 -70 1.75 Error: Weight and height must be positive
TC43 70 "x" Error: Invalid input type
10. FACTORIAL CALCULATOR
10.1 Requirements Specification
• The program should calculate the factorial of a given non-negative
integer.
• Users must input a non-negative integer.
• The system should validate that the input is a non-negative integer.
10.2 System Analysis
• Inputs: Integer nnn
• Processes:


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

Negative Test Cases


Test Case ID Input n Expected Output/Behavior
TC46 -3 Error: Input must be a non-negative integer
TC47 "abc" Error: Invalid input type

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.

You might also like