Untitled
unknown
plain_text
3 years ago
2.1 kB
3
Indexable
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int START_TIME = 4; // Start time in the evening
const int END_TIME = 1; // End time in the morning
const int NUM_SHIFTS = 10; // Total number of shifts available
const int SHIFT_LENGTH = 4; // Length of each shift in hours
// Volunteer class
class Volunteer {
public:
Volunteer(string name, int num_shifts) {
this->name = name;
this->num_shifts = num_shifts;
}
string get_name() {
return this->name;
}
int get_num_shifts() {
return this->num_shifts;
}
void set_shift(int shift) {
this->shifts.push_back(shift);
}
private:
string name;
int num_shifts;
vector<int> shifts;
};
// Function to display available shifts
void display_shifts(vector<int>& shifts) {
cout << "Available shifts:" << endl;
for (int i = 0; i < shifts.size(); i++) {
cout << shifts[i] << "pm - " << (shifts[i] + SHIFT_LENGTH) % 12 << "am" << endl;
}
}
int main() {
vector<int> shifts;
for (int i = START_TIME; i <= END_TIME + 12; i += SHIFT_LENGTH) {
shifts.push_back(i);
}
// Initialize volunteers
vector<Volunteer> volunteers;
volunteers.push_back(Volunteer("Alice", 0));
volunteers.push_back(Volunteer("Bob", 0));
volunteers.push_back(Volunteer("Charlie", 0));
volunteers.push_back(Volunteer("David", 0));
// Display available shifts
display_shifts(shifts);
// Schedule volunteers for shifts
for (int i = 0; i < NUM_SHIFTS; i++) {
cout << "Enter the shift number to assign a volunteer to (1-" << shifts.size() << "): ";
int shift_num;
cin >> shift_num;
// Check if the shift number is valid
if (shift_num < 1 || shift_num > shifts.size()) {
cout << "Invalid shift number. Please try again." << endl;
i--;
continue;
}
// Display the list of available volunteers
cout << "Available volunteers:" << endl;
for (int j = 0;
Editor is loading...