100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

COS assignment 1

Rating
-
Sold
5
Pages
10
Uploaded on
03-05-2025
Written in
2024/2025

COS assignment 1 change what you need to change










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
May 3, 2025
Number of pages
10
Written in
2024/2025
Type
Other
Person
Unknown

Subjects

Content preview

2025 COS2611 ASSIGNMENT 1
SOLUTION
#include <iostream>
#include <fstream>
#include <queue>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>

using namespace std;
// Passenger structure
struct Passenger {
char destination; // 'S', 'L', or 'C'
int id; // Passenger ID (e.g., 1, 2, 3...)
int boardingTime; // Time required to board
int remainingTime; // Remaining boarding time
int arrivalTime; // Time when the passenger arrived

Passenger(char dest, int passId, int boarding, int arrival) :
destination(dest), id(passId), boardingTime(boarding),
remainingTime(boarding), arrivalTime(arrival) {}
};

// Structure to keep track of taxi state
struct TaxiState {
int capacity; // Current number of passengers (max 5)
Passenger* boardingPassenger; // Pointer to the currently boarding passenger

TaxiState() : capacity(5), boardingPassenger(nullptr) {}
};

// Structure to maintain passenger counters for each type
struct PassengerCounters {
int sCount;
int lCount;
int cCount;

PassengerCounters() : sCount(0), lCount(0), cCount(0) {}
};

, // Parse a line from the input file
bool parseInputLine(const string& line, int& timeCount, char& route, int& boardingTime) {
stringstream ss(line);
string item;

// Parse time count
if (!getline(ss, item, ',')) return false;
timeCount = stoi(item);

// Parse route
if (!getline(ss, item, ',')) return false;
route = item[0];

// Parse boarding time
if (!getline(ss, item)) return false;
boardingTime = stoi(item);

return true;
}

// Print the table header
void printTableHeader() {
cout << "+------+------+-------+-------+-------+-------+-------+-------+-------+-------+-------+" << endl;
cout << "| T | next | S | L | C | WQS | WQL | WQC | CS | CL | CC |" << endl;
cout << "+------+------+-------+-------+-------+-------+-------+-------+-------+-------+-------+" << endl;
}

// Get string representation of a passenger
string passengerToString(const Passenger* p) {
if (!p) return "-";
stringstream ss;
ss << p->destination << p->id << "(" << p->remainingTime << ")";
return ss.str();
}

// Print a row in the table
void printTableRow(int time, char nextPassenger,
Passenger* queueS,
Passenger* queueL,
Passenger* queueC,
queue<Passenger*>& waitingQS,
queue<Passenger*>& waitingQL,
queue<Passenger*>& waitingQC,
const TaxiState& taxiS,

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
foxNotes Acsess Business Academy
View profile
Follow You need to be logged in order to follow users or courses
Sold
112
Member since
2 year
Number of followers
63
Documents
35
Last sold
1 month ago
saveNotes

5,0

5 reviews

5
5
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions