write a cade to make smart planner in c language
Question
write a cade to make smart planner in c language
Solution
Claro, aquí tienes un ejemplo de cómo podrías escribir un código para un planificador inteligente:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_TASKS 100
#define MAX_NAME_LENGTH 50
typedef struct {
char name[MAX_NAME_LENGTH];
int priority;
int duration; // in minutes
} Task;
void addTask(Task tasks[], int *taskCount) {
if (*taskCount >= MAX_TASKS) {
printf("No se pueden agregar más tareas.\n");
return;
}
printf("Ingrese el nombre de la tarea: ");
scanf(" %[^\n]", tasks[*taskCount].name);
printf("Ingrese la prioridad de la tarea (1-10): ");
scanf("%d", &tasks[*taskCount].priority);
printf("Ingrese la duración de la tarea (en minutos): ");
scanf("%d", &tasks[*taskCount].duration);
(*taskCount)++;
}
void displayTasks(Task tasks[], int taskCount) {
printf("\nLista de tareas:\n");
for (int i = 0; i < taskCount; i++) {
printf("Tarea %d: %s, Prioridad: %d, Duración: %d minutos\n", i + 1, tasks[i].name, tasks[i].priority, tasks[i].duration);
}
}
void sortTasksByPriority(Task tasks[], int taskCount) {
for (int i = 0; i < taskCount - 1; i++) {
for (int j = 0; j < taskCount - i - 1; j++) {
if (tasks[j].priority < tasks[j + 1].priority) {
Task temp = tasks[j];
tasks[j] = tasks[j + 1];
tasks[j + 1] = temp;
}
}
}
}
int main() {
Task tasks[MAX_TASKS];
int taskCount = 0;
int choice;
while (1) {
printf("\n1. Agregar tarea\n");
printf("2. Mostrar tareas\n");
printf("3. Ordenar tareas por prioridad\n");
printf("4. Salir\n");
printf("Ingrese su elección: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addTask(tasks, &taskCount);
break;
case 2:
displayTasks(tasks, taskCount);
break;
case 3:
sortTasksByPriority(tasks, taskCount);
printf("Tareas ordenadas por prioridad.\n");
break;
case 4:
exit(0);
default:
printf("Opción no válida.\n");
}
}
return 0;
}
Este código define un planificador simple que permite agregar tareas, mostrar las tareas y ordenarlas por prioridad. Cada tarea tiene un nombre, una prioridad y una duración.
Similar Questions
write a code to make a smart planner
smart planner using array,function,switch case,loop in c programming language
Context: make a ppt on smart planner using array,loops,function,switch case with an example and the whole ppt should be in english
After the problem has been clearly defined, the next step in the PDLC is to create the plan or algorithm. This plan is usually written as a _, and is in written in an ordinary language, such as English.
make a ppt on smart planner using array,loops,function,switch case
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.