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
47 changes: 44 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 [Joseph Mwaura Thuo]
* @student [ENE212-0149/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date [7-04-2026]
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -21,7 +21,26 @@
// Test with: 36.8, 39.2, 34.5 — screenshot each

// TODO: Exercise A — your code here

echo "<h1>Lab 3 - Task 1</h1>";

// --- EXERCISE A: Temperature Alert System ---
echo "<h2>Exercise A</h2>";
$temperature = 39.2; // Test with 36.8, 39.2, 34.5

echo "Current Temp: $temperature °C<br>";

if ($temperature >= 36.1 && $temperature <= 37.5) {
echo "Status: Normal<br>";
}
if ($temperature > 37.5) {
echo "Status: Fever<br>";
}
if ($temperature < 36.1) {
echo "Status: Hypothermia Warning<br>";
}

echo "<hr>";

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

// TODO: Exercise B — your code here

// --- EXERCISE B: Even or Odd ---
echo "<h2>Exercise B</h2>";
$number = 47;

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

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

echo "<hr>";

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

// 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<br>";
95 changes: 91 additions & 4 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 [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
Expand Down Expand Up @@ -44,23 +44,110 @@
// 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

?>

<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 20px auto; border: 1px solid #ccc; padding: 20px; border-radius: 8px; }
h1 { color: #2c3e50; border-bottom: 2px solid #2c3e50; padding-bottom: 10px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.label { font-weight: bold; }
.result-box { background: #f9f9f9; padding: 15px; border-left: 5px solid #2c3e50; }
.disqualified { color: #c0392b; font-weight: bold; border-left-color: #c0392b; }
</style>
</head>
<body>

<h1>Student Report Card</h1>

<div class="stat-grid">
<div class="label">Name:</div> <div><?php echo $name; ?></div>
<div class="label">Reg No:</div> <div><?php echo $reg_no; ?></div>
<div class="label">CAT Scores:</div> <div><?php echo "$cat1, $cat2, $cat3, $cat4"; ?></div>
<div class="label">Exam Score:</div> <div><?php echo $exam; ?></div>
<div class="label">CATs Attended:</div> <div><?php echo $cats_attended; ?> / 4</div>
</div>

<div class="result-box <?php echo !$eligible ? 'disqualified' : ''; ?>">
<?php if ($eligible): ?>
<p><span class="label">Total Score:</span> <?php echo $total; ?> / 100</p>
<p><span class="label">Grade:</span> <?php echo $grade; ?> (<?php echo $remark; ?>)</p>
<p><span class="label">Status:</span> <?php echo $supp_status; ?></p>
<?php else: ?>
<p>ELIGIBILITY STATUS: DISQUALIFIED — Exam conditions not met</p>
<p><small>(Reason: Must attend 3+ CATs and score 20+ in Exam)</small></p>
<?php endif; ?>
</div>

</body>
</html>


// ── 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)
// 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

52 changes: 49 additions & 3 deletions starter/lab3_task3.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 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]
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -22,6 +22,21 @@
$day = 3; // change this to test all cases

// TODO: switch-case for day classifier
$day = 3;

echo "<h3>Exercise A: Day Classifier</h3>";
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 "<hr>";


// ══════════════════════════════════════════════════════════════
Expand All @@ -41,6 +56,22 @@

// TODO: switch-case for HTTP status

$status_code = 404;

echo "<h3>Exercise B: HTTP Status (Switch)</h3>";
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 "<hr>";


// ══════════════════════════════════════════════════════════════
// EXERCISE C — PHP 8 match Expression
Expand All @@ -51,6 +82,21 @@

// TODO: match expression for HTTP status — same logic as Exercise B

echo "<h3>Exercise C: HTTP Status (Match)</h3>";

$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
Expand Down
58 changes: 55 additions & 3 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 [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 ───────────────────────────────
Expand Down Expand Up @@ -46,10 +46,62 @@
// ── STEP 1: Outer enrollment check ────────────────────────────────────────
// TODO: nested if structure implementing all rules above

echo "<h1>HELB Loan Eligibility System</h1>";

// ── 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 ───────────────────────────────────────────────
?>

<div style="font-family: sans-serif; border: 2px solid #34495e; padding: 20px; max-width: 500px;">
<h3>Application Details</h3>
<p><strong>Enrolled:</strong> <?php echo $enrolled ? 'Yes' : 'No'; ?></p>
<p><strong>GPA:</strong> <?php echo $gpa; ?></p>
<p><strong>Annual Income:</strong> KES <?php echo number_format($annual_income); ?></p>
<p><strong>Previous Loan:</strong> <?php echo $previous_loan ? 'Yes' : 'No'; ?></p>
<hr>
<p><strong>FINAL DECISION:</strong><br>
<span style="color: #2980b9; font-size: 1.2em;"><?php echo $final_result; ?></span>
</p>
</div>

// ── Required Test Data Sets — screenshot each ─────────────────────────────
// Set A: enrolled=true, gpa=3.1, income=180000, previous=false → Partial 75%
Expand Down
Loading