C语言写成绩管理系统代码
时间: 2023-04-06 08:03:47 浏览: 74
我可以回答这个问题。以下是一个简单的C语言代码示例,用于管理学生的成绩:
#include <stdio.h>
int main() {
int numStudents, i;
float grade, sum = 0.0, average;
printf("请输入学生人数:");
scanf("%d", &numStudents);
for (i = 1; i <= numStudents; ++i) {
printf("请输入第 %d 个学生的成绩:", i);
scanf("%f", &grade);
sum += grade;
}
average = sum / numStudents;
printf("平均成绩为:%.2f", average);
return 0;
}
注意:这只是一个简单的示例,实际的成绩管理系统可能需要更多的功能和复杂性。
相关问题
c语言 学生成绩管理系统代码
C语言是一种高级计算机编程语言,它广泛应用于系统软件、应用软件、嵌入式软件、游戏开发等领域。C语言具有高效、可移植、可扩展等特点,是学习计算机科学和编程的基础。
以下是一个简单的学生成绩管理系统代码示例,主要实现添加学生信息、查询学生信息、修改学生信息和删除学生信息的功能:
```
#include <stdio.h>
#include <string.h>
struct student{
char name[20];
int id;
float score;
};
int main(){
struct student stu[50];
int i, j, n, id, flag = 0;
char name[20];
float score;
printf("请输入学生人数:");
scanf("%d", &n);
for(i = 0; i < n; i++){
printf("请输入第%d个学生的姓名、学号和成绩:", i+1);
scanf("%s%d%f", stu[i].name, &stu[i].id, &stu[i].score);
}
printf("学生信息如下:\n");
printf("姓名\t学号\t成绩\n");
for(i = 0; i < n; i++){
printf("%s\t%d\t%.1f\n", stu[i].name, stu[i].id, stu[i].score);
}
printf("请输入要查询的学生姓名:");
scanf("%s", name);
for(i = 0; i < n; i++){
if(strcmp(stu[i].name, name) == 0){
printf("该学生的信息为:%s\t%d\t%.1f\n", stu[i].name, stu[i].id, stu[i].score);
flag = 1;
break;
}
}
if(flag == 0){
printf("未找到该学生的信息!\n");
}
printf("请输入要修改的学生学号:");
scanf("%d", &id);
for(i = 0; i < n; i++){
if(stu[i].id == id){
printf("请输入该学生的姓名和成绩:");
scanf("%s%f", stu[i].name, &score);
stu[i].score = score;
printf("修改成功!\n");
break;
}
}
printf("请输入要删除的学生学号:");
scanf("%d", &id);
for(i = 0; i < n; i++){
if(stu[i].id == id){
for(j = i; j < n-1; j++){
stu[j] = stu[j+1];
}
n--;
printf("删除成功!\n");
break;
}
}
printf("删除后的学生信息如下:\n");
printf("姓名\t学号\t成绩\n");
for(i = 0; i < n; i++){
printf("%s\t%d\t%.1f\n", stu[i].name, stu[i].id, stu[i].score);
}
return 0;
}
```
大一c语言学生成绩管理系统代码
很高兴为您介绍大一C语言学生成绩管理系统的代码。根据引用内容,该系统主要使用了循环语句、函数、结构体和链表存储数据,并实现了学生信息录入、学生单个信息查询、查询全部学生信息、修改学生信息、删除学生信息和退出系统等功能。
以下是一个简单的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
char name[20];
int id;
float score;
} Student;
// 定义链表节点结构体
typedef struct Node {
Student data;
struct Node* next;
} Node;
// 全局变量,指向链表头节点
Node* head = NULL;
// 添加学生信息
void addStudent() {
Node* newNode = (Node*)malloc(sizeof(Node));
printf("请输入学生姓名:");
scanf("%s", newNode->data.name);
printf("请输入学生学号:");
scanf("%d", &(newNode->data.id));
printf("请输入学生成绩:");
scanf("%f", &(newNode->data.score));
newNode->next = NULL;
if (head == NULL) {
head = newNode;
} else {
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
printf("学生信息添加成功!\n");
}
// 查询单个学生信息
void searchStudent() {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
Node* temp = head;
while (temp != NULL) {
if (temp->data.id == id) {
printf("学生姓名:%s\n", temp->data.name);
printf("学生学号:%d\n", temp->data.id);
printf("学生成绩:%.2f\n", temp->data.score);
return;
}
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 查询全部学生信息
void searchAllStudents() {
if (head == NULL) {
printf("暂无学生信息!\n");
return;
}
Node* temp = head;
while (temp != NULL) {
printf("学生姓名:%s\n", temp->data.name);
printf("学生学号:%d\n", temp->data.id);
printf("学生成绩:%.2f\n", temp->data.score);
printf("--\n");
temp = temp->next;
}
}
// 修改学生信息
void modifyStudent() {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
Node* temp = head;
while (temp != NULL) {
if (temp->data.id == id) {
printf("请输入学生姓名:");
scanf("%s", temp->data.name);
printf("请输入学生成绩:");
scanf("%f", &(temp->data.score));
printf("学生信息修改成功!\n");
return;
}
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 删除学生信息
void deleteStudent() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
if (head == NULL) {
printf("暂无学生信息!\n");
return;
}
Node* temp = head;
Node* prev = NULL;
while (temp != NULL) {
if (temp->data.id == id) {
if (prev == NULL) {
head = temp->next;
} else {
prev->next = temp->next;
}
free(temp);
printf("学生信息删除成功!\n");
return;
}
prev = temp;
temp = temp->next;
}
printf("未找到该学生信息!\n");
}
// 释放链表内存
void freeList() {
Node* temp = head;
while (temp != NULL) {
Node* nextNode = temp->next;
free(temp);
temp = nextNode;
}
}
int main() {
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("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
searchStudent();
break;
case 3:
searchAllStudents();
break;
case 4:
modifyStudent();
break;
case 5:
deleteStudent();
break;
case 6:
freeList();
printf("感谢使用学生成绩管理系统,再见!\n");
return 0;
default:
printf("无效的选择,请重新输入!\n");
break;
}
}
return 0;
}
```
请注意,这只是一个简单的示例代码,可能还有其他功能和优化的空间。您可以根据自己的需求进行修改和扩展。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)