0% found this document useful (0 votes)
7 views10 pages

Algorithm

The document outlines the SmartPark Parking Management System, detailing its algorithm, flowchart, JavaScript source code, and data structure used. It describes the procedures for parking and removing cars, checking parking status, and traversing parked cars, along with their time and space complexities. The system aims to improve accuracy and efficiency in managing parking slots for up to 50 cars.

Uploaded by

vibrazerdeejay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Algorithm

The document outlines the SmartPark Parking Management System, detailing its algorithm, flowchart, JavaScript source code, and data structure used. It describes the procedures for parking and removing cars, checking parking status, and traversing parked cars, along with their time and space complexities. The system aims to improve accuracy and efficiency in managing parking slots for up to 50 cars.

Uploaded by

vibrazerdeejay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SAINT KIZITO SAVE TSS

TRADE: Software Development


ACADEMIC YEAR: 2024–2025

INTEGRATED / SUMMATIVE ASSESSMENT


Data Structure and Algorithm (DSA)

1. PROCEDURE (ALGORITHM)
Algorithm for SmartPark Parking Management System

Start

1. Declare a constant MAX_SLOTS and assign it value 50.


2. Declare an array parkingSlots[50] and initialize all elements to null.
3. Display a menu with the following options:
o Park a car
o Remove a car
o Check parking status
o Traverse parked cars
o Exit
4. If the user selects Park a car:
o Check if the parking is full.
o If parking is not full:
 Input car plate number.
 Record entry time.
 Store the car details in the first available slot.
5. If the user selects Remove a car:
o Input car plate number.
o Search for the car in the array.
o Record exit time.
o Calculate total hours spent.
o Calculate parking fees:
 First hour = 500 Rwf
 Extra hours = 300 Rwf per hour
o Remove the car and free the slot.
6. If the user selects Check parking status:
o Count free and occupied slots.
7. If the user selects Traverse cars:
o Display all parked cars with their slots.
8. Repeat the process until the user selects Exit.
9. Stop

2. FLOWCHART DESCRIPTION (FOR DRAWING)


Flowchart Explanation

1. Start (Oval)
2. Initialize parkingSlots[50] = null (Process)
3. Display Menu (Input/Output)
4. Decision: User choice (Diamond)
5. Decision: Parking Full?
6. Process: Add car / Remove car
7. Process: Calculate parking fee
8. Output: Display results
9. Stop (Oval)

The flowchart shows logical data flow, correct symbols, looping, and finiteness.

3. JAVASCRIPT SOURCE CODE


// Declare maximum parking slots
const MAX_SLOTS = 50;

// Initialize parking slots array to null


let parkingSlots = new Array(MAX_SLOTS).fill(null);

// Function to check if parking is full


function isParkingFull() {
return [Link](slot => slot !== null);
}

// Function to park a car


function parkCar(plateNumber) {
if (isParkingFull()) {
[Link]("Parking is full");
return;
}

for (let i = 0; i < MAX_SLOTS; i++) {


if (parkingSlots[i] === null) {
parkingSlots[i] = {
plate: plateNumber,
entryTime: new Date()
};
[Link]("Car parked at slot " + i);
break;
}
}
}

// Function to remove a car and calculate fee


function removeCar(plateNumber) {
for (let i = 0; i < MAX_SLOTS; i++) {
if (parkingSlots[i] !== null && parkingSlots[i].plate === plateNumber)
{

let exitTime = new Date();


let entryTime = parkingSlots[i].entryTime;

let hoursSpent = [Link](


(exitTime - entryTime) / (1000 * 60 * 60)
);

let totalFee = 500;


if (hoursSpent > 1) {
totalFee += (hoursSpent - 1) * 300;
}

[Link]("Hours spent: " + hoursSpent);


[Link]("Total fee: Rwf " + totalFee);

parkingSlots[i] = null;
return;
}
}
[Link]("Car not found");
}

// Function to check parking status


function checkStatus() {
let freeSlots = [Link](slot => slot === null).length;
[Link]("Free slots: " + freeSlots);
[Link]("Occupied slots: " + (MAX_SLOTS - freeSlots));
}

// Function to traverse parked cars


function traverseCars() {
for (let i = 0; i < MAX_SLOTS; i++) {
if (parkingSlots[i] !== null) {
[Link]("Slot " + i + ": " + parkingSlots[i].plate);
}
}
}

4. DATA STRUCTURE USED


The system uses a Linear Array Data Structure to store parked cars.
Each array index represents a parking slot, and null indicates a free slot.
5. TIME AND SPACE COMPLEXITY
Time Complexity

Operation Complexity
Park a car O(n)
Remove a car O(n)
Check parking status O(n)
Traverse cars O(n)

The array may be scanned up to 50 elements.

Space Complexity

 Parking slots array size = 50


 Space complexity = O(n)

Memory usage is fixed and efficient.

6. CONCLUSION
The computerized SmartPark system improves accuracy, reduces human error, speeds up fee
calculation, and efficiently manages parking slots using arrays, algorithms, and JavaScript
programming.

ALGORITHM IN STRUCTURED
ENGLISH
SMARTPARK PARKING MANAGEMENT SYSTEM
START

DECLARE a constant variable MAX_SLOTS and set it to 50 to represent the maximum number
of cars allowed in the parking area.

DECLARE an array called parkingSlots with 50 positions to store parked cars.

