diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php
index f396a7e..1d3524e 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 [Tim Kiplimo]
+ * @student [ENE212-0063/2021]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [3/04/2026]
*/
// ══════════════════════════════════════════════════════════════
@@ -21,6 +21,19 @@
// Test with: 36.8, 39.2, 34.5 — screenshot each
// TODO: Exercise A — your code here
+// --- Exercise A: Temperature Alert System ---
+echo "
Exercise A
";
+$temperature = 34.5; // Change this value to 36.8 and 34.5 for your screenshots
+
+if ($temperature >= 36.1 && $temperature <= 37.5) {
+ echo "Normal
";
+}
+if ($temperature > 37.5) {
+ echo "Fever
";
+}
+if ($temperature < 36.1) {
+ echo "Hypothermia Warning
";
+}
// ══════════════════════════════════════════════════════════════
@@ -31,7 +44,18 @@
// Also check divisibility by 3, by 5, and by both 3 and 5 — one line each
// TODO: Exercise B — your code here
+echo "Exercise B
";
+$number = 47;
+if ($number % 2 == 0) {
+ echo "$number is EVEN
";
+} else {
+ echo "$number is ODD
";
+}
+// Additional checks
+echo ($number % 3 == 0) ? "$number is divisible by 3
" : "$number is NOT divisible by 3
";
+echo ($number % 5 == 0) ? "$number is divisible by 5
" : "$number is NOT divisible by 5
";
+echo ($number % 3 == 0 && $number % 5 == 0) ? "$number is divisible by both
" : "$number is NOT divisible by both
";
// ══════════════════════════════════════════════════════════════
// EXERCISE C — Comparison Chain
@@ -68,3 +92,9 @@
echo "Config: $result
";
// TODO: Add one more chained ?? example of your own and explain it in your report.
+$user_color = null;
+$session_color = null;
+$theme_default = "dark-mode";
+$final_theme = $user_color ?? $session_color ?? $theme_default;
+echo "Active Theme: $final_theme
";
+?>
\ No newline at end of file
diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php
index b03e13c..daf43cc 100644
--- a/starter/lab3_task2.php
+++ b/starter/lab3_task2.php
@@ -7,11 +7,11 @@
* 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 [Tim Kiplimo]
+ * @student [ENE212-0063/2021]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [3/04/2026]
*/
// ── Test Data Set A (change values to run other test sets) ─────────────────
@@ -64,3 +64,83 @@
// 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
+
+ 0 counts as attended)
+$cats_array = [$cat1, $cat2, $cat3, $cat4];
+$cats_attended = 0;
+foreach ($cats_array as $score) {
+ if ($score > 0) {
+ $cats_attended++;
+ }
+}
+
+echo "Student Results
";
+echo "Total Score: $total / 100
";
+echo "CATs Attended: $cats_attended
";
+
+// 3. Eligibility Rule (NESTED IF)
+if ($cats_attended >= 3 && $exam >= 20) {
+
+ // 4. Grade Rules (if-elseif-else, highest first)
+ if ($total >= 70) {
+ $grade = "A";
+ $desc = "Distinction";
+ } elseif ($total >= 65) {
+ $grade = "B+";
+ $desc = "Credit Upper";
+ } elseif ($total >= 60) {
+ $grade = "B";
+ $desc = "Credit Lower";
+ } elseif ($total >= 55) {
+ $grade = "C+";
+ $desc = "Pass Upper";
+ } elseif ($total >= 50) {
+ $grade = "C";
+ $desc = "Pass Lower";
+ } elseif ($total >= 40) {
+ $grade = "D";
+ $desc = "Marginal Pass";
+ } else {
+ $grade = "E";
+ $desc = "Fail";
+ }
+
+ // 5. Supplementary Rule (TERNARY)
+ $supp_status = ($grade === "D") ? "Eligible for Supplementary Exam" : "Not eligible for supplementary";
+
+ // Output Results
+ echo "GRADE: $grade ($desc)
";
+ echo "Status: $supp_status
";
+
+} else {
+ // Failure of Eligibility Gate
+ echo "DISQUALIFIED — Exam conditions not met
";
+}
+?>
\ No newline at end of file
diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php
index d9e00c8..4188057 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 [Tim Kiplimo]
+ * @student [ENE212-0063/2021]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [3/04/2026]
*/
// ══════════════════════════════════════════════════════════════
@@ -18,6 +18,20 @@
// Group Saturday and Sunday under "Weekend".
// All weekdays print their name and "— Lecture day".
// Remember: break is NOT optional. Missing break = fall-through.
+// --- Exercise A: Day of Week Classifier ---
+echo "Exercise A: Day Classifier
";
+$day = 3; // Test with 1-7
+
+switch ($day) {
+ case 1: echo "Monday — Lecture day
"; break;
+ case 2: echo "Tuesday — Lecture day
"; break;
+ case 3: echo "Wednesday — Lecture day
"; break;
+ case 4: echo "Thursday — Lecture day
"; break;
+ case 5: echo "Friday — Lecture day
"; break;
+ case 6:
+ case 7: echo "Weekend
"; break;
+ default: echo "Invalid Day
";
+}
$day = 3; // change this to test all cases
@@ -40,6 +54,20 @@
$status_code = 404;
// TODO: switch-case for HTTP status
+// --- Exercise B: HTTP Status Code (Switch) ---
+echo "Exercise B: HTTP Switch
";
+$status_code = "200";
+
+switch ($status_code) {
+ case 200: echo "200: OK
"; break;
+ case 301: echo "301: Moved Permanently
"; break;
+ case 400: echo "400: Bad Request
"; break;
+ case 401: echo "401: Unauthorized
"; break;
+ case 403: echo "403: Forbidden
"; break;
+ case 404: echo "404: Not Found
"; break;
+ case 500: echo "500: Internal Server Error
"; break;
+ default: echo "Unknown Status Code
";
+}
// ══════════════════════════════════════════════════════════════
@@ -50,7 +78,20 @@
// Observe the difference in syntax and behaviour.
// TODO: match expression for HTTP status — same logic as Exercise B
-
+// --- Exercise C: PHP 8 Match Rewrite ---
+echo "Exercise C: HTTP Match Expression
";
+// Note: Match returns a value, so we assign it or echo it directly
+$message = match ($status_code) {
+ 200 => "200: OK",
+ 301 => "301: Moved Permanently",
+ 400 => "400: Bad Request",
+ 401 => "401: Unauthorized",
+ 403 => "403: Forbidden",
+ 404 => "404: Not Found",
+ 500 => "500: Internal Server Error",
+ default => "Unknown Status Code",
+};
+echo "$message
";
// ══════════════════════════════════════════════════════════════
// EXERCISE D — Rewrite comparison
diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php
index 2a3d225..6aec4bb 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 [Tim Kiplimo]
+ * @student [ENE212-0063/2021]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [3/04/2026]
*/
// ── Problem: Student Loan Eligibility System ───────────────────────────────
@@ -57,3 +57,60 @@
// 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
+
+// --- TEST DATA SETS ---
+// Set A: Expected "Partial 75% | New"
+//$enrolled = true; $gpa = 3.1; $income = 180000; $prev_loan = false;
+
+// Set B: Expected "GPA fail"
+//$enrolled = true; $gpa = 1.8; $income = 80000; $prev_loan = false;
+
+// Set C: Expected "Not enrolled"
+//$enrolled = false; $gpa = 3.5; $income = 60000; $prev_loan = true;
+
+// Set D: Expected "Income fail"
+// $enrolled = true; $gpa = 2.5; $income = 600000; $prev_loan = true;
+
+// Set E: Expected "Full | Renewal"
+$enrolled = true; $gpa = 2.0; $income = 50000; $prev_loan = true;
+
+
+echo "HELB Loan Eligibility Results
";
+
+// OUTER CHECK — Enrollment
+if ($enrolled === true) {
+
+ // INNER CHECK 1 — GPA
+ if ($gpa >= 2.0) {
+
+ // INNER CHECK 2 — Household Income
+ if ($income < 100000) {
+ $loan_status = "Full loan";
+ $eligible = true;
+ } elseif ($income < 250000) {
+ $loan_status = "Partial 75%";
+ $eligible = true;
+ } elseif ($income < 500000) {
+ $loan_status = "Partial 50%";
+ $eligible = true;
+ } else {
+ $loan_status = "Not eligible — High income";
+ $eligible = false;
+ }
+
+ // TERNARY — Renewal vs New (Only if eligible)
+ if ($eligible) {
+ $app_type = ($prev_loan) ? "Renewal application" : "New application";
+ echo "Status: $loan_status | $app_type";
+ } else {
+ echo "$loan_status";
+ }
+
+ } else {
+ echo "Not eligible — GPA below minimum (GPA fail)";
+ }
+
+} else {
+ echo "Not eligible — must be an active student (Not enrolled)";
+}
+?>
\ No newline at end of file