diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php
index f396a7e..1492806 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 [Joseph Mwaura Thuo]
+ * @student [ENE212-0149/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [7-04-2026]
*/
// ══════════════════════════════════════════════════════════════
@@ -21,7 +21,26 @@
// Test with: 36.8, 39.2, 34.5 — screenshot each
// TODO: Exercise A — your code here
+
+echo "
Lab 3 - Task 1
";
+// --- EXERCISE A: Temperature Alert System ---
+echo "Exercise A
";
+$temperature = 39.2; // Test with 36.8, 39.2, 34.5
+
+echo "Current Temp: $temperature °C
";
+
+if ($temperature >= 36.1 && $temperature <= 37.5) {
+ echo "Status: Normal
";
+}
+if ($temperature > 37.5) {
+ echo "Status: Fever
";
+}
+if ($temperature < 36.1) {
+ echo "Status: Hypothermia Warning
";
+}
+
+echo "
";
// ══════════════════════════════════════════════════════════════
// EXERCISE B — Even or Odd
@@ -32,6 +51,22 @@
// TODO: Exercise B — your code here
+// --- EXERCISE B: Even or Odd ---
+echo "Exercise B
";
+$number = 47;
+
+if ($number % 2 == 0) {
+ echo "$number is EVEN
";
+} else {
+ echo "$number is ODD
";
+}
+
+// Divisibility checks
+if ($number % 3 == 0) { echo "$number is divisible by 3
"; } else { echo "$number is NOT divisible by 3
"; }
+if ($number % 5 == 0) { echo "$number is divisible by 5
"; } else { echo "$number is NOT divisible by 5
"; }
+if ($number % 3 == 0 && $number % 5 == 0) { echo "$number is divisible by BOTH 3 and 5
"; } else { echo "$number is NOT divisible by both
"; }
+
+echo "
";
// ══════════════════════════════════════════════════════════════
// EXERCISE C — Comparison Chain
@@ -68,3 +103,9 @@
echo "Config: $result
";
// TODO: Add one more chained ?? example of your own and explain it in your report.
+$user_upload = null;
+$avatar_link = "cool_avatar.png";
+$placeholder = "no_image.jpg";
+
+$final_image = $user_upload ?? $avatar_link ?? $placeholder;
+echo "Profile Picture selected: $final_image
";
\ No newline at end of file
diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php
index b03e13c..66f1a32 100644
--- a/starter/lab3_task2.php
+++ b/starter/lab3_task2.php
@@ -7,15 +7,15 @@
* 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 [Joseph Mwaura Thuo]
+ * @student [ENE212-0149/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [Date 07-04-2026]
*/
// ── Test Data Set A (change values to run other test sets) ─────────────────
-$name = "Your Name";
+$name = "Joseph Mwaura";
$cat1 = 8; // out of 10
$cat2 = 7; // out of 10
$cat3 = 9; // out of 10
@@ -44,19 +44,105 @@
// 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
+$eligible = false;
+$grade = "N/A";
+$remark = "N/A";
+$supp_status = "N/A";
+
+if ($cats_attended >= 3) {
+ if ($exam >= 20) {
+ $eligible = true;
+
+ // Grade classification (Highest first)
+ if ($total >= 70) {
+ $grade = "A";
+ $remark = "Distinction";
+ } elseif ($total >= 65) {
+ $grade = "B+";
+ $remark = "Credit Upper";
+ } elseif ($total >= 60) {
+ $grade = "B";
+ $remark = "Credit Lower";
+ } elseif ($total >= 55) {
+ $grade = "C+";
+ $remark = "Pass Upper";
+ } elseif ($total >= 50) {
+ $grade = "C";
+ $remark = "Pass Lower";
+ } elseif ($total >= 40) {
+ $grade = "D";
+ $remark = "Marginal Pass";
+ } else {
+ $grade = "E";
+ $remark = "Fail";
+ }
+
+ // Supplementary Rule (Ternary)
+ $supp_status = ($grade == "D") ? "Eligible for Supplementary Exam" : "Not eligible for supplementary";
+ }
+}
+
// ── 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
+?>
+
+
+
+
+
+
+
+
+ Student Report Card
+
+
+
Name:
+
Reg No:
+
CAT Scores:
+
Exam Score:
+
CATs Attended:
/ 4
+
+
+
+
+
Total Score: / 100
+
Grade: ()
+
Status:
+
+
ELIGIBILITY STATUS: DISQUALIFIED — Exam conditions not met
+
(Reason: Must attend 3+ CATs and score 20+ in Exam)
+
+
+
+
+
+
// ── Required Test Data Sets — screenshot each ─────────────────────────────
// Set A: cat1=8, cat2=7, cat3=9, cat4=6, exam=52 → expect grade B
@@ -64,3 +150,4 @@
// 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..fa3b2bd 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 [Joseph Mwaura]
+ * @student [ENE212-0149/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [07-04-2026]
*/
// ══════════════════════════════════════════════════════════════
@@ -22,6 +22,21 @@
$day = 3; // change this to test all cases
// TODO: switch-case for day classifier
+$day = 3;
+
+echo "Exercise A: Day Classifier
";
+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 number"; break;
+}
+
+echo "
";
// ══════════════════════════════════════════════════════════════
@@ -41,6 +56,22 @@
// TODO: switch-case for HTTP status
+$status_code = 404;
+
+echo "Exercise B: HTTP Status (Switch)
";
+switch ($status_code) {
+ case 200: echo "200: OK — request succeeded"; break;
+ case 301: echo "301: Moved Permanently — resource relocated"; break;
+ case 400: echo "400: Bad Request — client error"; break;
+ case 401: echo "401: Unauthorized — authentication required"; break;
+ case 403: echo "403: Forbidden — access denied"; break;
+ case 404: echo "404: Not Found — resource missing"; break;
+ case 500: echo "500: Internal Server Error — server fault"; break;
+ default: echo "Unknown status code"; break;
+}
+
+echo "
";
+
// ══════════════════════════════════════════════════════════════
// EXERCISE C — PHP 8 match Expression
@@ -51,6 +82,21 @@
// TODO: match expression for HTTP status — same logic as Exercise B
+echo "Exercise C: HTTP Status (Match)
";
+
+$message = match ($status_code) {
+ 200 => "200: OK — request succeeded",
+ 301 => "301: Moved Permanently — resource relocated",
+ 400 => "400: Bad Request — client error",
+ 401 => "401: Unauthorized — authentication required",
+ 403 => "403: Forbidden — access denied",
+ 404 => "404: Not Found — resource missing",
+ 500 => "500: Internal Server Error — server fault",
+ default => "Unknown status code",
+};
+
+echo $message;
+
// ══════════════════════════════════════════════════════════════
// EXERCISE D — Rewrite comparison
diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php
index 2a3d225..a756001 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 [Joseph Mwaura]
+ * @student [ENE212-0149/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
- * @date [Date completed]
+ * @date [07-04-2023]
*/
// ── Problem: Student Loan Eligibility System ───────────────────────────────
@@ -46,10 +46,62 @@
// ── STEP 1: Outer enrollment check ────────────────────────────────────────
// TODO: nested if structure implementing all rules above
+echo "HELB Loan Eligibility System
";
+
+// ── STEP 1 & 2: Nested Logic and Display ──────────────────────────────────
+
+// OUTER CHECK
+if ($enrolled === true) {
+
+ // INNER CHECK 1: GPA
+ if ($gpa >= 2.0) {
+
+ // INNER CHECK 2: Household Income
+ $is_eligible = true;
+ 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";
+ $is_eligible = false;
+ }
+
+ // ADDITIONAL RULE: Ternary for renewal vs new
+ if ($is_eligible) {
+ $app_type = ($previous_loan === true) ? " | Renewal application" : " | New application";
+ $final_result = $decision . $app_type;
+ } else {
+ $final_result = $decision;
+ }
+
+ } else {
+ $final_result = "Not eligible — GPA below minimum (2.0)";
+ }
+
+} else {
+ $final_result = "Not eligible — must be an active student";
+}
// ── STEP 2: Display result ────────────────────────────────────────────────
// TODO: output formatted result showing all input values and the decision
+// ── OUTPUT FORMATTED RESULT ───────────────────────────────────────────────
+?>
+
+
+
Application Details
+
Enrolled:
+
GPA:
+
Annual Income: KES
+
Previous Loan:
+
+
FINAL DECISION:
+
+
+
// ── Required Test Data Sets — screenshot each ─────────────────────────────
// Set A: enrolled=true, gpa=3.1, income=180000, previous=false → Partial 75%