From c3e477d25a89bf76ba897712cc4259e34fe7fb4c Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 2 Apr 2026 09:40:33 +0300 Subject: [PATCH 01/12] Update author and student information in lab3_task1.php --- starter/lab3_task1.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php index f396a7e..3211892 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 Robin Wanyonyi + * @student ENE212-0208/2023 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 03/04/2026 */ // ══════════════════════════════════════════════════════════════ @@ -31,7 +31,40 @@ // Also check divisibility by 3, by 5, and by both 3 and 5 — one line each // TODO: Exercise B — your code here +"; + +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Temperature: Normal" . "
";} +if ($temperature > 37.5) { + echo "Temperature: Fever" . "
";} +if ($temperature < 36.1) { + echo "Temperature: Hypothermia Warning" . "
";} + +echo "
"; + +$temperature = 36.8; +echo $temperature . "
"; + +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Temperature: Normal" . "
";} +if ($temperature > 37.5) { + echo "Temperature: Fever" . "
";} +if ($temperature < 36.1) { + echo "Temperature: Hypothermia Warning" . "
";} + +echo "
"; + +$temperature = 34.5; +echo $temperature . "
"; +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Temperature: Normal" . "
";} +if ($temperature > 37.5) { + echo "Temperature: Fever" . "
";} +if ($temperature < 36.1) { + echo "Temperature: Hypothermia Warning" . "
";} // ══════════════════════════════════════════════════════════════ // EXERCISE C — Comparison Chain From 37bca1e66d997ad58e37ec7adeca26b63b9098cc Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 2 Apr 2026 13:27:20 +0300 Subject: [PATCH 02/12] Update lab3_task1.php --- starter/lab3_task1.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php index 3211892..2a2ca38 100644 --- a/starter/lab3_task1.php +++ b/starter/lab3_task1.php @@ -90,8 +90,9 @@ // Run this code as written, then extend it as instructed below. $username = null; +$intro = "Welcome to the site!"; $display = $username ?? "Guest"; -echo "Welcome, $display
"; +echo "Welcome, $display
" . $intro . "
"; // Chained null coalescing $config_val = null; @@ -100,4 +101,11 @@ $result = $config_val ?? $env_val ?? $default; echo "Config: $result
"; +// Another chained example +$user_pref = null; +$site_pref = null; +$global_pref = "dark_mode"; +$theme = $user_pref ?? $site_pref ?? $global_pref; +echo "Theme: $theme
"; + // TODO: Add one more chained ?? example of your own and explain it in your report. From fd53a4b42d5f20eedb4add85d1b698feafe18ba0 Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 2 Apr 2026 21:21:15 +0300 Subject: [PATCH 03/12] Update lab3_task2.php --- starter/lab3_task2.php | 173 +++++++++++++++++++++++++++++++++++------ 1 file changed, 150 insertions(+), 23 deletions(-) diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index b03e13c..edb3b46 100644 --- a/starter/lab3_task2.php +++ b/starter/lab3_task2.php @@ -1,26 +1,10 @@ "; // student name +echo $name . "
"; + +echo "
"; + // ── Grade Rules (implement using if-elseif-else, ordered highest first) ──── // A (Distinction): Total >= 70 @@ -30,18 +14,72 @@ // C (Pass Lower): Total >= 50 // D (Marginal Pass): Total >= 40 // E (Fail): Total < 40 +$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 + +echo "CAT 1 Score: $cat1 *
"; +echo "CAT 2 Score: $cat2 *
"; +echo "CAT 3 Score: $cat3 *
"; +echo "CAT 4 Score: $cat4 *
"; +echo "Exam Score: $exam *
"; + +$cats_attended = 0; +if ($cat1 > 0) $cats_attended++; +if ($cat2 > 0) $cats_attended++; +if ($cat3 > 0) $cats_attended++; +if ($cat4 > 0) $cats_attended++; + +$total = $cat1 + $cat2 + $cat3 + $cat4 + $exam; +$eligible = ($cats_attended >= 3 && $exam >= 20); +if ($eligible) { + echo "Total Score: $total * - "; + echo "Eligible for Grade Classification
"; + + if ($total >= 70) { + echo $grade = "A (Distinction) "; + } elseif ($total >= 65) { + echo $grade = "B+ (Credit Upper) "; + } elseif ($total >= 60) { + echo $grade = "B (Credit Lower) "; + } elseif ($total >= 55) { + echo $grade = "C+ (Pass Upper) "; + } elseif ($total >= 50) { + echo $grade = "C (Pass Lower) "; + } elseif ($total >= 40) { + echo $grade = "D (Marginal Pass) "; + } else { + echo $grade = "E (Fail) "; + } +} else { + echo "DISQUALIFIED — Exam conditions not met
"; + echo "Not worthy of a grade Classification
"; + $grade = "N/A"; +} + +echo "
"; // ── 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" +// ── STEP 2: Count CATs attended ─────────────────────────────────────────── +// TODO: compute $cats_attended (each CAT > 0 counts as attended) + + +// ── STEP 1: Compute total ───────────────────────────────────────────────── +// TODO: compute $total + + + + // ── 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 // ── STEP 2: Count CATs attended ─────────────────────────────────────────── @@ -58,9 +96,98 @@ // cats attended, eligibility status, grade, remark, supplementary status + // ── 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 +?> + + + + + Student Result Card + + + +

