#include <iostream>
#include <queue>
#include <vector>
#include <cstdlib>
#include <ctime>
const int SERVER_CAPACITY = 5; // Number of tasks the server can handle at a time
const int TASK_COUNT = 20; // Number of tasks to be simulated
// Task class
class Task {
public:
Task(int id) : id(id) {}
int getId() const {
return id;
}
private:
int id;
};
// CloudServer class
class CloudServer {
public:
CloudServer(int capacity) : capacity(capacity), tasksProcessed(0) {}
void addTask(const Task& task) {
if (currentTasks.size() < capacity) {
currentTasks.push(task);
std::cout << "Added Task " << task.getId() << " to the server." << std::endl;
} else {
std::cout << "Server is at full capacity. Task " << task.getId() << " cannot be added." << std::endl;
}
}
void processTasks() {
while (!currentTasks.empty()) {
Task task = currentTasks.front();
currentTasks.pop();
tasksProcessed++;
std::cout << "Processed Task " << task.getId() << "." << std::endl;
}
}
int getTasksProcessed() const {
return tasksProcessed;
}
private:
int capacity;
int tasksProcessed;
std::queue<Task> currentTasks;
};
// Main function
int main() {
srand(static_cast<unsigned>(time(0)));
CloudServer server(SERVER_CAPACITY);
// Simulate adding tasks to the cloud server
for (int i = 0; i < TASK_COUNT; ++i) {
Task task(i + 1);
server.addTask(task);
}
// Process all tasks in the server
std::cout << "Processing tasks..." << std::endl;
server.processTasks();
std::cout << "Total tasks processed: " << server.getTasksProcessed() << std::endl;
return 0;
}