Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions starter/lab3_task1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -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<br>";
}
if ($temperature > 37.5) {
echo "Fever<br>";
}
if ($temperature < 36.1) {
echo "Hypothermia Warning<br>";
}

// ══════════════════════════════════════════════════════════════
// EXERCISE B — Even or Odd
Expand All @@ -32,6 +42,25 @@

// TODO: Exercise B — your code here

$number = 47;

if ($number % 2 == 0) {
echo "$number is EVEN<br>";
} else {
echo "$number is ODD<br>";
}

if ($number % 3 == 0) {
echo "$number is divisible by 3<br>";
}

if ($number % 5 == 0) {
echo "$number is divisible by 5<br>";
}

if ($number % 3 == 0 && $number % 5 == 0) {
echo "$number is divisible by both 3 and 5<br>";
}

// ══════════════════════════════════════════════════════════════
// EXERCISE C — Comparison Chain
Expand Down Expand Up @@ -68,3 +97,10 @@
echo "Config: $result<br>";

// 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<br>";
48 changes: 41 additions & 7 deletions starter/lab3_task2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "<h2>JKUAT Grade Report Card</h2>";
echo "<p><strong>Student Name:</strong> $name</p>";
echo "<p><strong>CAT Scores:</strong> $cat1, $cat2, $cat3, $cat4</p>";
echo "<p><strong>Exam Score:</strong> $exam</p>";
echo "<p><strong>Total:</strong> $total</p>";
echo "<p><strong>CATs Attended:</strong> $cats_attended</p>";
echo "<p><strong>Eligibility Status:</strong> " . ($cats_attended >= 3 && $exam >= 20 ? "Eligible" : "Not Eligible") . "</p>";
echo "<p><strong>Grade:</strong> $grade</p>";
echo "<p><strong>Supplementary Status:</strong> $supplementary_status</p>";

// ── Required Test Data Sets — screenshot each ─────────────────────────────
// Set A: cat1=8, cat2=7, cat3=9, cat4=6, exam=52 → expect grade B
Expand Down
74 changes: 65 additions & 9 deletions starter/lab3_task3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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 "<br>";
// ══════════════════════════════════════════════════════════════
// EXERCISE B — HTTP Status Code Explainer
// ══════════════════════════════════════════════════════════════
Expand All @@ -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 "<br>";
// ══════════════════════════════════════════════════════════════
// EXERCISE C — PHP 8 match Expression
// ══════════════════════════════════════════════════════════════
Expand All @@ -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 . "<br>" ;

// ══════════════════════════════════════════════════════════════
// EXERCISE D — Rewrite comparison
Expand Down
41 changes: 36 additions & 5 deletions starter/lab3_task4.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ───────────────────────────────
Expand Down Expand Up @@ -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 "<h2>HELB Loan Application Status</h2>";
echo "<strong>Enrolled:</strong> " . $enrolled_display . "<br>";
echo "<strong>GPA:</strong> " . $gpa . "<br>";
echo "<strong>Annual Income:</strong> KES " . number_format($annual_income) . "<br>";
echo "<strong>Previous Loan:</strong> " . $previous_display . "<br><br>";
echo "<strong>DECISION:</strong> " . $decision . "<br><br>";
// ── 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
Expand Down