要實現一個C語言成績查詢系統,你可以按照以下步驟進行:
typedef struct {
int studentID;
char name[50];
float score;
} Student;
Student student;
printf("請輸入學生信息:\n");
printf("學號:");
scanf("%d", &student.studentID);
printf("姓名:");
scanf("%s", student.name);
printf("成績:");
scanf("%f", &student.score);
Student students[100];
int numStudents = 0;
students[numStudents++] = student;
int searchStudentByID(int studentID) {
for (int i = 0; i < numStudents; i++) {
if (students[i].studentID == studentID)
return i;
}
return -1;
}
int searchStudentByName(char *name) {
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].name, name) == 0)
return i;
}
return -1;
}
int index = searchStudentByID(123456);
if (index != -1) {
printf("學號:%d\n", students[index].studentID);
printf("姓名:%s\n", students[index].name);
printf("成績:%.2f\n", students[index].score);
} else {
printf("未找到該學生。\n");
}
以上是一個簡單的C語言成績查詢系統的實現示例,你可以根據需要進行修改和擴展。