Menu
Coddy logo textTech

Show Skills

Lección 6 de 8 del curso Clase User - Proyecto de OOP de Coddy.

challenge icon

Desafío

Fácil

Agrega un método llamado showSkills que imprima información sobre las habilidades del usuario en un formato específico.

Por ejemplo, si las habilidades del usuario son:

  • "Python" es nivel 2
  • "C++" es nivel 1
  • "HTML" es nivel 3

Llamar a showSkills() producirá la siguiente salida:

C++: 1
HTML: 3
Python: 2

Las habilidades se muestran en orden alfabético por el nombre de la habilidad.

Pruébalo tú mismo

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "user.h"

int main() {
    User u;
    User_init(&u, "", "");
    char line[1024];
    while (fgets(line, sizeof(line), stdin)) {
        line[strcspn(line, "\r\n")] = '\0';
        char* cmd = strtok(line, " \t");
        if (!cmd) continue;
        if (strcmp(cmd, "new") == 0) {
            char* un = strtok(NULL, " \t");
            char* em = strtok(NULL, " \t");
            User_init(&u, un ? un : "", em ? em : "");
        }
        if (strcmp(cmd, "username") == 0) { printf("%s\n", u.username); }
        if (strcmp(cmd, "email") == 0) { printf("%s\n", u.email); }
        if (strcmp(cmd, "setLocation") == 0) { char* v = strtok(NULL, " \t"); if (v) User_setLocation(&u, v); }
        if (strcmp(cmd, "getLocation") == 0) { printf("%s\n", User_getLocation(&u)); }
        if (strcmp(cmd, "info") == 0) { User_info(&u); }
        if (strcmp(cmd, "learn") == 0) { char* v = strtok(NULL, " \t"); if (v) User_learn(&u, v); }
        if (strcmp(cmd, "showSkills") == 0) { User_showSkills(&u); }
    }
    return 0;
}

Todas las lecciones de Clase User - Proyecto de OOP