From 2283ddb48606fcd327d2675a8eb9702a73f379be Mon Sep 17 00:00:00 2001 From: puppykiwi Date: Mon, 6 Apr 2026 17:49:06 +0300 Subject: [PATCH 1/4] feat: lab3 complete - ENE212-0070/2022 --- starter/lab3_task1.php | 55 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php index f396a7e..febc960 100644 --- a/starter/lab3_task1.php +++ b/starter/lab3_task1.php @@ -3,11 +3,11 @@ * ICS 2371 — Lab 3: Control Structures I * Task 1: Simple if and if-else — Warm-Up Exercises [5 marks] * - * @author [Your Full Name] - * @student [Your Reg Number, e.g. SCT212-XXXX/2024] + * @author Johnray Mwendwa + * @student ENE212-0070/2022 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 06/04/2026 */ // ══════════════════════════════════════════════════════════════ @@ -21,6 +21,20 @@ // Test with: 36.8, 39.2, 34.5 — screenshot each // TODO: Exercise A — your code here +$temperature = 39.2; +echo "Test temperature: $temperature \n"; + +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Result:Normal \n"; +} +if ($temperature > 37.5) { + echo "Result:Fever \n"; +} +if ($temperature < 36.1) { + echo "Result:Hypothermia Warning \n"; +} +//line break +echo "\n"; // ══════════════════════════════════════════════════════════════ @@ -31,6 +45,23 @@ // Also check divisibility by 3, by 5, and by both 3 and 5 — one line each // TODO: Exercise B — your code here +$number = 47; +if ($number % 2 == 0) { + echo "$number is EVEN"; +} else { + echo "$number is ODD"; +} + +//fizzbuzz type of problem +if ($number % 3 == 0) { + echo "$number is divisible by 3"; +} +if ($number % 5 == 0) { + echo "$number is divisible by 5"; +} +if ($number % 3 == 0 && $number % 5 == 0) { + echo "$number is divisible by both 3 and 5"; +} // ══════════════════════════════════════════════════════════════ @@ -41,12 +72,12 @@ $x = 10; $y = "10"; $z = 10.0; -var_dump($x == $y); // A: ? -var_dump($x === $y); // B: ? -var_dump($x == $z); // C: ? -var_dump($x === $z); // D: ? -var_dump($y === $z); // E: ? -var_dump($x <=> $y); // F: spaceship — what type? what value? +var_dump($x == $y); // A: boolean true — because == does type juggling and considers 10 and "10" equal +var_dump($x === $y); // B: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as "10" (string) +var_dump($x == $z); // C: boolean true — because == does type juggling and considers 10 and 10.0 equal (both are numeric and have the same value) +var_dump($x === $z); // D: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as 10.0 (float) +var_dump($y === $z); // E: boolean false — because === checks for both value and type, and "10" (string) is not the same type as 10.0 (float) +var_dump($x <=> $y); // F: int(0) — because the spaceship operator <=> returns 0 when the two operands are equal in value (after type juggling) // Your explanation of each result goes in your PDF report (not here). @@ -60,7 +91,7 @@ $display = $username ?? "Guest"; echo "Welcome, $display
"; -// Chained null coalescing + $config_val = null; $env_val = null; $default = "system_default"; @@ -68,3 +99,7 @@ echo "Config: $result
"; // TODO: Add one more chained ?? example of your own and explain it in your report. +$custom_val = null; +$result2 = $custom_val ?? $env_val ?? $default; +echo "Custom: $result2
"; + From d3053d0f10517ca661e3a57c84bfed90c25815f4 Mon Sep 17 00:00:00 2001 From: puppykiwi Date: Mon, 6 Apr 2026 18:13:24 +0300 Subject: [PATCH 2/4] feat: lab3 complete - ENE212-0070/2022 --- starter/lab3_task2.php | 61 +++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index b03e13c..4d346ec 100644 --- a/starter/lab3_task2.php +++ b/starter/lab3_task2.php @@ -7,20 +7,20 @@ * report BEFORE writing any code below. Marks are awarded for all * three components: pseudocode, flowchart, and working code. * - * @author [Your Full Name] - * @student [Your Reg Number, e.g. SCT212-XXXX/2024] + * @author Johnray Mwendwa + * @student ENE212-0070/2022 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 06/04/2026 */ // ── Test Data Set A (change values to run other test sets) ───────────────── -$name = "Your Name"; -$cat1 = 8; // out of 10 -$cat2 = 7; // out of 10 -$cat3 = 9; // out of 10 -$cat4 = 6; // out of 10 -$exam = 52; // out of 60 +$name = "Johnray Mwendwa"; +$cat1 = 0; // out of 10 +$cat2 = 0; // out of 10 +$cat3 = 0; // out of 10 +$cat4 = 0; // out of 10 +$exam = 15; // out of 60 // ── Grade Rules (implement using if-elseif-else, ordered highest first) ──── // A (Distinction): Total >= 70 @@ -31,6 +31,8 @@ // D (Marginal Pass): Total >= 40 // E (Fail): Total < 40 + + // ── Eligibility Rule (implement using nested if) ─────────────────────────── // Must have attended at least 3 of 4 CATs (CAT score > 0 counts as attended) // AND exam score >= 20 @@ -42,20 +44,61 @@ // ── STEP 1: Compute total ───────────────────────────────────────────────── // TODO: compute $total +$total = $cat1 + $cat2 + $cat3 + $cat4 + $exam; // ── STEP 2: Count CATs attended ─────────────────────────────────────────── // TODO: compute $cats_attended (each CAT > 0 counts as attended) +$cats_attended = 0; +if ($cat1 > 0) $cats_attended++; +if ($cat2 > 0) $cats_attended++; +if ($cat3 > 0) $cats_attended++; +if ($cat4 > 0) $cats_attended++; // ── STEP 3: Eligibility check (nested if) ───────────────────────────────── // TODO: nested if — eligibility → grade classification → supplementary ternary +if ($cats_attended >= 3 && $exam >= 20) { + // eligible — now determine grade + if ($total >= 70) { + $grade = "A (Distinction)"; + } elseif ($total >= 65) { + $grade = "B+ (Credit Upper)"; + } elseif ($total >= 60) { + $grade = "B (Credit Lower)"; + } elseif ($total >= 55) { + $grade = "C+ (Pass Upper)"; + } elseif ($total >= 50) { + $grade = "C (Pass Lower)"; + } elseif ($total >= 40) { + $grade = "D (Marginal Pass)"; + } else { + $grade = "E (Fail)"; + } +} else { + // not eligible + $grade = "DISQUALIFIED — Exam conditions not met"; +} + // ── STEP 4: Display formatted HTML report card ──────────────────────────── // TODO: output a clear, formatted report card showing: // student name, each CAT score, exam score, total, // cats attended, eligibility status, grade, remark, supplementary status +echo "

