這篇文章將為大家詳細講解有關C語言如何實現簡單學生成績管理系統,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
本文實例為大家分享了C語言實現學生成績管理系統的具體代碼,供大家參考,具體內容如下
C語言小項目
實現一個學生成績管理系統
系統功能:
1.實現所有學生成績的錄入(利用結構體數組),當輸入字符為end時候,結束成績的錄入;
2.實現所有學生信息的輸出
3.輸入指定學生姓名,并能輸出這名學生的信息
4.將學生成績按照語文和數學成績排序
思路:
1. 首先,先把這個小項目的框架打好??紤]要寫幾個文件,每一個文件里面實現怎樣的功能??紤]到這個小項目的代碼量以及程序的易讀性,我決定將寫三個文件。一個main.c,里面就寫需要用到的函數;一個teacher.c主要實現main.c函數里面具體的內容;一個teacher.h里面主要寫這個項目我們需要用到一些宏定義和函數,以便在另外兩個C文件里面調用。(注意:在兩個C文件里面要包括teacher.h文件)。
2. 其次,分析一下這個系統要實現的功能,有四個功能。我們可以每一個功能寫一個函數,分別實現全部錄入,全部輸出,指定學生信息輸出以及語文和數學成績的排序這四個函數。將這四個函數的具體實現放在teacher.c文件里面。Main.c就負責直接調用這些函數。
3. 最后,考慮到需要錄入的時學生信息,包括姓名,學號,性別,語文成績,數學成績這些內容。所以,考慮用結構體數組來實現。
Teacher.h文件
#ifndef _TEACHER_H_
#define _TEACHER_H_
struct student
{
char name[20];
int id;
char sex;
int chinese;
int math;
};
typedef struct student stu;
void show_message(stu *st, int len);
int input(stu *st);
void find(stu *st, int len);
void sort(stu *st, int len);
void out(stu *st, int i);
void welcome();
void showchoice();
#endifMain.c文件
#include <stdio.h>
#include <string.h>
#include "teacher.h"
#include <stdlib.h>
int main()
{
int len;
int m;
stu st[100];
welcome();
while(1)
{
showchoice();
scanf("%d", &m);
switch(m)
{
case 1: len = input(st);break;
case 2: show_message(st , len);break;
case 3: find(st , len);break;
case 4: sort(st , len);break;
default : exit(0);
}
}
return 0;
}Teacher.c文件
#include <string.h>
#include <stdio.h>
#include "teacher.h"
void welcome() //系統界面歡迎函數
{
system("clear");
printf("*********************************\n");
printf("WELCOME TO TEACHER SYSTEM!\n");
printf("*********************************\n");
sleep(2);
}
void showchoice() //選擇提示函數
{
//system("clear");
printf("*********************************\n");
printf("1 input! 2 showinfor!\n");
printf("3 find! 4 sort!\n");
printf("*********************************\n");
printf("Please input your choice :\n");
}
void out(stu *st, int i) //輸出第i個學生的信息
{
printf("%s ",st[i].name);
printf("%d ",st[i].id);
printf("%c ",st[i].sex);
printf("%d ",st[i].chinese);
printf("%d",st[i].math);
printf("\n");
}
int input(stu *st) //錄入學生信息
{
int i;
printf("Input name, id, sex, Chinese score, Math score:\n");
for(i = 0; i < 100; i++)
{
scanf("%s", st[i].name);
if((!strcmp(st[i].name , "end")))
{
return i;
}
scanf("%d", &st[i].id);
scanf("%s", &st[i].sex);
scanf("%d", &st[i].chinese);
scanf("%d", &st[i].math);
}
return i;
}
void show_message(stu *st, int len) //輸出全部學生信息
{
int i;
printf("name, id, sex, Chinese score, Math score:\n");
for(i = 0; i < len; i++)
{
out(st, i);
}
}
void find(stu *st,int len) //查找出特定學生信息
{
char tmp[20];
int i;
printf("Please input the target student:\n");
scanf("%s", tmp);
for(i = 0; i < len; i++ )
{
if(!strcmp(st[i].name,tmp))
{
out(st, i);
}
}
}
void sort(stu *st, int len) //將數學,語文成績冒泡排序
{
int tmp;
int i,j,k;
int id,sex,chinese,math;
char name[20];
int choice;
printf("\n");
printf("Please input your sort choice:\n"); //選擇提示:1 數學成績排序 2 語文成績排序
printf("1 math grade! 2 chinese grade!\n");
printf("\n");
scanf("%d",&choice);
if(1 == choice)
{
for(i = 0;i < len-1;i++)
{
for(j = 0;j < len-1-i;j++)
{
if(st[j].math > st[j+1].math) //將成績較大的學生信息放到成績較低的后面
{
tmp = st[j].math;
st[j].math = st[j+1].math;
st[j+1].math = tmp;
strcpy(name,st[j].name);
strcpy(st[j].name,st[j+1].name);
strcpy(st[j+1].name,name);
id = st[j].id;
st[j].id = st[j+1].id;
st[j+1].id = id;
sex = st[j].sex;
st[j].sex = st[j+1].sex;
st[j+1].sex = sex;
chinese = st[j].chinese;
st[j].chinese = st[j+1].chinese;
st[j+1].chinese = chinese;
}
}
}
printf("After sort math grade :\n");
for(k = 0;k < len;k++)
{
out(st, k);
}
}
else if(2 == choice)
{
for(i = 0;i < len-1;i++)
{
for(j = 0;j < len-1-i;j++)
{
if(st[j].chinese > st[j+1].chinese)
{
tmp = st[j].chinese;
st[j].chinese = st[j+1].chinese;
st[j+1].chinese = tmp;
math = st[j].math;
st[j].math = st[j+1].math;
st[j+1].math = math;
strcpy(name,st[j].name);
strcpy(st[j].name,st[j+1].name);
strcpy(st[j+1].name,name);
id = st[j].id;
st[j].id = st[j+1].id;
st[j+1].id = id;
sex = st[j].sex;
st[j].sex = st[j+1].sex;
st[j+1].sex = sex;
}
}
}
printf("After sort chinese grade :\n");
for(k = 0;k < len;k++)
{
out(st,k);
}
}
else
{
printf("Input error!\nPlease input again!\n");
}
}關于“C語言如何實現簡單學生成績管理系統”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。