Required Test Data Sets

+ ['cat1'=>8,'cat2'=>7,'cat3'=>9,'cat4'=>6,'exam'=>52, 'expected'=>'Grade B'], + 'B' => ['cat1'=>9,'cat2'=>8,'cat3'=>0,'cat4'=>9,'exam'=>55, 'expected'=>'Grade A'] , + 'C' => ['cat1'=>0,'cat2'=>0,'cat3'=>7,'cat4'=>0,'exam'=>48, 'expected'=>'DISQUALIFIED'], + 'D' => ['cat1'=>5,'cat2'=>4,'cat3'=>6,'cat4'=>3,'exam'=>22, 'expected'=>'Grade D + supp eligible'], + 'E' => ['cat1'=>0,'cat2'=>0,'cat3'=>0,'cat4'=>0,'exam'=>15, 'expected'=>'DISQUALIFIED'], + ]; + + function calc_grade($total) { + if ($total >= 70) return 'A (Distinction)'; + if ($total >= 65) return 'B+ (Credit Upper)'; + if ($total >= 60) return 'B (Credit Lower)'; + if ($total >= 55) return 'C+ (Pass Upper)'; + if ($total >= 50) return 'C (Pass Lower)'; + if ($total >= 40) return 'D (Marginal Pass)'; + return 'E (Fail)'; + } + ?> + + + + + + + + + + + + + + + + + + + + $d): + $cats_attended = count(array_filter([$d['cat1'],$d['cat2'],$d['cat3'],$d['cat4']], fn($x) => $x > 0)); + $total = $d['cat1'] + $d['cat2'] + $d['cat3'] + $d['cat4'] + $d['exam']; + $eligible = ($cats_attended >= 3 && $d['exam'] >= 20); + $grade = $eligible ? calc_grade($total) : 'N/A'; + $supp = $eligible ? 'Not eligible' : 'Eligible'; + $eligText = $eligible ? 'Yes' : 'No'; + ?> + + + + + + + + + + + + + + + + +
SetCAT1CAT2CAT3CAT4ExamTotalAttendedEligibleGradeSupplementaryExpected
+ + From fe3439b1d2a7a0347a0b33c1d0c9f5a06811bb7f Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 2 Apr 2026 22:41:31 +0300 Subject: [PATCH 04/12] Add header comments to lab3_task2.php Added header comments with task details and author information. --- starter/lab3_task2.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index edb3b46..487aee2 100644 --- a/starter/lab3_task2.php +++ b/starter/lab3_task2.php @@ -1,3 +1,18 @@ +/** + * ICS 2371 — Lab 3: Control Structures I + * Task 2: JKUAT Grade Classification System [8 marks] + * + * IMPORTANT: You must complete pseudocode AND flowchart in your PDF + * report BEFORE writing any code below. Marks are awarded for all + * three components: pseudocode, flowchart, and working code. + * + * @author Robin Wanyonyi + * @student ENE212-0208/2023 + * @lab Lab 3 of 14 + * @unit ICS 2371 + * @date 03/04/2026 + */ + "; // student name From 9e7f8772fb5eb7201b14fb287eab7ad341b824ce Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 2 Apr 2026 23:41:22 +0300 Subject: [PATCH 05/12] Update lab3_task3.php --- starter/lab3_task3.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index d9e00c8..0832b8f 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -3,11 +3,11 @@ * ICS 2371 — Lab 3: Control Structures I * Task 3: switch-case and match Expression [6 marks] * - * @author [Your Full Name] - * @student [Your Reg Number, e.g. SCT212-XXXX/2024] + * @author Robin Wanyonyi + * @student ENE212-0208/2023 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 03/04/2026 */ // ══════════════════════════════════════════════════════════════ From 8e0213f130fc96cab7c6d999a6419387403dd25c Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 07:12:21 +0300 Subject: [PATCH 06/12] Implement switch-case and match for day and status --- starter/lab3_task3.php | 84 +++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index 0832b8f..d395752 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -1,3 +1,4 @@ + "; // ══════════════════════════════════════════════════════════════ // EXERCISE B — HTTP Status Code Explainer // ══════════════════════════════════════════════════════════════ -// Given $status_code, use switch-case to explain it: -// 200 → "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" $status_code = 404; // TODO: switch-case for HTTP status +switch ($status_code) { + case 200: + echo "OK — request succeeded\n"; + break; + case 301: + echo "Moved Permanently — resource relocated\n"; + break; + case 400: + echo "Bad Request — client error\n"; + break; + case 401: + echo "Unauthorized — authentication required\n"; + break; + case 403: + echo "Forbidden — access denied\n"; + break; + case 404: + echo "Not Found — resource missing\n"; + break; + case 500: + echo "Internal Server Error — server fault\n"; + break; + default: + echo "Unknown status code\n"; +} +echo "
"; // ══════════════════════════════════════════════════════════════ // EXERCISE C — PHP 8 match Expression // ══════════════════════════════════════════════════════════════ -// Rewrite Exercise B using PHP 8 match instead of switch-case. -// Note: match uses STRICT comparison (===). No break needed. -// Observe the difference in syntax and behaviour. // TODO: match expression for HTTP status — same logic as Exercise B +$status_code = 404; + +$message = match($status_code) { + 200 => "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 $message . "\n"; +echo "<
"; // ══════════════════════════════════════════════════════════════ // EXERCISE D — Rewrite comparison From e96aef44aa2e655cf3fdf24fabb02fd8e8ff22cc Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 07:16:37 +0300 Subject: [PATCH 07/12] Update lab3_task4.php --- starter/lab3_task4.php | 106 +++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php index 2a3d225..aee2a95 100644 --- a/starter/lab3_task4.php +++ b/starter/lab3_task4.php @@ -6,54 +6,68 @@ * 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 Robin Wanyonyi + * @student ENE212-0208/2023 * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date 03/04/2026 */ -// ── Problem: Student Loan Eligibility System ─────────────────────────────── -// -// A student applies for a HELB loan. Eligibility rules (nested): -// -// OUTER CHECK — Is the student enrolled? -// $enrolled = true/false -// If NOT enrolled → "Not eligible — must be an active student" -// -// INNER CHECK 1 — GPA requirement (if enrolled) -// $gpa (float, 0.0–4.0) -// GPA >= 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" +// HELB Loan Eligibility Checker +?> + + + + Loan Eligibility + + + +

Required Test Data Sets

+ ['enrolled' => true, 'gpa' => 3.1, 'income' => 180000, 'prev_loan' => false], + 'B' => ['enrolled' => true, 'gpa' => 1.8, 'income' => 80000, 'prev_loan' => false], + 'C' => ['enrolled' => false, 'gpa' => 3.5, 'income' => 60000, 'prev_loan' => true], + 'D' => ['enrolled' => true, 'gpa' => 2.5, 'income' => 600000, 'prev_loan' => true], + 'E' => ['enrolled' => true, 'gpa' => 2.0, 'income' => 50000, 'prev_loan' => true], + ]; -// ── 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 + function determine_eligibility($enrolled, $gpa, $income, $prev_loan) { + if (!$enrolled) return "Not enrolled"; + if ($gpa < 2.0) return "GPA fail"; + if ($income > 500000) return "Income fail"; + if ($prev_loan) return "Full | Renewal"; + return "Partial 75% | New"; + } + ?> + + + + + + + + + + + + + $d): ?> + + + + + + + + + + +
SetEnrolledGPAIncome (KES)Prev loanExpected
+ + From c3bc438ce5dc04fbd7e8636fb7afd3fd352c9a57 Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 07:17:02 +0300 Subject: [PATCH 08/12] Update lab3_task3.php From 821f03592aee0dba0ed21cdcdfdd68d643b62d59 Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 07:18:37 +0300 Subject: [PATCH 09/12] Add starter/UPDATED lab3_task3.php file From 00cfc9c1b648c4ea9433bedd7a9611b7da938de6 Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 09:42:43 +0300 Subject: [PATCH 10/12] Fix PHP opening tag in lab3_task2.php --- starter/lab3_task2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index 487aee2..7e0af89 100644 --- a/starter/lab3_task2.php +++ b/starter/lab3_task2.php @@ -1,3 +1,4 @@ +"; // student name echo $name . "
"; From 0e9bb10b5919a1e464f58013a639b2be0e44ed8f Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Fri, 3 Apr 2026 10:28:07 +0300 Subject: [PATCH 11/12] Update lab3_task3.php --- starter/lab3_task3.php | 62 +++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index d395752..d6a6c3d 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -15,33 +15,45 @@ // EXERCISE A — Day of Week Classifier // ══════════════════════════════════════════════════════════════ -$day = 3; // change this to test all cases +// ══════════════════════════════════════════════════════════════ +// EXERCISE A — Day of Week Classifier +// ══════════════════════════════════════════════════════════════ + +$day = 1; // change this to test all cases +$day = 2; +$day = 3; +$day = 4; +$day = 5; +$day = 6; +$day = 7; // TODO: switch-case for day classifier -switch ($day) { - case 1: - echo "Monday — Lecture day\n"; - break; - case 2: - echo "Tuesday — Lecture day\n"; - break; - case 3: - echo "Wednesday — Lecture day\n"; - break; - case 4: - echo "Thursday — Lecture day\n"; - break; - case 5: - echo "Friday — Lecture day\n"; - break; - case 6: - echo "Saturday — Weekend\n"; - break; - case 7: - echo "Sunday — Weekend\n"; - break; - default: - echo "Invalid day. Please enter a number between 1 and 7.\n"; +for ($day = 1; $day <= 7; $day++) { + switch ($day) { + case 1: + echo "Monday — Lecture day\n" . "
"; + break; + case 2: + echo "Tuesday — Lecture day\n" . "
"; + break; + case 3: + echo "Wednesday — Lecture day\n" . "
"; + break; + case 4: + echo "Thursday — Lecture day\n" . "
"; + break; + case 5: + echo "Friday — Lecture day\n" . "
"; + break; + case 6: + echo "Saturday — Weekend\n" . "
"; + break; + case 7: + echo "Sunday — Weekend\n" . "
"; + break; + default: + echo "Invalid day. Please enter a number between 1 and 7.\n"; + } } echo "
"; From e4599d1507d6947b06bd3f55528da59661a36789 Mon Sep 17 00:00:00 2001 From: robinwanyonyi7-netizen Date: Thu, 9 Apr 2026 17:46:43 +0300 Subject: [PATCH 12/12] Update lab3_task3.php --- starter/lab3_task3.php | 1 + 1 file changed, 1 insertion(+) diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index d6a6c3d..a149a09 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -121,3 +121,4 @@ // 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? +?>