Report Card

"; +echo "

Student Name: $name

"; +echo "

CAT 1: $cat1

"; +echo "

CAT 2: $cat2

"; +echo "

CAT 3: $cat3

"; +echo "

CAT 4: $cat4

"; +echo "

Exam: $exam

"; +echo "

Total: $total

"; +echo "

CATs Attended: $cats_attended

"; +echo "

Eligibility Status: " . ($cats_attended >= 3 && $exam >= 20 ? "Eligible" : "DISQUALIFIED") . "

"; +echo "

Grade: $grade

"; +echo "

Remark: " . ($grade == "E (Fail)" ? "Needs Improvement" : "Well Done") . "

"; +echo "

Supplementary Status: " . ($grade == "D (Marginal Pass)" ? "Eligible for Supplementary Exam" : "Not eligible for supplementary") . "

"; // ── Required Test Data Sets — screenshot each ───────────────────────────── From cf8a601404f1ab3f418b103a681b41f25a222b28 Mon Sep 17 00:00:00 2001 From: puppykiwi Date: Tue, 7 Apr 2026 14:38:51 +0300 Subject: [PATCH 3/4] feat: lab3 task3complete - ENE212-0070/2022 --- starter/lab3_task1.php | 210 +++++++++++++++++++-------------------- starter/lab3_task2.php | 218 ++++++++++++++++++++--------------------- starter/lab3_task3.php | 186 +++++++++++++++++++++++------------ starter/lab3_task4.php | 118 +++++++++++----------- 4 files changed, 398 insertions(+), 334 deletions(-) diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php index febc960..e0f2f10 100644 --- a/starter/lab3_task1.php +++ b/starter/lab3_task1.php @@ -1,105 +1,105 @@ - 37.5 -// "Hypothermia Warning" if temp < 36.1 -// Test with: 36.8, 39.2, 34.5 — screenshot each - -// TODO: Exercise A — your code here -$temperature = 39.2; -echo "Test temperature: $temperature \n"; - -if ($temperature >= 36.1 && $temperature <= 37.5) { - echo "Result:Normal \n"; -} -if ($temperature > 37.5) { - echo "Result:Fever \n"; -} -if ($temperature < 36.1) { - echo "Result:Hypothermia Warning \n"; -} -//line break -echo "\n"; - - -// ══════════════════════════════════════════════════════════════ -// EXERCISE B — Even or Odd -// ══════════════════════════════════════════════════════════════ -// Declare $number = 47 -// Use if-else to print "$number is EVEN" or "$number is ODD" -// Also check divisibility by 3, by 5, and by both 3 and 5 — one line each - -// TODO: Exercise B — your code here -$number = 47; -if ($number % 2 == 0) { - echo "$number is EVEN"; -} else { - echo "$number is ODD"; -} - -//fizzbuzz type of problem -if ($number % 3 == 0) { - echo "$number is divisible by 3"; -} -if ($number % 5 == 0) { - echo "$number is divisible by 5"; -} -if ($number % 3 == 0 && $number % 5 == 0) { - echo "$number is divisible by both 3 and 5"; -} - - -// ══════════════════════════════════════════════════════════════ -// EXERCISE C — Comparison Chain -// ══════════════════════════════════════════════════════════════ -// Run this code EXACTLY as written. -// Record all six outputs in your report and explain each result. - -$x = 10; $y = "10"; $z = 10.0; - -var_dump($x == $y); // A: boolean true — because == does type juggling and considers 10 and "10" equal -var_dump($x === $y); // B: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as "10" (string) -var_dump($x == $z); // C: boolean true — because == does type juggling and considers 10 and 10.0 equal (both are numeric and have the same value) -var_dump($x === $z); // D: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as 10.0 (float) -var_dump($y === $z); // E: boolean false — because === checks for both value and type, and "10" (string) is not the same type as 10.0 (float) -var_dump($x <=> $y); // F: int(0) — because the spaceship operator <=> returns 0 when the two operands are equal in value (after type juggling) - -// Your explanation of each result goes in your PDF report (not here). - - -// ══════════════════════════════════════════════════════════════ -// EXERCISE D — Null & Default Values -// ══════════════════════════════════════════════════════════════ -// Run this code as written, then extend it as instructed below. - -$username = null; -$display = $username ?? "Guest"; -echo "Welcome, $display
"; - - -$config_val = null; -$env_val = null; -$default = "system_default"; -$result = $config_val ?? $env_val ?? $default; -echo "Config: $result
"; - -// TODO: Add one more chained ?? example of your own and explain it in your report. -$custom_val = null; -$result2 = $custom_val ?? $env_val ?? $default; -echo "Custom: $result2
"; - + 37.5 +// "Hypothermia Warning" if temp < 36.1 +// Test with: 36.8, 39.2, 34.5 — screenshot each + +// TODO: Exercise A — your code here +$temperature = 39.2; +echo "Test temperature: $temperature \n"; + +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Result:Normal \n"; +} +if ($temperature > 37.5) { + echo "Result:Fever \n"; +} +if ($temperature < 36.1) { + echo "Result:Hypothermia Warning \n"; +} +//line break +echo "\n"; + + +// ══════════════════════════════════════════════════════════════ +// EXERCISE B — Even or Odd +// ══════════════════════════════════════════════════════════════ +// Declare $number = 47 +// Use if-else to print "$number is EVEN" or "$number is ODD" +// Also check divisibility by 3, by 5, and by both 3 and 5 — one line each + +// TODO: Exercise B — your code here +$number = 47; +if ($number % 2 == 0) { + echo "$number is EVEN"; +} else { + echo "$number is ODD"; +} + +//fizzbuzz type of problem +if ($number % 3 == 0) { + echo "$number is divisible by 3"; +} +if ($number % 5 == 0) { + echo "$number is divisible by 5"; +} +if ($number % 3 == 0 && $number % 5 == 0) { + echo "$number is divisible by both 3 and 5"; +} + + +// ══════════════════════════════════════════════════════════════ +// EXERCISE C — Comparison Chain +// ══════════════════════════════════════════════════════════════ +// Run this code EXACTLY as written. +// Record all six outputs in your report and explain each result. + +$x = 10; $y = "10"; $z = 10.0; + +var_dump($x == $y); // A: boolean true — because == does type juggling and considers 10 and "10" equal +var_dump($x === $y); // B: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as "10" (string) +var_dump($x == $z); // C: boolean true — because == does type juggling and considers 10 and 10.0 equal (both are numeric and have the same value) +var_dump($x === $z); // D: boolean false — because === checks for both value and type, and 10 (integer) is not the same type as 10.0 (float) +var_dump($y === $z); // E: boolean false — because === checks for both value and type, and "10" (string) is not the same type as 10.0 (float) +var_dump($x <=> $y); // F: int(0) — because the spaceship operator <=> returns 0 when the two operands are equal in value (after type juggling) + +// Your explanation of each result goes in your PDF report (not here). + + +// ══════════════════════════════════════════════════════════════ +// EXERCISE D — Null & Default Values +// ══════════════════════════════════════════════════════════════ +// Run this code as written, then extend it as instructed below. + +$username = null; +$display = $username ?? "Guest"; +echo "Welcome, $display
"; + + +$config_val = null; +$env_val = null; +$default = "system_default"; +$result = $config_val ?? $env_val ?? $default; +echo "Config: $result
"; + +// TODO: Add one more chained ?? example of your own and explain it in your report. +$custom_val = null; +$result2 = $custom_val ?? $env_val ?? $default; +echo "Custom: $result2
"; + diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index 4d346ec..08116f2 100644 --- a/starter/lab3_task2.php +++ b/starter/lab3_task2.php @@ -1,109 +1,109 @@ -= 70 -// B+ (Credit Upper): Total >= 65 -// B (Credit Lower): Total >= 60 -// C+ (Pass Upper): Total >= 55 -// C (Pass Lower): Total >= 50 -// D (Marginal Pass): Total >= 40 -// E (Fail): Total < 40 - - - -// ── Eligibility Rule (implement using nested if) ─────────────────────────── -// Must have attended at least 3 of 4 CATs (CAT score > 0 counts as attended) -// AND exam score >= 20 -// Otherwise: "DISQUALIFIED — Exam conditions not met" - -// ── Supplementary Rule (implement using ternary) ────────────────────────── -// If grade is D: "Eligible for Supplementary Exam" -// Otherwise: "Not eligible for supplementary" - -// ── STEP 1: Compute total ───────────────────────────────────────────────── -// TODO: compute $total -$total = $cat1 + $cat2 + $cat3 + $cat4 + $exam; - - -// ── STEP 2: Count CATs attended ─────────────────────────────────────────── -// TODO: compute $cats_attended (each CAT > 0 counts as attended) -$cats_attended = 0; -if ($cat1 > 0) $cats_attended++; -if ($cat2 > 0) $cats_attended++; -if ($cat3 > 0) $cats_attended++; -if ($cat4 > 0) $cats_attended++; - - -// ── STEP 3: Eligibility check (nested if) ───────────────────────────────── -// TODO: nested if — eligibility → grade classification → supplementary ternary -if ($cats_attended >= 3 && $exam >= 20) { - // eligible — now determine grade - if ($total >= 70) { - $grade = "A (Distinction)"; - } elseif ($total >= 65) { - $grade = "B+ (Credit Upper)"; - } elseif ($total >= 60) { - $grade = "B (Credit Lower)"; - } elseif ($total >= 55) { - $grade = "C+ (Pass Upper)"; - } elseif ($total >= 50) { - $grade = "C (Pass Lower)"; - } elseif ($total >= 40) { - $grade = "D (Marginal Pass)"; - } else { - $grade = "E (Fail)"; - } -} else { - // not eligible - $grade = "DISQUALIFIED — Exam conditions not met"; -} - - - -// ── STEP 4: Display formatted HTML report card ──────────────────────────── -// TODO: output a clear, formatted report card showing: -// student name, each CAT score, exam score, total, -// cats attended, eligibility status, grade, remark, supplementary status -echo "