INITIALIZE all positions of parkingSlots to NULL to show that all parking slots are free at the
beginning.

DISPLAY a menu to the user with the following options:

 Park a car
 Remove a car
 Check parking status
 Display all parked cars
 Exit the system

REPEAT the following steps until the user chooses to exit the system:

READ the user’s menu choice.

IF the user chooses Park a Car, THEN


CHECK whether the parking area is full.
IF the parking area is full, THEN
DISPLAY the message “Parking is full”.
ELSE
READ the car plate number from the user.
RECORD the current time as the entry time.
STORE the car details in the first available parking slot.
END IF

ELSE IF the user chooses Remove a Car, THEN


READ the car plate number to be removed.
SEARCH for the car in the parkingSlots array.
RECORD the current time as the exit time.
CALCULATE the total time the car spent in the parking area.
CALCULATE the parking fee as follows:
CHARGE 500 Rwf for the first hour.
ADD 300 Rwf for every extra hour.
DISPLAY the total time spent and the total fee to be paid.
REMOVE the car from the parking slot and mark the slot as free.

ELSE IF the user chooses Check Parking Status, THEN


COUNT the number of free parking slots.
DISPLAY the number of free slots and occupied slots.
ELSE IF the user chooses Display All Parked Cars, THEN
DISPLAY the list of all parked cars together with their parking slot numbers.

END IF

END REPEAT

STOP

✅ WHY THIS VERSION IS VERY GOOD FOR EXAMS


✔ Very clear English
✔ Step-by-step explanation
✔ Shows decisions and repetition
✔ Matches the flowchart and JavaScript code
✔ Easy for examiner to follow

HOW TO EXPLAIN THE SMARTPARK


SYSTEM TO THE TEACHER
(Structured Explanation + Practical Demonstration)

1. GENERAL INTRODUCTION (START WITH THIS)


“This system is a computerized parking management system called SmartPark.
It uses an array data structure to manage up to 50 cars.
Each array index represents one parking slot, and a null value means the slot is free.”
2. HOW THE SYSTEM IS STARTED
“First, I declare a constant MAX_SLOTS equal to 50.
Then I create an array called parkingSlots with 50 positions and initialize all of them to
null, which means all parking slots are free at the beginning.”

You can point to this code:

const MAX_SLOTS = 50;


let parkingSlots = new Array(MAX_SLOTS).fill(null);

3. IF THE TEACHER ASKS: “HOW DO YOU ADD


(PARK) A CAR?”
✅ SAY THIS (STRUCTURED & CLEAR)

“To add a car, I use the ParkCar procedure.


First, the system checks whether the parking area is full.
If the parking is full, it displays a message saying ‘Parking is full’.
If there is a free slot, the system records the car plate number and the entry time, then
stores the car in the first available parking slot.”

THEN DEMONSTRATE (IN CONSOLE)


parkCar("RAB123A");

EXPLAIN THE RESULT

“The system parks the car in the first free slot and displays the slot number.”

4. IF THE TEACHER ASKS: “HOW DO YOU REMOVE


A CAR?”
✅ SAY THIS

“To remove a car, I use the RemoveCar procedure.


The system searches for the car using the plate number.
Once the car is found, the system records the exit time, calculates the total time spent in
parking, and then calculates the parking fee.
After that, the car is removed and the parking slot is set back to null.”
THEN DEMONSTRATE
removeCar("RAB123A");

EXPLAIN THE FEE LOGIC

“The system charges 500 Rwf for the first hour and 300 Rwf for every additional hour.”

5. IF THE TEACHER ASKS: “HOW DO YOU CHECK


PARKING STATUS?”
✅ SAY THIS

“The system counts how many slots are null to know how many slots are free.
The difference between total slots and free slots gives the occupied slots.”

DEMONSTRATE
checkStatus();

6. IF THE TEACHER ASKS: “HOW DO YOU DISPLAY


ALL PARKED CARS?”
✅ SAY THIS

“The system traverses the parkingSlots array using a loop.


For each slot that is not null, it displays the slot number and the car plate number.”

DEMONSTRATE
traverseCars();

7. IF THE TEACHER ASKS: “WHY DID YOU USE AN


ARRAY?”
✅ SAY THIS (VERY IMPORTANT)
“I used an array because parking slots are arranged in a linear order.
Each array index represents one parking slot, which makes it easy to add, remove, and
traverse cars efficiently.”

8. IF THE TEACHER ASKS: “HOW DID YOU RUN THE


PROGRAM?”
✅ SAY THIS EXACTLY

“I ran the program using a web browser.


I opened the HTML file in the browser and used the browser console to call the JavaScript
functions for parking, removing cars, and checking status.”

9. FINAL CONFIDENT CONCLUSION (END WITH


THIS)
“This system reduces manual errors, improves accuracy in time and fee calculation, and
efficiently manages parking slots using data structures and algorithms.”

✅ QUICK MEMORY TIP (FOR ORAL DEFENSE)


Teacher asks You answer
Add a car ParkCar → check full → store car
Remove car Search → calculate time → fee → remove
Status Count null slots
Data structure Array
Fee 500 + 300 per extra hour
Execution Browser console

🎯 YOU ARE NOW READY


✔ Confident explanation
✔ Structured English
✔ Matches code & flowchart
✔ Teacher-friendly

You might also like