Knowee
Questions
Features
Study Tools

smart planner using array,function,switch case,loop in c programming language

Question

smart planner using array,function,switch case,loop in c programming language

🧐 Not the exact question you are looking for?Go ask a question

Solution

Claro, aquí tienes un ejemplo de un planificador inteligente utilizando arreglos, funciones, switch case y bucles:

#include <stdio.h>
#include <string.h>

#define MAX_TASKS 100
#define MAX_NAME_LENGTH 50

typedef struct {
    char name[MAX_NAME_LENGTH];
    int priority;
} Task;

Task tasks[MAX_TASKS];
int taskCount = 0;

void addTask(char name[], int priority) {
    if (taskCount < MAX_TASKS) {
        strcpy(tasks[taskCount].name, name);
        tasks[taskCount].priority = priority;
        taskCount++;
    } else {
        printf("No se pueden agregar más tareas.\n");
    }
}

void displayTasks() {
    for (int i = 0; i < taskCount; i++) {
        printf("Tarea: %s, Prioridad: %d\n", tasks[i].name, tasks[i].priority);
    }
}

void sortTasksByPriority() {
    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() {
    int choice;
    char name[MAX_NAME_LENGTH];
    int priority;

    do {
        printf("1. Agregar tarea\n");
        printf("2. Mostrar tareas\n");
        printf("3. Ordenar tareas por prioridad\n");
        printf("4. Salir\n");
        printf("Elige una opción: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                printf("Nombre de la tarea: ");
                scanf("%s", name);
                printf("Prioridad de la tarea (1-10): ");
                scanf("%d", &priority);
                addTask(name, priority);
                break;
            case 2:
                displayTasks();
                break;
            case 3:
                sortTasksByPriority();
                printf("Tareas ordenadas por prioridad.\n");
                break;
            case 4:
                printf("Saliendo...\n");
                break;
            default:
                printf("Opción no válida.\n");
        }
    } while (choice != 4);

    return 0;
}

Este programa permite al usuario agregar tareas con una prioridad, mostrar las tareas, y ordenarlas por prioridad utilizando un menú interactivo.

This problem has been solved

Similar Questions

how to write a code in c language to make smart planner

make a ppt on smart planner using array,loops,function,switch case

write a code to make a smart planner

Context: make a ppt on smart planner using array,loops,function,switch case with an example and the whole ppt should be in english

GIVE ME SOME QUTIONS TO PRACTICE LOOPS IN C

1/1

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.