Grupo
Programación en Tiempo Real en C++
Ojetivo
Escriba un programa en C++ que simule un sistema de programación de tareas. El programa debe permitir programar tareas a intervalos específicos y ejecutarlas según corresponda. Puede simular diferentes tareas, como mostrar mensajes o realizar acciones simples, y programarlas para que se ejecuten a horas o intervalos específicos. Utilice un bucle para supervisar la programación de tareas y ejecutarlas cuando llegue la hora programada.
Implemente un sistema de programación de tareas.
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the input-output stream library
#include <thread> // Include the thread library for time management
#include <chrono> // Include the chrono library for handling time intervals
using namespace std;
// A simple task function to simulate a scheduled task
void task(string taskName) {
cout << taskName << " task executed!" << endl; // Print a message indicating the task is executed
}
// Function to schedule and manage tasks
void scheduleTasks() {
// Schedule tasks with different time intervals
this_thread::sleep_for(chrono::seconds(3)); // Wait for 3 seconds
task("Task 1"); // Execute Task 1 after 3 seconds
this_thread::sleep_for(chrono::seconds(2)); // Wait for 2 seconds
task("Task 2"); // Execute Task 2 after 2 more seconds
this_thread::sleep_for(chrono::seconds(4)); // Wait for 4 seconds
task("Task 3"); // Execute Task 3 after 4 more seconds
this_thread::sleep_for(chrono::seconds(1)); // Wait for 1 second
task("Task 4"); // Execute Task 4 after 1 more second
}
int main() {
// Start the task scheduling system
cout << "Scheduling tasks..." << endl;
scheduleTasks(); // Call the scheduleTasks function to manage task execution
return 0;
}
Salida
Scheduling tasks...
Task 1 task executed!
Task 2 task executed!
Task 3 task executed!
Task 4 task executed!
Comparte este ejercicio C++