c语言课程设计第二关Add

任务描述

现在你的数据库里已经存储了以下信息:


  1. Name_f Name_l stu_id score retake GPA
  2. Jingyu LI 202200000000 85 0 A
  3. Jy LEE 202200100000 89 0 A
  4. Jxxxyx Leeeee 202100100000 100 1 A+
  5. Jingyu11 LI 202200000001 85 0 A

追加若干个学生的成绩信息,输出新的数据库和学生总数。 要求编写函数 Add(name_f, name_l, id, score)

编程要求

根据提示,在右侧编辑器补充代码,完成学生信息追加。

测试说明

输入说明: 追加信息。

输出说明: 输出新的新的成绩表。

注意:需要过滤掉不合法输入:成绩不在0~100区间内的;学号不是12位的。

平台会对你编写的代码进行测试:

测试输入: Jingyuuuu LI 202200000900 59 Jingyuuuu Lous 202100000900 60 预期输出:


  1. Name_f Name_l stu_id score retake GPA
  2. Jingyu LI 202200000000 85 0 A
  3. Jy LEE 202200100000 89 0 A
  4. Jxxxyx Leeeee 202100100000 100 1 A+
  5. Jingyu11 LI 202200000001 85 0 A
  6. Jingyuuuu LI 202200000900 59 0 F
  7. Jingyuuuu Lous 202100000900 60 1 D
  8. Total: 6
  9. 代码实现:

    #include <stdio.h>

    #include <string.h>

    struct Information

    {

        char first_name[20];

        char last_name[20];

        char id[20];

        int score;

        int retake;

        char GPA[5];//定义结构体

    } stu[110] = {

        {"Jingyu", "LI", "202200000000", 85, 0, "A"},

        {"Jy", "LEE", "202200100000", 89, 0, "A"},

        {"Jxxxyx", "Leeeee", "202100100000", 100, 1, "A+"},

        {"Jingyu11", "LI", "202200000001", 85, 0, "A"}};//数据库已有内容

    char gpa[][5] = {{""}, {"A+"}, {"A"}, {"B+"}, {"B"}, {"C+"}, {"C"}, {"D"}, {"F"}};

    char check_id[] = {"2022"};

    void get_gpa(int i)

    {

        if (stu[i].score >= 93)

            strcpy(stu[i].GPA, "A+");

        else if (stu[i].score >= 85)

            strcpy(stu[i].GPA, "A");

        else if (stu[i].score >= 80)

            strcpy(stu[i].GPA, "B+");

        else if (stu[i].score >= 75)

            strcpy(stu[i].GPA, "B");

        else if (stu[i].score >= 70)

            strcpy(stu[i].GPA, "C+");

        else if (stu[i].score >= 65)

            strcpy(stu[i].GPA, "C");

        else if (stu[i].score >= 60)

            strcpy(stu[i].GPA, "D");

        else

            strcpy(stu[i].GPA, "F");

    }//成绩判定函数

    void Add(char name_f[], char name_l[], char id[], int score, int i)

    {

        strcpy(stu[i].first_name, name_f);

        strcpy(stu[i].last_name, name_l);

        strcpy(stu[i].id, id);

        stu[i].score = score;

    }//添加学生信息函数

    int main()

    {

        printf("Name_f Name_l stu_id score retake GPA\n");

        printf("Jingyu LI 202200000000 85 0 A\n");

        printf("Jy LEE 202200100000 89 0 A\n");

        printf("Jxxxyx Leeeee 202100100000 100 1 A+\n");

        printf("Jingyu11 LI 202200000001 85 0 A\n");

        char name_first[20], name_last[20], id[20];

        int score;

        int i = 4;

        while (~scanf("%s%s%s%d", name_first, name_last, id, &score))

        {

            if (strlen(id) != 12 || score < 0 || score > 100)

                continue;//排除错误信息

            Add(name_first, name_last, id, score, i);

            get_gpa(i);

            if (memcmp(stu[i].id, check_id, 4) != 0)

                stu[i].retake = 1;//memcmp函数用于比较内存区域buf1和buf2的前count个字节,相等就输出0,所以这里不相等就说明他不是2022的学生,也就是重修的

            printf("%s %s %s %d %d %s\n", stu[i].first_name, stu[i].last_name, stu[i].id, stu[i].score, stu[i].retake, stu[i].GPA);

            i++;

        }

        printf("Total: %d", i);

        return 0;

    }

 

### C语言课程设计示例及相资源 C语言作为一门基础编程语言,在课程设计中具有广泛的应用场景。以下是几个常见的C语言课程设计主题及其对应的实现思路。 #### 1. 学生成绩管理系统 学生成绩管理系统的功能通常包括学生信息录入、成绩查询、修改以及删除等功能[^1]。 下面是一个简单的学生成绩管理系统的核心代码框架: ```c #include <stdio.h> #include <string.h> #define MAX_STUDENTS 100 typedef struct { int id; char name[50]; float score; } Student; void addStudent(Student students[], int *count); void displayStudents(const Student students[], int count); int main() { Student students[MAX_STUDENTS]; int studentCount = 0, choice; while (1) { printf("\n1. Add Student\n2. Display Students\n3. Exit\nEnter your choice: "); scanf("%d", &choice); switch(choice) { case 1: addStudent(students, &studentCount); break; case 2: displayStudents(students, studentCount); break; case 3: return 0; default: printf("Invalid choice!\n"); } } return 0; } void addStudent(Student students[], int *count) { if (*count >= MAX_STUDENTS) { printf("Maximum number of students reached.\n"); return; } printf("Enter ID: "); scanf("%d", &(students[*count].id)); printf("Enter Name: "); scanf("%s", students[*count].name); printf("Enter Score: "); scanf("%f", &(students[*count].score)); (*count)++; } void displayStudents(const Student students[], int count) { for(int i=0; i<count; i++) { printf("ID: %d, Name: %s, Score: %.2f\n", students[i].id, students[i].name, students[i].score); } } ``` 此程序提供了一个基本的学生数据操作界面,可以扩展更多功能如按分数排序或导出到文件等[^2]。 #### 2. 图书馆借阅系统 图书馆借阅系统的设计目标是记录书籍的借还状态并支持管理员对图书库存的操作。核心逻辑涉及链表结构来动态存储书籍信息[^3]。 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct BookNode { char title[100]; int availableCopies; struct BookNode* next; } BookNode; BookNode* createBook(char title[], int copies) { BookNode* newBook = malloc(sizeof(BookNode)); strcpy(newBook->title, title); newBook->availableCopies = copies; newBook->next = NULL; return newBook; } // 添加其他函数... ``` 上述代码片段展示了如何创建单个节点表示一本书籍的信息,并通过指针链接多个节点形成列表[^4]。 #### 于下载资料 对于完整的项目案例和学习材料,建议访问开源平台如GitHub搜索"C language project examples"[^5] 或者查阅经典教材《The C Programming Language》第二版中的实践章节[^6]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值