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
78 changes: 75 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 BRANICE NAFULA
* @student ENE212-0088/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 7TH APRIL 2026
*/

// ══════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -68,3 +68,75 @@
echo "Config: $result<br>";

// TODO: Add one more chained ?? example of your own and explain it in your report.
<?php
echo "<h3>Exercise A - Temperature Alert system</h3>";
$temperatures = [36.8, 39.2, 34.5];
foreach ($temperatures as $temperature) {
echo "Temperature: $temperature C";
if ($temperature >= 36.1 && $temperature <= 37.5) {
echo "normal\n";
}
if ($temperature > 37.5) {
echo "fever\n";
}
if ($temperature < 36.1) {
echo "hypothermia warning\n";
}
echo "<br>";
}
echo "<h3>Exercise B </h3>";
// Even or Odd
$number = 47;
if ($number % 2 == 0) {
echo "$number is EVEN\n";
} else {
echo "$number is ODD\n";
echo "<br>";
}
// Divisibility by 3
if ($number % 3 == 0) {
echo "Divisible by 3\n";
} else {
echo "Not Divisible by 3\n";
echo "<br>";
}
// Divisibity by 5
if ($number % 5 == 0) {
echo "Divisible by 5\n";
} else {
echo "Not Divisible by 5\n";
echo "<br>";
}
// Divisibility by 3 and 5
if ($number % 3 == 0 && $number % 5 == 0) {
echo "Divisible by both 3 and 5\n";
} else {
echo "Not divisible by both 3 and 5\n";
echo "<br>";
}
echo " <h3>Exercise C - Comparison Chain </h3> ";
$x = 10;
$y = "10";
$z = 10.0;
var_dump($x == $y);
var_dump($x === $y);
var_dump($x == $z);
var_dump($x === $z);
var_dump($y === $z);
var_dump($x <=> $y );
echo "<br>";
echo "<h3>Exercise D - Null and Default Values</h3>";
$username = null;
$display = $username ?? "Guest";
echo "welcome, $display<br>";
$config_val = null;
$env_val = null;
$default = "system_default";
$result = $config_val ?? $env_val ?? $default;
echo "Config: $result<br>";
$user_color_pref = null;
$theme_color = null;
$fallback_color = "black";
$final_color = $user_color_pref ?? $theme_color ?? $fallback_color;
echo "Selected Color: $fallback_color";
?>
68 changes: 64 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 BRANICE NAFULA
* @student ENE212-0088/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 7TH APRIL 2026
*/

// ── Test Data Set A (change values to run other test sets) ─────────────────
$name = "Your Name";
$name = "BRANICE NAFULA";
$cat1 = 8; // out of 10
$cat2 = 7; // out of 10
$cat3 = 9; // out of 10
Expand Down Expand Up @@ -64,3 +64,63 @@
// 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
<?php
//input data Set B
$cat1 = 8;
$cat2 = 7;
$cat3 = 9;
$cat4 = 6;
$exam = 45;
// Calculating total score
$total = $cat1 + $cat2 + $cat3 + $cat4 + $exam;
// determining eligibility
$attendance_count = 0;
$scores = [$cat1, $cat2, $cat3, $cat4];
foreach ($scores as $score) {
if ($score > 0) {
$attendance_count++;
}
}
if ($attendance_count >= 3) {
if ($exam >= 20) {
$status = "Qualified";
} else {
$status = "Disqualified - Exam condition not met";
}
} else {
$status = "Disqualified - Exam conditions not met";
}
//Determining the grade
if ($total >= 70) {
$grade = "A";
$description = "Distinction";
} elseif ($total >= 65) {
$grade = "B+";
$description = "Credit Upper";
} elseif ($total >= 60) {
$grade = "B";
$description = "Credit Lower";
} elseif ($total >= 55) {
$grade = "C+";
$description = "Pass Upper";
} elseif ($total >= 50) {
$grade = "C";
$description = "Pass Lower";
} else if ($total >= 40) {
$grade = "D";
$description = "Marginal Pass";
} else {
$grade = "E";
$description = "Fail";
}
//Supplimentary Rule
$supp_status = ($grade === "D")
? "Eligible for supplimentary Exam"
: "Not eligible for supplimentary Exams";
//Displaying Results
echo "<h2>Students Results</h2>";
echo "Total Marks: $total / 100<br>";
echo "Eligibility: $status<br>";
echo "Grade: $grade ($description)<br>";
echo "Supplimentary Status: $supp_status<br>";
?>
74 changes: 71 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 BRANICE NAFULA
* @student ENE212-0088/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 7TH APRIL 2026
*/

// ══════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -59,3 +59,71 @@
// 1. What is the key difference between switch (==) and match (===)?
// 2. Give one example where this difference changes the output.
// 3. When would you prefer switch over match, and why?
<?php
echo "<h3>Exercise A - Day of week classifier</h3>";
$day = 1;
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 "<h3>HTTP status code explainer</h3>";
$status_code = 404;
switch ($status_code){
case 200:
echo "200: OK";
break;
case 301:
echo "301: Moved permanently";
break;
case 400:
echo "400: Bad request";
break;
case 401:
echo "401: Unauthorised";
break;
case 403:
echo "403: Forbidden";
break;
case 404:
echo "404: Not found";
break;
case 500:
echo "500: Internal server error";
break;
default:
echo "Unknown status code";
break;
}
echo "<h3>Exercise C - PHP 8 match</h3>";
$status_code = 404;
$explanation = match ($status_code) {
200 => "OK",
301 => "Moved Permanently",
400 => "Bad Request",
403 => "Forbidden",
404 => "Not Found",
500 => "Internal Server Error",
default => "Unknown Status Code",
};
echo "status $status_code: $explanation";
?>
36 changes: 33 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 BRANICE NAFULA
* @student ENE212-0088/2023
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date 7TH APRIL 2026
*/

// ── Problem: Student Loan Eligibility System ───────────────────────────────
Expand Down Expand Up @@ -57,3 +57,33 @@
// Set C: enrolled=false, gpa=3.5, income=60000, previous=true → Not enrolled
// Set D: enrolled=true, gpa=2.5, income=600000, previous=true → Income fail
// Set E: enrolled=true, gpa=2.0, income=50000, previous=true → Full | Renewal
<?php
echo "<h2>HELB Loan Eligibility Checker</h2>";
$enrolled = true;
$gpa = 3.1;
$annual_income = 180000;
$previous_loan = false;
if (!$enrolled) {
$result = "Not eligible - must be an active student";
} else {
if ($gpa < 2.0) {
$result = "Not eligible - GPA below minimum";
} else {
if ($annual_income < 100000) {
$loan_amount = "Full Loan";
} elseif ($annual_income < 250000) {
$loan_amount = "Partial 75%";
} elseif ($annual_income < 500000) {
$loan_amount = "Partial 50%";
} else {
$loan_amount = null;
}
if ($loan_amount) {
$app_type = ($previous_loan) ?
"Renewal application" : "New application";
$result = "$loan_amount | $app_type";
}
}
}
echo "status: <strong>$result</strong>";
?>