diff --git a/starter/lab3_task1.php b/starter/lab3_task1.php index f396a7e..00525ba 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 [MUTWIRI KELVIN MWENDA] + * @student [ENE212-0067/2023] * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date [4TH APRIL 2026] */ // ══════════════════════════════════════════════════════════════ @@ -21,7 +21,17 @@ // Test with: 36.8, 39.2, 34.5 — screenshot each // TODO: Exercise A — your code here +$temperature = 34.5; +if ($temperature >= 36.1 && $temperature <= 37.5) { + echo "Normal
"; +} +if ($temperature > 37.5) { + echo "Fever
"; +} +if ($temperature < 36.1) { + echo "Hypothermia Warning
"; +} // ══════════════════════════════════════════════════════════════ // EXERCISE B — Even or Odd @@ -32,6 +42,25 @@ // TODO: Exercise B — your code here +$number = 47; + +if ($number % 2 == 0) { + echo "$number is EVEN
"; +} else { + echo "$number is ODD
"; +} + +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 @@ -68,3 +97,10 @@ echo "Config: $result
"; // TODO: Add one more chained ?? example of your own and explain it in your report. +$cloudinary_api_url = null; // Primary source: Imagine the API didn't return an image +$local_upload_url = null; // Secondary source: Imagine no local file was uploaded either +$placeholder_image = "default_avatar.jpg"; // Fallback source + +$final_image_to_load = $cloudinary_api_url ?? $local_upload_url ?? $placeholder_image; + +echo "Image source to load: $final_image_to_load
"; \ No newline at end of file diff --git a/starter/lab3_task2.php b/starter/lab3_task2.php index b03e13c..f8a5daa 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 [MUTWIRI KELVIN MWENDA] + * @student [ENE212-0067/2023] * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date [4TH APRIL 2026] */ // ── Test Data Set A (change values to run other test sets) ───────────────── -$name = "Your Name"; +$name = "MUTWIRI KELVIN MWENDA"; $cat1 = 8; // out of 10 $cat2 = 7; // out of 10 $cat3 = 9; // out of 10 @@ -42,21 +42,55 @@ // ── 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 — determine grade + if ($total >= 70) { + $grade = "A"; + } elseif ($total >= 65) { + $grade = "B+"; + } elseif ($total >= 60) { + $grade = "B"; + } elseif ($total >= 55) { + $grade = "C+"; + } elseif ($total >= 50) { + $grade = "C"; + } elseif ($total >= 40) { + $grade = "D"; + } else { + $grade = "E"; + } +} else { + // Not eligible + $grade = "DISQUALIFIED — Exam conditions not met"; +} +$supplementary_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 - +echo "

JKUAT Grade Report Card

"; +echo "

Student Name: $name

"; +echo "

CAT Scores: $cat1, $cat2, $cat3, $cat4

"; +echo "

Exam Score: $exam

"; +echo "

Total: $total

"; +echo "

CATs Attended: $cats_attended

"; +echo "

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

"; +echo "

Grade: $grade

"; +echo "

Supplementary Status: $supplementary_status

"; // ── Required Test Data Sets — screenshot each ───────────────────────────── // Set A: cat1=8, cat2=7, cat3=9, cat4=6, exam=52 → expect grade B diff --git a/starter/lab3_task3.php b/starter/lab3_task3.php index d9e00c8..532559a 100644 --- a/starter/lab3_task3.php +++ b/starter/lab3_task3.php @@ -3,16 +3,16 @@ * 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 [MUTWIRI KELVIN MWENDA] + * @student [ENE212-0067/2023] * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date [4TH APRIL 2026] */ // ══════════════════════════════════════════════════════════════ // EXERCISE A — Day of Week Classifier -// ══════════════════════════════════════════════════════════════ +// ══════════════════════════════════════════════════════ // Given $day (integer 1–7, where 1=Monday): // Use switch-case to print the day name. // Group Saturday and Sunday under "Weekend". @@ -22,8 +22,30 @@ $day = 3; // change this to test all cases // TODO: switch-case for 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"; +} +echo "
"; // ══════════════════════════════════════════════════════════════ // EXERCISE B — HTTP Status Code Explainer // ══════════════════════════════════════════════════════════════ @@ -40,8 +62,32 @@ $status_code = 404; // TODO: switch-case for HTTP status - - +switch ($status_code){ + case 200: + echo "OK — request succeeded"; + break; + case 301: + echo "Moved Permanently — resource relocated"; + break; + case 400: + echo "Bad Request — client error"; + break; + case 401: + echo "Unauthorized — authentication required"; + break; + case 403: + echo "Forbidden — access denied"; + break; + case 404: + echo "Not Found — resource missing"; + break; + case 500: + echo "Internal Server Error — server fault"; + break; + default: + echo "Unknown status code"; +} +echo "
"; // ══════════════════════════════════════════════════════════════ // EXERCISE C — PHP 8 match Expression // ══════════════════════════════════════════════════════════════ @@ -50,7 +96,17 @@ // Observe the difference in syntax and behaviour. // TODO: match expression for HTTP status — same logic as Exercise B - +$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 . "
" ; // ══════════════════════════════════════════════════════════════ // EXERCISE D — Rewrite comparison diff --git a/starter/lab3_task4.php b/starter/lab3_task4.php index 2a3d225..c80caec 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 [MUTWIRI KELVIN MWENDA] + * @student [ENE212-0067/2023] * @lab Lab 3 of 14 * @unit ICS 2371 - * @date [Date completed] + * @date [4TH APRIL 2026] */ // ── Problem: Student Loan Eligibility System ─────────────────────────────── @@ -45,12 +45,43 @@ // ── STEP 1: Outer enrollment check ──────────────────────────────────────── // TODO: nested if structure implementing all rules above +$decision = ""; - +if ($enrolled) { + // INNER CHECK 1 — GPA requirement (if enrolled) + if ($gpa >= 2.0) { + + // Ternary for renewal vs new application (evaluated before assigning eligibility) + $app_type = $previous_loan ? " | Renewal application" : " | New application"; + + // INNER CHECK 2 — Household income bracket (if enrolled AND GPA >= 2.0) + if ($annual_income < 100000) { + $decision = "Eligible — Full loan award" . $app_type; + } elseif ($annual_income < 250000) { + $decision = "Eligible — Partial loan (75%)" . $app_type; + } elseif ($annual_income < 500000) { + $decision = "Eligible — Partial loan (50%)" . $app_type; + } else { + $decision = "Not eligible — household income exceeds threshold"; + } + + } else { + $decision = "Not eligible — GPA below minimum (2.0)"; + } +} else { + $decision = "Not eligible — must be an active student"; +} // ── STEP 2: Display result ──────────────────────────────────────────────── // TODO: output formatted result showing all input values and the decision +$enrolled_display = $enrolled ? "Yes" : "No"; +$previous_display = $previous_loan ? "Yes" : "No"; - +echo "

HELB Loan Application Status

"; +echo "Enrolled: " . $enrolled_display . "
"; +echo "GPA: " . $gpa . "
"; +echo "Annual Income: KES " . number_format($annual_income) . "
"; +echo "Previous Loan: " . $previous_display . "

"; +echo "DECISION: " . $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