Skip to content
Open
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
57 changes: 45 additions & 12 deletions starter/lab3_task1.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

/**
* 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 Bramuel Barack Kuloba
* @student ENE212-0150/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 4/3/26
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -22,7 +23,17 @@

// TODO: Exercise A — your code here

$temperature = 36.8;

if ($temperature >= 36.1 && $temperature < 37.5) {
echo "Normal temperature<br>";
}
if ($temperature > 37.5) {
echo "Fever<br>";
}
if ($temperature < 36.1) {
echo "Hypothermia Warning<br>";
}
// ══════════════════════════════════════════════════════════════
// EXERCISE B — Even or Odd
// ══════════════════════════════════════════════════════════════
Expand All @@ -31,22 +42,39 @@
// Also check divisibility by 3, by 5, and by both 3 and 5 — one line each

// 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 . "divisble by 3";
}
if (($number % 5) == 0) {
echo $number . "divisble by 5";
}
if ((($number % 5) == 0) && ($number % 3)) {
echo $number . "divisble by 3";
}


// ══════════════════════════════════════════════════════════════
// EXERCISE C — Comparison Chain
// ══════════════════════════════════════════════════════════════
// Run this code EXACTLY as written.
// Record all six outputs in your report and explain each result.
echo "<hr>";
$x = 10;
$y = "10";
$z = 10.0;

$x = 10; $y = "10"; $z = 10.0;

var_dump($x == $y); // A: ?
var_dump($x === $y); // B: ?
var_dump($x == $z); // C: ?
var_dump($x === $z); // D: ?
var_dump($y === $z); // E: ?
var_dump($x <=> $y); // F: spaceship — what type? what value?
var_dump($x == $y) . "<br>"; // A: ?
var_dump($x === $y) . "<br>"; // B: ?
var_dump($x == $z) . "<br>"; // C: ?
var_dump($x === $z) . "<br>"; // D: ?
var_dump($y === $z) . "<br>"; // E: ?
var_dump($x <=> $y) . "<br>"; // F: spaceship — what type? what value? -->

// Your explanation of each result goes in your PDF report (not here).

Expand All @@ -55,7 +83,7 @@
// EXERCISE D — Null & Default Values
// ══════════════════════════════════════════════════════════════
// Run this code as written, then extend it as instructed below.

echo "<hr>";
$username = null;
$display = $username ?? "Guest";
echo "Welcome, $display<br>";
Expand All @@ -68,3 +96,8 @@
echo "Config: $result<br>";

// TODO: Add one more chained ?? example of your own and explain it in your report.
$class_attendance = null;
$class_default = "Average";
$class_performance = "Poor";
$resultclass = $class_performance ?? $class_attendance ?? $class_default;
echo "Perfomance: $resultclass<br>";
89 changes: 80 additions & 9 deletions starter/lab3_task2.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* ICS 2371 — Lab 3: Control Structures I
* Task 2: JKUAT Grade Classification System [8 marks]
Expand All @@ -7,20 +8,20 @@
* 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 Bramuel Barack Kuloba
* @student ENE212-0150/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 4/3/26
*/

// ── Test Data Set A (change values to run other test sets) ─────────────────
$name = "Your Name";
$cat1 = 8; // out of 10
$cat2 = 7; // out of 10
$cat3 = 9; // out of 10
$cat4 = 6; // out of 10
$exam = 52; // out of 60
$name = "Jane Doe";
$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

// ── Grade Rules (implement using if-elseif-else, ordered highest first) ────
// A (Distinction): Total >= 70
Expand All @@ -42,22 +43,92 @@

// ── 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;
$qualified = false;
if ($cat1 > 0) $cats_attended += 1;
if ($cat2 > 0) $cats_attended += 1;
if ($cat3 > 0) $cats_attended += 1;
if ($cat4 > 0) $cats_attended += 1;
if ($cats_attended >= 3) $qualified = true;


// ── STEP 3: Eligibility check (nested if) ─────────────────────────────────
// TODO: nested if — eligibility → grade classification → supplementary ternary
if ($qualified && ($exam >= 20)) {
$eligibility = "ELIGIBLE";
} else {
$eligibility = "DISQUALIFIED - Exam conditions not met";
};

if ($eligibility == "ELIGIBLE") {

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 = ($grade == "D")
? "Eligible for Supplementary Exam"
: "Not eligible for supplementary";
}
// A (Distinction): Total >= 70
// B+ (Credit Upper): Total >= 65
// B (Credit Lower): Total >= 60
// C+ (Pass Upper): Total >= 55
// C (Pass Lower): Total >= 50
// D (Marginal Pass): Total >= 40
// E (Fail): Total < 40


// ── 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 "<hr>";
echo "<h3>Student Report Card</h3>";

echo "<b>Name:</b> $name<br><br>";

echo "<b>CAT Scores:</b><br>";
echo "CAT1: $cat1<br>";
echo "CAT2: $cat2<br>";
echo "CAT3: $cat3<br>";
echo "CAT4: $cat4<br><br>";

echo "<b>Exam:</b> $exam<br>";
echo "<b>Total:</b> $total<br>";
echo "<b>CATs Attended:</b> $cats_attended<br><br>";

echo "<b>Eligibility:</b> $eligibility<br>";

if ($eligibility == "ELIGIBLE") {
echo "<b>Grade:</b> $grade<br>";
echo "<b>Remark:</b> $remark<br>";
echo "<b>Supplementary:</b> $supplementary<br>";
}
// ── 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)
Expand Down
71 changes: 67 additions & 4 deletions starter/lab3_task3.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

/**
* 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 Bramuel Barack Kuloba
* @student ENE212-0150/203
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 4/2/26
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -22,7 +23,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";
break;
}

// ══════════════════════════════════════════════════════════════
// EXERCISE B — HTTP Status Code Explainer
Expand All @@ -41,6 +65,34 @@

// TODO: switch-case for HTTP status

$status_code = 404;

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";
break;
}

// ══════════════════════════════════════════════════════════════
// EXERCISE C — PHP 8 match Expression
Expand All @@ -50,7 +102,18 @@
// Observe the difference in syntax and behaviour.

// TODO: match expression for HTTP status — same logic as Exercise B
$result = 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 $result;

// ══════════════════════════════════════════════════════════════
// EXERCISE D — Rewrite comparison
Expand Down
Loading
Loading