-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbus.h
70 lines (60 loc) · 1.88 KB
/
bus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
bus.h
Authors: M00909998, M00906834
Created: 25/03/2024
Updated: 21/04/2024
*/
#ifndef BUS_H
#define BUS_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <limits>
const int TABLE_SIZE = 10000;
// Class to represent a bus
class Bus {
public:
char busn[20];
char departure[20];
char driver[50];
char currentStation[50];
char from[50];
char to[50];
char ETA[20];
// Default constructor
Bus() {}
// Constructor
Bus(const char* busNum, const char* depart, const char* driverName,
const char* currentSta, const char* fromLoc, const char* toLoc,
const char* eta) {
strncpy(busn, busNum, sizeof(busn) - 1);
strncpy(departure, depart, sizeof(departure) - 1);
strncpy(driver, driverName, sizeof(driver) - 1);
strncpy(currentStation, currentSta, sizeof(currentStation) - 1);
strncpy(from, fromLoc, sizeof(from) - 1);
strncpy(to, toLoc, sizeof(to) - 1);
strncpy(ETA, eta, sizeof(ETA) - 1);
}
};
// Hash table to store bus information
extern Bus busTable[TABLE_SIZE];
// Function declarations
void vline(char ch);
int hashFunction(const char* busNumber);
void emptyBus(Bus& bus);
void addBus();
void searchBus(const char* busNumber);
void showAvailableBuses();
void deleteBusInfo(const char* busNumber);
void readBusDataFromCSV(const char* filename);
void writeBusDataToCSV(const char* filename);
bool compareBuses(const Bus& bus1, const Bus& bus2);
void sortBus(Bus* buses, int top, int bottom, int sortBy);
void merge(Bus* buses, int top, int mid, int bottom, int sortBy);
bool validateTimeFormat(const char* timeStr);
// Custom comparator functions for sorting
bool compareByBusNo(const Bus& bus1, const Bus& bus2);
bool compareByDepartureTime(const Bus& bus1, const Bus& bus2);
bool compareByArrivalTime(const Bus& bus1, const Bus& bus2);
#endif