Report Card

"; -echo "

Student Name: $name

"; -echo "

CAT 1: $cat1

"; -echo "

CAT 2: $cat2

"; -echo "

CAT 3: $cat3

"; -echo "

CAT 4: $cat4

"; -echo "

Exam: $exam

"; -echo "

Total: $total

"; -echo "

CATs Attended: $cats_attended

"; -echo "

Eligibility Status: " . ($cats_attended >= 3 && $exam >= 20 ? "Eligible" : "DISQUALIFIED") . "

"; -echo "

Grade: $grade

"; -echo "

Remark: " . ($grade == "E (Fail)" ? "Needs Improvement" : "Well Done") . "

"; -echo "

Supplementary Status: " . ($grade == "D (Marginal Pass)" ? "Eligible for Supplementary Exam" : "Not eligible for supplementary") . "

"; - - -// ── Required Test Data Sets — screenshot each ───────────────────────────── -// Set A: cat1=8, cat2=7, cat3=9, cat4=6, exam=52 → expect grade B -// Set B: cat1=9, cat2=8, cat3=0, cat4=9, exam=55 → expect grade A (check cats_attended) -// Set C: cat1=0, cat2=0, cat3=7, cat4=0, exam=48 → expect DISQUALIFIED -// Set D: cat1=5, cat2=4, cat3=6, cat4=3, exam=22 → expect grade D + supp eligible -// Set E: cat1=0, cat2=0, cat3=0, cat4=0, exam=15 → expect DISQUALIFIED += 70 +// B+ (Credit Upper): Total >= 65 +// B (Credit Lower): Total >= 60 +// C+ (Pass Upper): Total >= 55 +// C (Pass Lower): Total >= 50 +// D (Marginal Pass): Total >= 40 +// E (Fail): Total < 40 + + + +// ── Eligibility Rule (implement using nested if) ─────────────────────────── +// Must have attended at least 3 of 4 CATs (CAT score > 0 counts as attended) +// AND exam score >= 20 +// Otherwise: "DISQUALIFIED — Exam conditions not met" + +// ── Supplementary Rule (implement using ternary) ────────────────────────── +// If grade is D: "Eligible for Supplementary Exam" +// Otherwise: "Not eligible for supplementary" + +// ── STEP 1: Compute total ───────────────────────────────────────────────── +// TODO: compute $total +$total = $cat1 + $cat2 + $cat3 + $cat4 + $exam; + + +// ── STEP 2: Count CATs attended ─────────────────────────────────────────── +// TODO: compute $cats_attended (each CAT > 0 counts as attended) +$cats_attended = 0; +if ($cat1 > 0) $cats_attended++; +if ($cat2 > 0) $cats_attended++; +if ($cat3 > 0) $cats_attended++; +if ($cat4 > 0) $cats_attended++; + + +// ── STEP 3: Eligibility check (nested if) ───────────────────────────────── +// TODO: nested if — eligibility → grade classification → supplementary ternary +if ($cats_attended >= 3 && $exam >= 20) { + // eligible — now determine grade + if ($total >= 70) { + $grade = "A (Distinction)"; + } elseif ($total >= 65) { + $grade = "B+ (Credit Upper)"; + } elseif ($total >= 60) { + $grade = "B (Credit Lower)"; + } elseif ($total >= 55) { + $grade = "C+ (Pass Upper)"; + } elseif ($total >= 50) { + $grade = "C (Pass Lower)"; + } elseif ($total >= 40) { + $grade = "D (Marginal Pass)"; + } else { + $grade = "E (Fail)"; + } +} else { + // not eligible + $grade = "DISQUALIFIED — Exam conditions not met"; +} + + + +// ── STEP 4: Display formatted HTML report card ──────────────────────────── +// TODO: output a clear, formatted report card showing: +// student name, each CAT score, exam score, total, +// cats attended, eligibility status, grade, remark, supplementary status +echo "

Report Card

"; +echo "

Student Name: $name

"; +echo "

CAT 1: $cat1

"; +echo "

CAT 2: $cat2

"; +echo "

CAT 3: $cat3

"; +echo "

CAT 4: $cat4

"; +echo "

Exam: $exam

"; +echo "

Total: $total

"; +echo "

CATs Attended: $cats_attended

"; +echo "

Eligibility Status: " . ($cats_attended >= 3 && $exam >= 20 ? "Eligible" : "DISQUALIFIED") . "

"; +echo "

Grade: $grade

"; +echo "

Remark: " . ($grade == "E (Fail)" ? "Needs Improvement" : "Well Done") . "

"; +echo "

Supplementary Status: " . ($grade == "D (Marginal Pass)" ? "Eligible for Supplementary Exam" : "Not eligible for supplementary") . "

"; + + +// ── Required Test Data Sets — screenshot each ───────────────────────────── +// Set A: cat1=8, cat2=7, cat3=9, cat4=6, exam=52 → expect grade B +// Set B: cat1=9, cat2=8, cat3=0, cat4=9, exam=55 → expect grade A (check cats_attended) +// Set C: cat1=0, cat2=0, cat3=7, cat4=0, exam=48 → expect DISQUALIFIED +// Set D: cat1=5, cat2=4, cat3=6, cat4=3, exam=22 → expect grade D + supp eligible +// Set E: cat1=0, cat2=0, cat3=0, cat4=0, exam=15 → expect DISQUALIFIED diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index d9e00c8..a2337cf 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -1,61 +1,125 @@ - "OK — request succeeded", + 301 => "Moved Permanently — resource relocated", + 400 => "Bad Request — client error", + 401 => "Unauthorized — authentication required", + 403 => "Forbidden — access denied", + 404 => "Not Found — resource missing", + 500 => "Internal Server Error — server fault", + default => "Unknown status code", +}; + +echo $result . "\n"; +// ══════════════════════════════════════════════════════════════ +// EXERCISE D — Rewrite comparison +// ══════════════════════════════════════════════════════════════ +// In your PDF report, answer: +// 1. What is the key difference between switch (==) and match (===)? +// +// 2. Give one example where this difference changes the output. +// 3. When would you prefer switch over match, and why? diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php index 2a3d225..37032db 100644 --- a/starter/lab3_task4.php +++ b/starter/lab3_task4.php @@ -1,59 +1,59 @@ -= 2.0 → proceed to inner check 2 -// GPA < 2.0 → "Not eligible — GPA below minimum (2.0)" -// -// INNER CHECK 2 — Household income bracket (if enrolled AND GPA >= 2.0) -// $annual_income (KES) -// < 100000 → "Eligible — Full loan award" -// < 250000 → "Eligible — Partial loan (75%)" -// < 500000 → "Eligible — Partial loan (50%)" -// >= 500000 → "Not eligible — household income exceeds threshold" -// -// ADDITIONAL RULE — Ternary for renewal vs new application: -// $previous_loan = true/false -// If eligible: use ternary to append "| Renewal application" or "| New application" - -// ── Test data (change to test all branches) ─────────────────────────────── -$enrolled = true; -$gpa = 3.1; -$annual_income = 180000; -$previous_loan = false; - -// ── STEP 1: Outer enrollment check ──────────────────────────────────────── -// TODO: nested if structure implementing all rules above - - -// ── STEP 2: Display result ──────────────────────────────────────────────── -// TODO: output formatted result showing all input values and the decision - - -// ── Required Test Data Sets — screenshot each ───────────────────────────── -// Set A: enrolled=true, gpa=3.1, income=180000, previous=false → Partial 75% -// Set B: enrolled=true, gpa=1.8, income=80000, previous=false → GPA fail -// Set C: enrolled=false, gpa=3.5, income=60000, previous=true → Not enrolled -// Set D: enrolled=true, gpa=2.5, income=600000, previous=true → Income fail -// Set E: enrolled=true, gpa=2.0, income=50000, previous=true → Full | Renewal += 2.0 → proceed to inner check 2 +// GPA < 2.0 → "Not eligible — GPA below minimum (2.0)" +// +// INNER CHECK 2 — Household income bracket (if enrolled AND GPA >= 2.0) +// $annual_income (KES) +// < 100000 → "Eligible — Full loan award" +// < 250000 → "Eligible — Partial loan (75%)" +// < 500000 → "Eligible — Partial loan (50%)" +// >= 500000 → "Not eligible — household income exceeds threshold" +// +// ADDITIONAL RULE — Ternary for renewal vs new application: +// $previous_loan = true/false +// If eligible: use ternary to append "| Renewal application" or "| New application" + +// ── Test data (change to test all branches) ─────────────────────────────── +$enrolled = true; +$gpa = 3.1; +$annual_income = 180000; +$previous_loan = false; + +// ── STEP 1: Outer enrollment check ──────────────────────────────────────── +// TODO: nested if structure implementing all rules above + + +// ── STEP 2: Display result ──────────────────────────────────────────────── +// TODO: output formatted result showing all input values and the decision + + +// ── Required Test Data Sets — screenshot each ───────────────────────────── +// Set A: enrolled=true, gpa=3.1, income=180000, previous=false → Partial 75% +// Set B: enrolled=true, gpa=1.8, income=80000, previous=false → GPA fail +// Set C: enrolled=false, gpa=3.5, income=60000, previous=true → Not enrolled +// Set D: enrolled=true, gpa=2.5, income=600000, previous=true → Income fail +// Set E: enrolled=true, gpa=2.0, income=50000, previous=true → Full | Renewal From 7ac48242796003036f9cd7b4ec715c4b3e4f10bf Mon Sep 17 00:00:00 2001 From: puppykiwi Date: Tue, 7 Apr 2026 15:02:00 +0300 Subject: [PATCH 4/4] feat: lab3 complete - ENE212-0070/2022 --- starter/lab3_task4.php | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php index 37032db..5779da7 100644 --- a/starter/lab3_task4.php +++ b/starter/lab3_task4.php @@ -6,11 +6,11 @@ * IMPORTANT: You must complete pseudocode AND flowchart in your PDF * report BEFORE writing any code below. * - * @author [Your Full Name] - * @student [Your Reg Number, e.g. SCT212-XXXX/2024] + * @author Johnray Mwendwa + * @student ENE212-0070/2022 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 06/04/2026 */ // ── Problem: Student Loan Eligibility System ─────────────────────────────── @@ -39,17 +39,39 @@ // ── Test data (change to test all branches) ─────────────────────────────── $enrolled = true; -$gpa = 3.1; -$annual_income = 180000; -$previous_loan = false; +$gpa = 2.0; +$annual_income = 50000; +$previous_loan = true; +$decision = ""; // to store final decision message // ── STEP 1: Outer enrollment check ──────────────────────────────────────── // TODO: nested if structure implementing all rules above - +if (!$enrolled) { + $decision = "Not eligible — must be an active student"; +} else { + if ($gpa < 2.0) { + $decision = "Not eligible — GPA below minimum (2.0)"; + } else { + if ($annual_income < 100000) { + $decision = "Eligible — Full loan award"; + } elseif ($annual_income < 250000) { + $decision = "Eligible — Partial loan (75%)"; + } elseif ($annual_income < 500000) { + $decision = "Eligible — Partial loan (50%)"; + } else { + $decision = "Not eligible — household income exceeds threshold"; + } + } +} // ── STEP 2: Display result ──────────────────────────────────────────────── // TODO: output formatted result showing all input values and the decision - +echo "Loan Application Result:\n"; +echo "Enrolled: " . ($enrolled ? "Yes" : "No") . "\n"; +echo "GPA: " . $gpa . "\n"; +echo "Annual Income: " . $annual_income . "\n"; +echo "Previous Loan: " . ($previous_loan ? "Yes" : "No") . "\n"; +echo "Decision: " . $decision . "\n"; // ── Required Test Data Sets — screenshot each ───────────────────────────── // Set A: enrolled=true, gpa=3.1, income=180000, previous=false → Partial 75%