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
62 changes: 57 additions & 5 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 [SUNDRA EVANS]
* @student [ENE212-0148/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date [03/04/2026]
*/

// ══════════════════════════════════════════════════════════════
Expand All @@ -20,8 +20,19 @@
// "Hypothermia Warning" if temp < 36.1
// Test with: 36.8, 39.2, 34.5 — screenshot each

// TODO: Exercise A — your code here
$temperature = 36.8;
echo "Temperature: $temperature °C<br>";
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>";
}

echo "<br>";

// ══════════════════════════════════════════════════════════════
// EXERCISE B — Even or Odd
Expand All @@ -30,8 +41,37 @@
// Use if-else to print "$number is EVEN" or "$number is ODD"
// Also check divisibility by 3, by 5, and by both 3 and 5 — one line each

// TODO: Exercise B — your code here
$number = 47;

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

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

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

// Divisible by both 3 and 5
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 3 and 5<br>";
}

echo "<br>";

// ══════════════════════════════════════════════════════════════
// EXERCISE C — Comparison Chain
Expand All @@ -48,6 +88,9 @@
var_dump($y === $z); // E: ?
var_dump($x <=> $y); // F: spaceship — what type? what value?

echo "<br>";
echo "<br>";

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


Expand All @@ -60,11 +103,20 @@
$display = $username ?? "Guest";
echo "Welcome, $display<br>";

echo "<br>";

// Chained null coalescing
$config_val = null;
$env_val = null;
$default = "system_default";
$result = $config_val ?? $env_val ?? $default;
echo "Config: $result<br>";

echo "<br>";

// TODO: Add one more chained ?? example of your own and explain it in your report.
$input_name = null;
$cookie_name = null;
$session_name = "Mwenda";
$final_name = $input_name ?? $cookie_name ?? $session_name ?? "Anonymous";
echo "User: $final_name<br>";
254 changes: 236 additions & 18 deletions starter/lab3_task2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,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 [SUNDRA EVANS]
* @student [ENE212-0148/2023]
* @lab Lab 3 of 14
* @unit ICS 2371
* @date [Date completed]
* @date [03/04/2026]
*/

// ── 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 = "Sundra Evans";
$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 @@ -41,26 +41,244 @@
// Otherwise: "Not eligible for supplementary"

// ── 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
$eligible = 'Disqualified';
$grade = 'N/A';
$description = 'DISQUALIFIED';
$remark = 'Exam conditions not met';
$supplementary = 'Not eligible for supplementary';

if ($cats_attended >= 3 && $exam >= 20) {
$eligible = 'Eligible';
// Grade using if-elseif-else, highest first
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';
} elseif ($total >= 40) {
$grade = 'D'; $description = 'Marginal Pass';
} else {
$grade = 'E'; $description = 'Fail';
}

$supplementary = ($grade === 'D')
? 'Eligible for Supplementary Exam'
: 'Not eligible for supplementary';

$status = "Grade {$grade} — {$description}";
$remark = $description;


} else {

$eligible = 'Disqualified';
$grade = 'N/A';
$description = 'DISQUALIFIED';
$remark = 'Exam conditions not met';
$supplementary = 'Not eligible for supplementary';
$status = 'DISQUALIFIED — Exam conditions not met';
}


// ── 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 lang="en">
<head>
<meta charset="UTF-8">
<title>Student Report Card</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f0f2f5;
display: flex;
justify-content: center;
padding: 40px 20px;
}

.card {
background: white;
width: 480px;
border-radius: 8px;
box-shadow: 0 2px 12px rgba(0,0,0,0.12);
overflow: hidden;
}

.card-header {
background: #1a3a5c;
color: white;
padding: 24px;
text-align: center;
}

.card-header h2 {
margin: 0 0 4px 0;
font-size: 20px;
}

.card-header p {
margin: 0;
font-size: 13px;
opacity: 0.75;
}

.card-body {
padding: 24px;
}

.student-name {
text-align: center;
font-size: 18px;
font-weight: bold;
color: #1a3a5c;
margin-bottom: 20px;
}

table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}

td {
padding: 10px 12px;
border-bottom: 1px solid #eee;
}

td:first-child {
color: #666;
width: 55%;
}

td:last-child {
font-weight: 500;
color: #1a1a1a;
text-align: right;
}

.section-label {
background: #f8f9fa;
font-size: 11px;
letter-spacing: 1px;
text-transform: uppercase;
color: #999;
padding: 8px 12px;
font-weight: bold;
}

.grade-box {
text-align: center;
margin: 24px 0 8px;
padding: 16px;
background: #f0f4ff;
border-radius: 6px;
}

.grade-letter {
font-size: 48px;
font-weight: bold;
color: #1a3a5c;
line-height: 1;
}

.grade-remark {
font-size: 14px;
color: #555;
margin-top: 6px;
}

.status-badge {
display: inline-block;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: bold;
}

.status-eligible { background: #d4edda; color: #1e6b3a; }
.status-disqualified { background: #f8d7da; color: #8b1a1a; }
.status-supp-yes { background: #fff3cd; color: #856404; }
.status-supp-no { background: #e2e3e5; color: #495057; }
</style>
</head>
<body>
<div class="card">

<div class="card-header">
<h2>JKUAT — Student Report Card</h2>
<p>Academic Performance Summary</p>
</div>

<div class="card-body">

<div class="student-name"><?php echo $name; ?></div>

<table>
<!-- CAT Scores -->
<tr><td colspan="2" class="section-label">CAT Scores</td></tr>
<tr><td>CAT 1</td><td><?php echo $cat1; ?> / 10</td></tr>
<tr><td>CAT 2</td><td><?php echo $cat2; ?> / 10</td></tr>
<tr><td>CAT 3</td><td><?php echo $cat3; ?> / 10</td></tr>
<tr><td>CAT 4</td><td><?php echo $cat4; ?> / 10</td></tr>

<!-- Exam & Totals -->
<tr><td colspan="2" class="section-label">Exam &amp; Totals</td></tr>
<tr><td>Final Exam</td><td><?php echo $exam; ?> / 60</td></tr>
<tr><td>Total Score</td><td><?php echo $total; ?> / 100</td></tr>
<tr><td>CATs Attended</td><td><?php echo $cats_attended; ?> / 4</td></tr>

<!-- Status -->
<tr><td colspan="2" class="section-label">Status</td></tr>
<tr>
<td>Eligibility</td>
<td>
<?php
$badge = ($eligible === 'Eligible') ? 'status-eligible' : 'status-disqualified';
echo "<span class='status-badge $badge'>$eligible</span>";
?>
</td>
</tr>
<tr>
<td>Supplementary</td>
<td>
<?php
$sbadge = ($supplementary === 'Eligible for Supplementary') ? 'status-supp-yes' : 'status-supp-no';
echo "<span class='status-badge $sbadge'>$supplementary</span>";
?>
</td>
</tr>
</table>

<!-- Grade box -->
<div class="grade-box">
<div class="grade-letter"><?php echo $grade; ?></div>
<div class="grade-remark"><?php echo $remark; ?></div>
</div>

</div>
</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
Loading
Loading