• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 10 pages
Other

COS assignment 1

Document preview thumbnail
Preview 2 out of 10 pages

COS assignment 1 change what you need to change

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,

Document information

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

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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
4.9
(9)
Sold
150
Followers
63
Items
51
Last sold
3 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

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

Student with book image

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

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions