第三周毛概课学习心得

  这一周的毛概课,我们继续学习了相关的知识点内容,以及迎来了实践课的任务及要求。希望自己能够做好实践课。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是用C语言编写学生成绩管理实现各种功能的示例代码: 1. 输入学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void inputScore(struct Student *student) { printf("请输入学生的成绩:\n"); printf("大学英语成绩:"); scanf("%f", &(student->english)); printf("毛概成绩:"); scanf("%f", &(student->politics)); printf("数据结构成绩:"); scanf("%f", &(student->dataStructure)); printf("数据库成绩:"); scanf("%f", &(student->database)); } ``` 2. 输出学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void outputScore(struct Student student) { printf("学生的成绩如下:\n"); printf("大学英语成绩:%f\n", student.english); printf("毛概成绩:%f\n", student.politics); printf("数据结构成绩:%f\n", student.dataStructure); printf("数据库成绩:%f\n", student.database); } ``` 3. 插入学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void insertScore(struct Student *student, float english, float politics, float dataStructure, float database) { student->english = english; student->politics = politics; student->dataStructure = dataStructure; student->database = database; } ``` 4. 删除学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void deleteScore(struct Student *student) { student->english = 0; student->politics = 0; student->dataStructure = 0; student->database = 0; } ``` 5. 查找学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void searchScore(struct Student student) { printf("学生的成绩如下:\n"); printf("大学英语成绩:%f\n", student.english); printf("毛概成绩:%f\n", student.politics); printf("数据结构成绩:%f\n", student.dataStructure); printf("数据库成绩:%f\n", student.database); } ``` 6. 追加学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void appendScore(struct Student *student, float english, float politics, float dataStructure, float database) { student->english += english; student->politics += politics; student->dataStructure += dataStructure; student->database += database; } ``` 7. 读入学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void readScore(struct Student *student) { printf("请输入学生的成绩:\n"); printf("大学英语成绩:"); scanf("%f", &(student->english)); printf("毛概成绩:"); scanf("%f", &(student->politics)); printf("数据结构成绩:"); scanf("%f", &(student->dataStructure)); printf("数据库成绩:"); scanf("%f", &(student->database)); } ``` 8. 显示学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void displayScore(struct Student student) { printf("学生的成绩如下:\n"); printf("大学英语成绩:%f\n", student.english); printf("毛概成绩:%f\n", student.politics); printf("数据结构成绩:%f\n", student.dataStructure); printf("数据库成绩:%f\n", student.database); } ``` 9. 保存学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void saveScore(struct Student student) { FILE *file = fopen("score.txt", "w"); if (file == NULL) { printf("保存失败!\n"); return; } fprintf(file, "大学英语成绩:%f\n", student.english); fprintf(file, "毛概成绩:%f\n", student.politics); fprintf(file, "数据结构成绩:%f\n", student.dataStructure); fprintf(file, "数据库成绩:%f\n", student.database); fclose(file); printf("保存成功!\n"); } ``` 10. 拷贝学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void copyScore(struct Student *dest, struct Student src) { dest->english = src.english; dest->politics = src.politics; dest->dataStructure = src.dataStructure; dest->database = src.database; } ``` 11. 排序学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void sortScore(struct Student *students, int count) { // 使用冒泡排序按照大学英语成绩从小到大排序 for (int i = 0; i < count - 1; i++) { for (int j = 0; j < count - i - 1; j++) { if (students[j].english > students[j + 1].english) { struct Student temp = students[j]; students[j] = students[j + 1]; students[j + 1] = temp; } } } } ``` 12. 索引学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void indexScore(struct Student *students, int count) { printf("学生成绩索引如下:\n"); for (int i = 0; i < count; i++) { printf("学生%d的大学英语成绩:%f\n", i + 1, students[i].english); } } ``` 13. 分类合计学生成绩: ```c #include <stdio.h> struct Student { float english; float politics; float dataStructure; float database; }; void sumScore(struct Student *students, int count) { float englishSum = 0; float politicsSum = 0; float dataStructureSum = 0; float databaseSum = 0; for (int i = 0; i < count; i++) { englishSum += students[i].english; politicsSum += students[i].politics; dataStructureSum += students[i].dataStructure; databaseSum += students[i].database; } printf("大学英语成绩总和:%f\n", englishSum); printf("毛概成绩总和:%f\n", politicsSum); printf("数据结构成绩总和:%f\n", dataStructureSum); printf("数据库成绩总和:%f\n", databaseSum); } ``` 14. 退出程序: ```c #include <stdio.h> #include <stdlib.h> void exitProgram() { printf("程序已退出!\n"); exit(0); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值