球星管理系统

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node {
    char name[100];
    double points;  //得分 
    double rebound; //篮板 
    double assist;  //助攻 
    double ST;      //抢断 
    double block;   //盖帽 
    int compensation;  //薪资 
    struct node* next;
};
void menu();
void printPlayerInfo(struct node* player);
void initialize(struct node** head);
void print(struct node** head);
void input(struct node** head);
void amend(struct node** head);
void Delete(struct node** head);
void search(struct node** head);
void sorted(struct node** head);
void sort(struct node** head);
int main() {
    int m;
    struct node* L;
    system("color F4");
    initialize(&L);

    do {
        system("cls");//清屏
        menu();
        printf("请输入你的选择:\n");
        scanf("%d", &m);
        switch (m)
        {
        case 1: input(&L);
            system("pause"); //将程序暂停,防止清屏
            break;
        case 2: amend(&L);
            system("pause");
            break;
        case 3: Delete(&L);
            system("pause");
            break;
        case 4: print(&L);
            system("pause");
            break;
        case 5: search(&L);
            system("pause");
            break;
        case 6: sorted(&L);
            system("pause");
            break;
        case 0: printf("感谢您的使用!");//退出 
            exit(0);   //正常退出,返回0
        default:printf("输入有误!!!请重新输入:\n"); //在case都不成立的情况下执行
            system("pause");
            break;
        }
    } while (m != 0);
    return 0;

}
void menu() {
    printf("NBA球星管理系统\n\n");
    printf("1.球员信息录入\n\n");
    printf("2.球员信息修改\n\n");
    printf("3.球员信息删除\n\n");
    printf("4.球员信息浏览\n\n");
    printf("5.球员信息查询\n\n");
    printf("6.球员数据排序\n\n");
    printf("0.退出系统\n\n");
}
void initialize(struct node** head) {
    struct node* p;

    *head = (struct node*)malloc(sizeof(struct node));
    p = *head;
    strcpy(p->name, "luka");
    p->points = 33.9;
    p->rebound = 9.2;
    p->assist = 9.8;
    p->ST = 1.4;
    p->block = 0.6;
    p->compensation = 3586000;
    p->next = (struct node*)malloc(sizeof(struct node));
    p = p->next;

    strcpy(p->name, "jalen");
    p->points = 28.4;
    p->rebound = 3.6;
    p->assist = 6.7;
    p->ST = 0.9;
    p->block = 0.2;
    p->compensation = 2773000;
    p->next = (struct node*)malloc(sizeof(struct node));
    p = p->next;

    strcpy(p->name, "SGA");
    p->points = 30.4;
    p->rebound = 5.6;
    p->assist = 0.9;
    p->ST = 2.1;
    p->block = 0.9;
    p->compensation = 3338000;
    p->next = (struct node*)malloc(sizeof(struct node));
    p = p->next;

    strcpy(p->name, "Giannis");
    p->points = 30.4;
    p->rebound = 11.5;
    p->assist = 2.7;
    p->ST = 1.2;
    p->block = 1.1;
    p->compensation = 4546000;
    p->next = (struct node*)malloc(sizeof(struct node));
    p = p->next;

    strcpy(p->name, "Durant");
    p->points = 27.3;
    p->rebound = 6.6;
    p->assist = 5.2;
    p->ST = 0.9;
    p->block = 1.2;
    p->compensation = 4764000;
    p->next = NULL;
}


void print(struct node** head) {
    struct node* p;
    p = *head;
    printf("                       球员信息                            \n");
    printf("--------------------------------------------------------\n");
    printf("姓名    得分    篮板    助攻    抢断    盖帽    薪资\n");
    while (p != NULL) {
        printf("%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%d$\t\n", p->name, p->points, p->rebound, p->assist, p->ST, p->block, p->compensation);
        p = p->next;
    }
    printf("--------------------------------------------------------\n");
}

void input(struct node** head) {
    struct node* t, * p;
    t = *head;
    while (t->next != NULL) { // 遍历链表找到最后一个节点
        t = t->next;
    }
    t->next = (struct node*)malloc(sizeof(struct node)); // 为新节点分配内存
    t = t->next; // 将t指向新节点
    printf("请输入球员姓名\n");
    scanf("%s", t->name);
    printf("请输入球员得分\n");
    scanf("%lf", &t->points);
    printf("请输入球员篮板\n");
    scanf("%lf", &t->rebound);
    printf("请输入球员助攻\n");
    scanf("%lf", &t->assist);
    printf("请输入球员抢断\n");
    scanf("%lf", &t->ST);
    printf("请输入球员盖帽\n");
    scanf("%lf", &t->block);
    printf("请输入球员薪资\n");
    scanf("%d", &t->compensation);
    t->next = NULL;
}
void amend(struct node** head) {
    struct node* t;
    char name1[100];
    int m, flag = 1;
    t = *head;
    printf("请输入你要修改的球员名称:\n");
    scanf("%s", name1);
    while (t != NULL) {
        if (strcmp(t->name, name1) == 0) {
            flag = 0;
            printf("请输入你要修改的数据类型\n1:得分 2:篮板 3:助攻 4:抢断 5:盖帽 6:薪资\n");
            scanf("%d", &m);
            switch (m) {
            case 1:
                printf("将得分修改为:\n");
                scanf("%lf", &t->points);
                break;
            case 2:
                printf("将篮板修改为:\n");
                scanf("%lf", &t->rebound);
                break;
   
         case 3:
                printf("将助攻修改为:\n");
                scanf("%lf", &t->assist);
                break;
            case 4:
                printf("将抢断修改为:\n");
                scanf("%lf", &t->ST);
                break;
            case 5:
                printf("将盖帽修改为:\n");
                scanf("%lf", &t->block);
                break;
            case 6:
                printf("将薪资修改为:\n");
                scanf("%d", &t->compensation);
                break;
            default:
                printf("输入有误,请重新输入数据类型\n");
                continue; // 如果输入数据类型错误,继续循环等待新的输入
            }//switch
            break;
        }//if
        t = t->next;
    }//while
    if (flag)
        printf("未找到该球员\n");
}
void Delete(struct node** head) {
    struct node* t, * prev=NULL;
    t = *head;
    char name1[100];
    int flag = 1;
    printf("请输入你要删除的球员:\n");
    scanf("%s", name1);
    while (t != NULL) {
        if (strcmp(t->name, name1) == 0) {
            flag = 0;
            printf("该球员信息已删除\n");
            if (t = *head) {
                *head = t->next;
                free(t);
            }
            else
                prev->next = t->next;
        }
        prev = t;
        t = t->next;
    }
    if (flag)
        printf("未找到该球员");
}
void printPlayerInfo(struct node* player) {
    printf("%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%d$\t\n", player->name, player->points, player->rebound, player->assist, player->ST, player->block, player->compensation);
}

void search(struct node** head) {
    struct node* t = *head;
    double threshold;
    int option;

    printf("请输入你要根据哪一项数据查询球员:\n");
    printf("1:得分 2:篮板 3:助攻 4:抢断 5:盖帽 6:薪资\n");
    scanf("%d", &option);

    printf("请输入查询的阈值:\n");
    scanf("%lf", &threshold);

    printf("                       球员信息                            \n");
    printf("--------------------------------------------------------\n");
    printf("姓名\t得分\t篮板\t助攻\t抢断\t盖帽\t薪资\n");

    while (t != NULL) {
        switch (option) {
        case 1:
            if (t->points > threshold) {
                printPlayerInfo(t);
            }
            break;
        case 2:
            if (t->rebound > threshold) {
                printPlayerInfo(t);
            }
            break;
        case 3:
            if (t->assist > threshold) {
                printPlayerInfo(t);
            }
            break;
        case 4:
            if (t->ST > threshold) {
                printPlayerInfo(t);
            }
            break;
        case 5:
            if (t->block > threshold) {
                printPlayerInfo(t);
            }
            break;
        case 6:
            if (t->compensation > threshold) {
                printPlayerInfo(t);
            }
            break;
        default:
            printf("输入有误,请重新输入数据类型\n");
            break;
        }
        t = t->next;
    }
    printf("--------------------------------------------------------\n");
}

void sort_points(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->points > p->points))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sort_rebound(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->rebound > p->rebound))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sort_assist(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->assist > p->assist))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sort_ST(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->ST > p->ST))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sort_block(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->block > p->block))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sort_compensation(struct node** head) {
    struct node* p, * q, * pre;
    p = (*head)->next->next;
    (*head)->next->next = NULL;
    while (p)
    {
        q = p->next;
        pre = (*head);
        while ((pre->next != NULL) && (pre->next->compensation > p->compensation))
            pre = pre->next;
        p->next = pre->next;
        pre->next = p;
        p = q;
    }
}

void sorted(struct node** head) {
    struct node* p_head = (struct node*)malloc(sizeof(struct node));
    int m;
    p_head->next = (*head);

    printf("请输入你要根据哪一项数据进行排序:\n");
    printf("1:得分 2:篮板 3:助攻 4:抢断 5:盖帽 6:薪资\n");
    scanf("%d", &m);
    switch (m) {
    case 1: {
        sort_points(&p_head);
        break;
    }
    case 2: {
        sort_rebound(&p_head);
        break;
    }
    case 3: {
        sort_assist(&p_head);
        break;
    }
    case 4: {
        sort_ST(&p_head);
        break;
    }
    case 5: {
        sort_block(&p_head);
        break;
    }
    case 6: {
        sort_compensation(&p_head);
        break;
    }
    default: {
        printf("输入有误,请重新输入数据类型\n");
    }
    }

    (*head) = p_head->next;
    free(p_head);
    print(head);
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值