2301_77054721 2023-06-14 16:19 采纳率: 66.7%
浏览 48
已结题

点歌台管理系统c语言

点歌台管理系统
当今社会生活节奏快,压力大,需要唱唱歌来放松,现有一ktv点歌设备公司拟使用C话言开
发一款ktv点歌管理系统,功能包括但不限于如下:
1.该系统可以有管理员,管理员登录之后可以新增,删除,查找,修改歌曲的信息。2.该系统可以由管理员启动点歌模式,可以设置本次消费时长,可以延长本次消费时间3.客户可根据歌曲的风格,拼音首字母,歌手名字等相关信息进行点歌
4.已点歌曲列表可以进行歌曲置顶,删除等操作5.可以提供热歌榜,新歌榜等相关内容方便客户进行点歌6.所有的相关数据都应使用文件进行持文化保存

  • 写回答

3条回答 默认 最新

  • Minuw 2023-06-14 16:41
    关注

    https://blog.csdn.net/qq_35960743/article/details/122408272

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    // 歌曲结构体
    typedef struct Song {
        char name[100];
        char artist[100];
        char style[100];
        struct Song* next;
    } Song;
    
    // 歌曲列表结构体
    typedef struct SongList {
        Song* head;
        int count;
    } SongList;
    
    // 初始化歌曲列表
    SongList* initSongList() {
        SongList* list = (SongList*)malloc(sizeof(SongList));
        list->head = NULL;
        list->count = 0;
        return list;
    }
    
    // 添加歌曲
    void addSong(SongList* list, const char* name, const char* artist, const char* style) {
        Song* song = (Song*)malloc(sizeof(Song));
        strcpy(song->name, name);
        strcpy(song->artist, artist);
        strcpy(song->style, style);
        song->next = NULL;
    
        if (list->head == NULL) {
            list->head = song;
        }
        else {
            Song* current = list->head;
            while (current->next != NULL) {
                current = current->next;
            }
            current->next = song;
        }
    
        list->count++;
    }
    
    // 删除歌曲
    void deleteSong(SongList* list, const char* name) {
        if (list->head == NULL) {
            return;
        }
    
        if (strcmp(list->head->name, name) == 0) {
            Song* temp = list->head;
            list->head = list->head->next;
            free(temp);
            list->count--;
            return;
        }
    
        Song* current = list->head;
        while (current->next != NULL) {
            if (strcmp(current->next->name, name) == 0) {
                Song* temp = current->next;
                current->next = current->next->next;
                free(temp);
                list->count--;
                return;
            }
            current = current->next;
        }
    }
    
    // 查找歌曲
    Song* findSong(SongList* list, const char* name) {
        Song* current = list->head;
        while (current != NULL) {
            if (strcmp(current->name, name) == 0) {
                return current;
            }
            current = current->next;
        }
        return NULL;
    }
    
    // 修改歌曲信息
    void modifySong(Song* song, const char* name, const char* artist, const char* style) {
        strcpy(song->name, name);
        strcpy(song->artist, artist);
        strcpy(song->style, style);
    }
    
    // 显示歌曲列表
    void displaySongList(SongList* list) {
        Song* current = list->head;
        printf("歌曲列表:\n");
        while (current != NULL) {
            printf("歌曲名称:%s\n", current->name);
            printf("歌手:%s\n", current->artist);
            printf("风格:%s\n", current->style);
            printf("-------------------\n");
            current = current->next;
        }
    }
    
    // 保存歌曲列表到文件
    void saveSongListToFile(SongList* list, const char* filename) {
        FILE* file = fopen(filename, "w");
        if (file == NULL) {
            printf("无法打开文件\n");
            return;
        }
    
        Song* current = list->head;
        while (current != NULL) {
            fprintf(file, "%s,%s,%s\n", current->name, current->artist, current->style);
            current = current->next;
        }
    
        fclose(file);
        printf("歌曲列表保存成功\n");
    }
    
    // 从文件加载歌曲列表
    SongList* loadSongListFromFile(const char* filename) {
        FILE* file = fopen(filename, "r");
        if (file == NULL) {
            printf("无法打开文件\n");
            return NULL;
        }
    
        SongList* list = initSongList();
        char line[300];
        while (fgets(line, sizeof(line), file)) {
            char* name = strtok(line, ",");
            char* artist = strtok(NULL, ",");
            char* style = strtok(NULL, "\n");
            addSong(list, name, artist, style);
        }
    
        fclose(file);
        printf("歌曲列表加载成功\n");
        return list;
    }
    
    int main() {
        SongList* songList = initSongList();
        char filename[100] = "songlist.txt";
        songList = loadSongListFromFile(filename);
    
        int choice;
        while (1) {
            printf("请选择操作:\n");
            printf("1. 添加歌曲\n");
            printf("2. 删除歌曲\n");
            printf("3. 查找歌曲\n");
            printf("4. 修改歌曲信息\n");
            printf("5. 显示歌曲列表\n");
            printf("6. 保存歌曲列表到文件\n");
            printf("0. 退出\n");
            scanf("%d", &choice);
    
            if (choice == 1) {
                char name[100], artist[100], style[100];
                printf("请输入歌曲名称:");
                scanf("%s", name);
                printf("请输入歌手:");
                scanf("%s", artist);
                printf("请输入风格:");
                scanf("%s", style);
                addSong(songList, name, artist, style);
                printf("歌曲添加成功\n");
            }
            else if (choice == 2) {
                char name[100];
                printf("请输入要删除的歌曲名称:");
                scanf("%s", name);
                deleteSong(songList, name);
                printf("歌曲删除成功\n");
            }
            else if (choice == 3) {
                char name[100];
                printf("请输入要查找的歌曲名称:");
                scanf("%s", name);
                Song* song = findSong(songList, name);
                if (song != NULL) {
                    printf("歌曲名称:%s\n", song->name);
                    printf("歌手:%s\n", song->artist);
                    printf("风格:%s\n", song->style);
                }
                else {
                    printf("未找到该歌曲\n");
                }
            }
            else if (choice == 4) {
                char name[100], artist[100], style[100];
                printf("请输入要修改的歌曲名称:");
                scanf("%s", name);
                Song* song = findSong(songList, name);
                if (song != NULL) {
                    printf("请输入新的歌曲名称:");
                    scanf("%s", name);
                    printf("请输入新的歌手:");
                    scanf("%s", artist);
                    printf("请输入新的风格:");
                    scanf("%s", style);
                    modifySong(song, name, artist, style);
                    printf("歌曲信息修改成功\n");
                }
                else {
                    printf("未找到该歌曲\n");
                }
            }
            else if (choice == 5) {
                displaySongList(songList);
            }
            else if (choice == 6) {
                saveSongListToFile(songList, filename);
            }
            else if (choice == 0) {
                break;
            }
            else {
                printf("无效的选择\n");
            }
        }
    
        return 0;
    }
    
    
    
    
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月14日
  • 已采纳回答 6月14日
  • 创建了问题 6月14日