連結一:
連結清單模版連結位址
連結二:
學生成績管理詳細說明
《c語言項目》學生成績管理系統(devc++)
1.分子產品程式設計分别命名
main.cpp
#include<stdio.h>
#include<stdlib.h>
#include"stdd.h"
#include<string.h>
#include"cjfx.h"
int main()
{
int i,j=1;
struct node*head;
last=NULL;
head=(struct node*)malloc(sizeof(struct node));
head->next =NULL;
printf("\t\t---歡迎使用學生成績管理系統---\n");
while(j){
i= menu();
switch(i){
case 0:
j=0;
printf("退出成功");
break;
case 1:
head=input(head);system("pause");break;//建立節點函數
case 2:
head=add(head);system("pause");break;//增加學生資訊及成績
case 3:
find(head);system("pause");break;//查詢學生資訊及成績
case 4:
del(head);system("pause");break; //删除學生資訊及成績;
case 5:
head=change(head);system("pause");break;//05修改學生資訊和成績
case 6:
output(head);system("pause");break;//浏覽學生資訊及成績
case 7:
file(head);system("pause");break;//(自己創新)儲存到桌面
case 8:
main1(head);system("pause");break;//(創新)學生成績分析
default:break;
}
printf("\n");
printf("\t\t——————————————\n");
}//while結束
system("pause");
}
stdd.h
#include<stdio.h>
//結構體
struct node
{
int date; //學号
int me_class; //班級
double yuwen;//國文成績
double shuxue;//數學成績
double yingyu;//英語成績
double num; //總分
double avg; //平均分
char name[20]; //姓名
char kemu[20]; //所選科目
struct node *next;
};
struct node*input(struct node*head); //01錄入學生的資料和成績.
struct node*add(struct node*head); //02增加學生資訊及成績
struct node*find(struct node*head); //3.查詢學生資訊及成績
void del(struct node*head); //04删除學生資訊及成績;
struct node*change(struct node*head); //05修改學生資訊和成績
struct node* output(struct node*head); //06浏覽學生資訊及成績
void file(struct node*head); //檔案夾操作。
//主菜單
int menu(){
int i=1;
printf("\t\t 1.錄入學生資訊及成績\n");
printf("\t\t 2.增加學生資訊及成績\n");
printf("\t\t 3.查詢學生資訊及成績\n");
printf("\t\t 4.删除學生資訊及成績\n");
printf("\t\t 5.修改學生資訊及成績\n");
printf("\t\t 6.浏覽學生資訊及成績\n");
printf("\t\t 7.儲存學生成績到c盤\n");
printf("\t\t 8.成績分析系統\n");
printf("\t\t 0.退出\n");
printf("\t\t-----------------------------\n");
printf("\t請選擇序号\n");
scanf("%d",&i);
while(1)
{
if(i<0||i>8)
{
printf("***沒有此選項。請重新選擇***\n");
system("pause");
}
break;
}
return i;
}
struct node *last;//尾節點
//01錄入學生的資料和成績.
struct node*input(node *head)//
{
int i=0,j=1;
struct node *p,*n;
p=(struct node*)malloc(sizeof(struct node));
p=head;
while(1)
{
if(j>0)
{
i++;
n=(struct node*)malloc(sizeof(struct node));
printf("請輸入第%d個學生的學号,姓名\n",i);
scanf("%d %s",&n->date,&n->name);
getchar();
printf("請輸入科目(文或理)和班級(1或者2)\n");
scanf("%s %d",&n->kemu,&n->me_class);
fflush(stdin);
printf("請輸目前學生的國文,數學,英語成績\n");
scanf("%lf %lf %lf",&n->yuwen,&n->shuxue,&n->yingyu);
getchar();
n->num=n->yuwen+n->shuxue+n->yingyu;
n->avg=(p->num)/3;
p->next=n;
p=n;
printf("是否繼續輸入下一個同學的資訊?輸入 1 繼續,輸入 0 就停止輸入\n");
fflush(stdin);
scanf("%d",&j);
fflush(stdin);
}
else
{
p->next=last=NULL;
p=last;
break;
}
}
free(p);//釋放p
return head;
}
//02增加學生資訊及成績
struct node*add(struct node*head)
{
if(head->next==NULL)
{
printf("還沒有存儲資料,請先存儲資料");
return head;
}
else
{
struct node*head1,*p;
head1=(struct node*)malloc(sizeof(struct node));
printf("正在添加學生資訊及成績\n");
head1=input(head1);//插入的節點用連結清單的方式存儲.
p=head->next;
while(p->next!=NULL)
{
p=p->next;
}
p->next=head1->next;//因為頭結點是空的是以應該連結頭結點的下一個節點。
return head;
}
}
//3.查詢學生資訊及成績
struct node*find(struct node*head)
{
int i;
struct node*p;
if(head==NULL)
{
printf("還沒有存儲資料,請先存儲資料\n");
}
else
{
printf("請輸入你要找查的學号:");
scanf("%d",&i);
p=head->next;
while(p->date!=i&&p->next!=NULL)
{
p=p->next;
}
if(p->date==i)
{
printf("學号\t姓名\t班級\t科目\t國文\t\t數學\t\t英語\n");
printf("%d\t%s\t%d\t%s\t%lf\t%lf\t%lf",p->date,p->name,p->me_class,p->kemu,p->yuwen,p->shuxue,p->yingyu);
printf("\n");
return p;
}
else
{
printf("沒有找到你要查找的同學\n");
return NULL;
}
}
}
//04删除學生資訊及成績;
void del(struct node*head)
{
int key,j=0;
struct node*p,*s;
s=head->next;
p=head;
printf("請輸入你要删除學生的學号");
fflush(stdin);//删除緩存的資料。
scanf("%d",&key);
while(s!=NULL)
{
if(s->date!=key)
{
p=s;
s=s->next;
}
else
break;
}
if(s!=NULL)
{
p->next=s->next;
free(s);
printf("删除成功\n");
}
else
printf("删除失敗\n");
}
//05修改學生資訊和成績
struct node*change(struct node*head)
{
struct node*p=NULL;
p=find(head);
if(p==NULL)
{
printf("修改失敗\n");
return head;
}
else
{
printf("請輸入修改的學生資訊\n");
printf("姓名 班級 科目\n");
scanf("%s %d %s",&p->name,&p->me_class ,&p->kemu);
fflush(stdin);
printf("請輸入修改的學生成績\n");
printf("國文 數學 英語\n");
scanf("%lf %lf %lf",&p->yuwen,&p->shuxue,&p->yingyu);
fflush(stdin);//getchar()
printf("\n學号\t姓名\t班級\t科目\t國文\t\t數學\t\t英語\n");
printf("%d\t%s\t%d\t%s\t%lf\t%lf\t%lf\n",p->date,p->name,p->me_class,p->kemu,p->yuwen,p->shuxue,p->yingyu);
return head;
}
}
//06浏覽學生資訊及成績(測試)
struct node* output(struct node*head)
{
if(head==NULL)
printf("還沒有資料請先輸入資料\n");
else
{
struct node *p;
p=head->next;
printf("學号\t姓名\t班級\t科目\t國文\t\t數學\t\t英語\n");
while(p!=NULL)
{
printf("%d\t%s\t%d\t%s\t%lf\t%lf\t%lf",p->date,p->name,p->me_class,p->kemu,p->yuwen,p->shuxue,p->yingyu);
p=p->next;
printf("\n");
}
printf("\n");
}
return head;
}
void file(struct node*head)
{
int i=0;
FILE *fp;
struct node*p=head->next;
fp=fopen("C:\\學生成績單.txt","wt");
fprintf(fp,"學号\t姓名\t班級\t科目\t國文\t\t 數學\t\t 英語\n");
while(p!=NULL)
{
fprintf(fp,"%d\t%s\t%d\t%s\t%lf\t\t%lf\t\t%lf\n",p->date,p->name,p->me_class,p->kemu,p->yuwen,p->shuxue,p->yingyu);
p = p->next;
i++;
}
if(i>0)
printf("\t\t\t\t\t—————成功儲存c盤—————\n");
else printf("\t\t\t\t\t—————沒有資料儲存失敗到桌面—————\n");
fclose(fp);
}
cjfx.h
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node1
{
int date; //學号
int me_class; //班級
double yuwen;//國文成績
double shuxue;//數學成績
double yingyu;//英語成績
double num; //總分
double avg; //平均分
char name[20]; //姓名
char kemu[20]; //所選科目
}stu1[50],stu2[50],t;
int si1=0,si2=0;
void lbzsz(struct node*head);
void OutPx(struct node*head,struct node1 stu[50],int si,int n);//輸出成績排序//輸出成績統計
void Outtj(struct node1 stu[50],int si,int n);//輸出成績統計
int cjmenu(){
int i=1;
printf("\t\t 1.1班成績排序\n");
printf("\t\t 2.2班成績排序\n");
printf("\t\t 3.1班成績統計\n");
printf("\t\t 4.2班成績統計\n");
printf("\t\t 0.退出\n");
printf("\t\t-----------------------------\n");
printf("\t請選擇序号\n");
scanf("%d",&i);
while(1)
{
if(i<0||i>4)
{
printf("***沒有此選項。請重新選擇***\n");
system("pause");
}
break;
}
return i;
}
void main1(struct node*head)
{
int i,j=1;
printf("\t\t---成績分析系統---\n");
while(j){
i= cjmenu();
lbzsz(head);
switch(i){
case 0:
j=0;
printf("退出成功");
break;
case 1:
OutPx(head,stu1,si1,1);system("pause");break;system("pause");
case 2:
OutPx(head,stu2,si2,2);system("pause");break;system("pause");
case 3:
Outtj(stu1,si1,1);system("pause");break;system("pause");
case 4:
Outtj(stu2,si2,2);system("pause");break;system("pause");
default:break;
}
printf("\n");
printf("\t\t——————————————\n");
}//while結束
}
//連結清單存入兩個數組
void lbzsz(struct node*head)
{
struct node*p;
p=head;
if(head->next==NULL)
{printf("沒有資料請先存入資料");}
if(head->next)
{
for(si1=0,si2=0;p->next !=NULL;)
{
p=p->next ;
if(p->me_class %2==0)
{
stu2[si2].avg =p->avg ;//平均分
stu2[si2].date=p->date;//學号
strcpy(stu2[si2].kemu,p->kemu);//字元串要用strcpy
stu2[si2].me_class=p->me_class;
strcpy(stu2[si2].name,p->name);
stu2[si2].num=p->num;
stu2[si2].shuxue=p->shuxue;
stu2[si2].yingyu=p->yingyu;
stu2[si2].yuwen=p->yuwen;
si2++;
}
else
{
stu1[si1].avg =p->avg ;//平均分
stu1[si1].date=p->date;//學号
strcpy(stu1[si1].kemu,p->kemu);
stu1[si1].me_class=p->me_class;
strcpy(stu1[si1].name,p->name);
stu1[si1].num=p->num;
stu1[si1].shuxue=p->shuxue;
stu1[si1].yingyu=p->yingyu;
stu1[si1].yuwen=p->yuwen;
si1++;
}
}
}
/******************************************************/
}//連結清單存入兩個數組
//輸出成績排序
void OutPx(struct node*head,struct node1 stu[],int si,int n){//stu[50]數組,int si長度,int n班級。
int j,k=0;
int i,h;//控制學科。
struct xueke
{
char aa[15];
}km[4]={{"國文"},{"數學"},{"英語"},{"總成績"}};
lbzsz(head);
printf("\t\t%d班的成績排序\n",n);
for(i=0,h=1;i<4;i++,h++){//for1
for(j=0;j<si;j++){//for2
for(k=0;k<si-1-j;k++){//for3
if(h==1){
if(stu[k].yuwen<stu[k+1].yuwen){
t=stu[k+1];
stu[k+1] =stu[k] ;
stu[k]=t;
}
}
if(h==2){
if(stu[k].shuxue<stu[k+1].shuxue){
t =stu[k+1];
stu[k+1] =stu[k] ;
stu[k] =t ;
}
}
if(h==3){
if(stu[k].yingyu<stu[k+1].yingyu){
t=stu[k+1];
stu[k+1] =stu[k] ;
stu[k] =t ;
}
}
if(h==4){
if(stu[k].num <stu[k+1].num ){
t =stu[k+1];
stu[k+1] =stu[k] ;
stu[k] =t ;
}
}
}//for3結束
}//for2結束
printf("%s排名\n學号\t姓名\t班級\t%s成績\t排名\n",km[i].aa,km[i].aa);
if(h==1){
for(j=0,k=1;j<si;j++,k++)
printf("%d\t%s\t%d\t%lf\t%d\n",stu[j].date,stu[j].name,stu[j].me_class,stu[j].yuwen,k);
}
if(h==2){
for(j=0,k=1;j<si;j++,k++)
printf("%d\t%s\t%d\t%lf\t%d\n",stu[j].date,stu[j].name,stu[j].me_class,stu[j].shuxue ,k);
}
if(h==3){
for(j=0,k=1;j<si;j++,k++)
printf("%d\t%s\t%d\t%lf\t%d\n",stu[j].date,stu[j].name,stu[j].me_class,stu[j].yingyu ,k);
}
if(h==4){
for(j=0,k=1;j<si;j++,k++)
printf("%d\t%s\t%d\t%lf\t%d\n",stu[j].date,stu[j].name,stu[j].me_class,stu[j].num ,k);
}
}
}
//輸出成績統計
void Outtj(struct node1 stu[50],int si,int n)
{
double avg1=0,avg2=0,avg3=0;
double k1=0,k2=0,k3=0;//及格率
double j1=0,j2=0,j3=0;//優秀率
double max1;
double min1;
int j;
max1=stu[0].yuwen;
min1=stu[0].yuwen;
for(j=0;j<si;j++)
{
avg1+=stu[j].yuwen;
if(stu[j].yuwen>=60) k1++;
if(stu[j].yuwen>=90) j1++;
if(stu[j].yuwen>max1) max1=stu[j].yuwen;
if(stu[j].yuwen<min1) min1=stu[j].yuwen;
}
avg1/=j;
k1/=j;
j1/=j;
printf("\t\t*********%d班成績*************\n",n);
printf("國文平均成績\t\t及格率\t\t優秀率\t\t最高分\t\t最低分\n");
printf("%f\t\t%f\t%f\t%lf\t%lf\n",avg1,k1,j1,max1,min1);
max1=stu[0].shuxue;
min1=stu[0].shuxue;
for(j=0;j<si;j++)
{
avg2+=stu[j].shuxue;
if(stu[j].shuxue>=60)k2++;
if(stu[j].shuxue>=90)j2++;
if(stu[j].shuxue>max1) max1=stu[j].shuxue;
if(stu[j].shuxue<min1) min1=stu[j].shuxue;
}
avg2/=j;
k2/=j;
j2/=j;
printf("數學平均成績\t\t及格率\t\t優秀率\t\t最高分\t\t最低分\n");
printf("%lf\t\t%lf\t%lf\t%lf\t%lf\n",avg2,k2,j2,max1,min1);
max1=stu[0].yingyu;
min1=stu[0].yingyu;
for(j=0;j<si;j++)
{
avg3+=stu[j].yingyu ;
if(stu[j].yingyu>=60) k3++;
if(stu[j].yingyu>=90)j3++;
if(stu[j].yingyu>max1) max1=stu[j].yingyu;
if(stu[j].yingyu<min1) min1=stu[j].yingyu;
}
avg3/=(j);
k3/=(j);
j3/=(j);
printf("英語平均成績\t\t及格率\t\t優秀率\t\t最高分\t\t最低分\n");
printf("%lf\t\t%lf\t%lf\t%lf\t%lf\n",avg3,k3,j3,max1,min1);
}