Skip to content
Merged
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
17 changes: 0 additions & 17 deletions Menu WIP.py

This file was deleted.

43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
Random CS project.<br>
CS Project has 3 tasks, each task has it's own flowchart.<br>
Current stage is Pseudocode.<br>

Finished: Overview, FlowCharts, Code( I think)

{Currently not working on this}
# CS Project Organization

This repository contains various Computer Science tasks, organized into a clean directory structure with a central dispatcher.

## Project Structure

- `main.py`: The main entry point. Run this to access all tasks via a menu.
- `algorithms/`: Searching and sorting algorithm implementations.
- `booking_system/`: A transport booking system with account management and price calculation.
- `data_structures/`: Implementations of Linked Lists and Stacks (both OOP and Procedural).
- `docs/`: Documentation, including flowcharts and pseudocode.
- `high_scores/`: A high score tracking system.
- `shapes/`: Area calculation for various geometric shapes.
- `student_management/`: OOP implementation for managing student information.

## How to Run

1. Ensure you have Python installed.
2. Run the main dispatcher from the root directory:
```bash
python main.py
```
3. Follow the on-screen prompts to select the task you want to run.

## Features

- **Menu-Driven Interface:** Easily navigate through different tasks.
- **Robust Error Handling:** Scripts have been improved to handle invalid inputs gracefully.
- **Persistent Data:** Booking data and high scores are saved to text files within their respective directories.
- **Sample Data:** Each task comes with sample data or uses provided data files to demonstrate functionality.

## Documentation

Check the `docs/` folder for:
- `pseudocode.txt`: Logic descriptions.
- `flowchart.drawio.html` & `overview.drawio.html`: Visual representations of the project logic.
File renamed without changes.
48 changes: 48 additions & 0 deletions algorithms/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os


def search(search_item, search_array):
id_item = 0
for item in search_array:
try:
if int(item) == search_item:
return id_item, item, True
except ValueError:
if item == search_item:
return id_item, item, True
id_item += 1
return False


def run_search():
# Get the directory of the current script
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
data_file = os.path.join(BASE_DIR, "data.txt")

try:
with open(data_file, "r") as f:
farray = f.read().split(',')

# Clean up whitespace
farray = [item.strip() for item in farray]

print("Array content:", farray)

try:
item_s = int(input("Enter a number to search for: "))
except ValueError:
print("Invalid input. Searching for default item 10.")
item_s = 10

result = search(item_s, farray)
if result:
idx, val, found = result
print(f"Item found! The item searched is: {val} at index {idx}")
else:
print(f"Item {item_s} not found!")
except FileNotFoundError:
print(f"Error: {data_file} not found.")


if __name__ == "__main__":
run_search()
69 changes: 69 additions & 0 deletions algorithms/search_hard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os


def search(search_item, search_array):
while True:
array_length = len(search_array)
if array_length == 0:
return False
midpoint = array_length // 2

if search_array[midpoint] == search_item:
return True
elif array_length <= 1:
return False
elif search_item > search_array[midpoint]:
search_array = search_array[midpoint+1:]
else:
search_array = search_array[0:midpoint]


def sort(sort_array):
array = list(sort_array)
changed = True
while changed:
changed = False
for i in range(len(array) - 1):
if array[i] > array[i + 1]:
temp = array[i]
array[i] = array[i + 1]
array[i + 1] = temp
changed = True
return array


def run_search_hard():
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
data_file = os.path.join(BASE_DIR, "data.txt")

try:
with open(data_file, "r") as f:
content = f.read().strip()
if content:
farray = content.split(',')
farray = [int(i.strip()) for i in farray]
else:
farray = []

sorted_array = sort(farray)
print("Sorted array:", sorted_array)

try:
item_s = int(
input("Enter a number to search for (Binary Search): "))
except ValueError:
print("Invalid input. Searching for 11.")
item_s = 11

if search(item_s, sorted_array):
print(f"Item {item_s} found!")
else:
print(f"Item {item_s} not found!")
except FileNotFoundError:
print(f"Error: {data_file} not found.")
except Exception as e:
print(f"An error occurred: {e}")


if __name__ == "__main__":
run_search_hard()
25 changes: 25 additions & 0 deletions algorithms/sorting123.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def sort(array):
arr = list(array)
for i in range(len(arr)):
if i == 0:
continue
if arr[i] < arr[i-1]:
for b in range(i, 0, -1):
if arr[b] < arr[b-1]:
temp = arr[b]
arr[b] = arr[b-1]
arr[b-1] = temp
else:
break
return arr


def run_sorting():
unsorted = [1, 3, 7, 8, 23, 0, 4, 5, 6, 2, 12]
print(f"Unsorted list: {unsorted}")
sorted_list = sort(unsorted)
print(f"Sorted list: {sorted_list}")


if __name__ == "__main__":
run_sorting()
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading