學生英語成績統計動態鏈表
㈠ C語言 建立一個動態學生成績的鏈表,
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char() num[10];/* 學號 */
char() name[20];
char() sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新時間 */
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()
{
printf("********************************************************************************");
printf("\t1登記學生資料\t\t\t\t\t2刪除學生資料\n");
printf("\t3查詢學生資料\t\t\t\t\t4修改學生資料\n");
printf("\t5保存學生資料\t\t\t\t\t0退出系統\n");
printf("********************************************************************************\n");
}
void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:輸入錯誤!\n");
}
void Nofind()
{
printf("\n=====>提示:沒有找到該學生!\n");
}
void printc() /* 本函數用於輸出中文 */
{
printf(" 學號\t 姓名 性別 英語成績 數學成績 C語言成績 總分 平均分\n");
}
void printe(Node *p)/* 本函數用於輸出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}
Node* Locate(Link l,char findmess[],char nameornum[]) /* 該函數用於定位連表中符合要求的接點,並返回該指針 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按學號查詢 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查詢 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}
void Add(Link l) /* 增加學生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 將指針置於最末尾 */
while(1)
{
printf("請你輸入學號(以'0'返回上一級菜單:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:學號為'%s'的學生已經存在,若要修改請你選擇'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.num,num);
printf("請你輸入姓名:");
scanf("%s",p->data.name);
getchar()();
printf("請你輸入性別:");
scanf("%s",p->data.sex);
getchar()();
printf("請你輸入c語言成績:");
scanf("%d",&p->data.cgrade);
getchar()();
printf("請你輸入數學成績:");
scanf("%d",&p->data.mgrade);
getchar();
printf("請你輸入英語成績:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息輸入已經完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}
void Qur(Link l) /* 查詢學生 */
{
int sel;
char findmess[20];
Node *p;
if(!l->next)
{
printf("\n=====>提示:沒有資料可以查詢!\n");
return;
}
printf("\n=====>1按學號查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 學號 */
{
printf("請你輸入要查找的學號:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找結果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("請你輸入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找結果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();
}
void Del(Link l) /* 刪除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:沒有資料可以刪除!\n");
return;
}
printf("\n=====>1按學號刪除\n=====>2按姓名刪除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("請你輸入要刪除的學號:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:該學生已經成功刪除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("請你輸入要刪除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:該學生已經成功刪除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}
void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:沒有資料可以修改!\n");
return;
}
printf("請你輸入要修改的學生學號:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("請你輸入新學號(原來是%s):",p->data.num);
scanf("%s",p->data.num);
printf("請你輸入新姓名(原來是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("請你輸入新性別(原來是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("請你輸入新的c語言成績(原來是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("請你輸入新的數學成績(原來是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("請你輸入新的英語成績(原來是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:資料修改成功!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;
if(!p)
{
printf("\n=====>提示:沒有資料可以顯示!\n");
return;
}
printf("\t\t\t\t顯示結果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}
void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用於指向分數最高的接點 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:沒有資料可以統計!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;
r=r->next;
}
printf("------------------------------統計結果--------------------------------\n");
printf("總分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);
printf("英語最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("數學最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c語言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}
void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;
ll=(Link)malloc(sizeof(Node)); /* 用於做新的連表 */
ll->next=NULL;
if(l->next==NULL)
{
printf("\n=====>提示:沒有資料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接點用於保存信息 */
s->data=p->data;
s->next=NULL;
rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已經完成!\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打開文件時發生錯誤!\n");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d條記錄已經保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}
void main()
{
Link l;/* 連表 */
FILE *fp; /* 文件指針 */
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\t學生成績管理系統\n\t\t\t\t-------福建農業職業學院計應0501 黃歡(32號)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件還不存在,是否創建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已經打開,正在導入記錄......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 將文件的內容放入接點中 */
{
p->next=NULL;
r->next=p;
r=p; /* 將該接點掛入連中 */
count++;
}
}
fclose(fp); /* 關閉文件 */
printf("\n=====>提示:記錄導入完畢,共導入%d條記錄.\n",count);
while(1)
{
menu();
printf("請你選擇操作:");
scanf("%d",&sel);
if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:資料已經改動,是否將改動保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已經退出系統,再見!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加學生 */
case 2:Del(l);break;/* 刪除學生 */
case 3:Qur(l);break;/* 查詢學生 */
case 4:Modify(l);break;/* 修改學生 */
case 5:Save(l);break;/* 保存學生 */
case 9:printf("\t\t\t==========幫助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}
㈡ c語言:寫一個程序建立一個含有學生(學號成績)數據的單向動態鏈表(我是個初學者希望可以解釋清楚點)
1.n的存在沒必要,直接在循環外面將head指向p1
2.新建節點順序錯誤。你應該先用p2=malloc(…)分配空間,然後輸入數據,最後將p1的next指向p2,最後令p1=p2就行了。之後進行循環
㈢ C語言動態鏈表問題描述:學生信息包括學號、姓名、性別、語文、數學、英語。 插入學生信息:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
struct student
{
char number[20];
char name[20];
char sex;
double score[3];
};
typedef struct node
{
struct student Data;
struct node *next;
} List;
void InitList(List **head);
void inputSingle(List *head);
void outputSingle(List *head);
void main()
{
List *stu;
char order[20];
int sel;
InitList(&stu);
do
{
printf("輸入命令\n");
scanf("%s",order);
if(!strcmp(order,"Insert\0"))
sel=1;
else
if(!strcmp(order,"Quit\0")||!(order,"Exit\0"))
sel=2;
switch(sel)
{
case 1:
inputSingle(stu);
outputSingle(stu);
break;
case 2:
outputSingle(stu);
printf("Goodbye\n");
break;
}
}while(sel!=2);
}
void InitList(List **head)
{
*head=(List *)malloc(sizeof(List));
(*head)->next=NULL;
}
void inputSingle(List *head)
{
List *p,*q=head;
while(q->next)
q=q->next;
p=(List *)malloc(sizeof(List));
p->next=NULL;
scanf("%s%s %c%ld%ld%ld",p->Data.number,p->Data.name,&(p->Data.sex),&(p->Data.score[0]),&(p->Data.score[1]),&(p->Data.score[2]));
q->next=p;
}
void outputSingle(List *head)
{
List *p=head->next;
while(p)
{
printf("%11s%9s%4c%5.2ld%5.2ld%5.2ld\n",p->Data.number,p->Data.name,(p->Data).sex,(p->Data).score[0],(p->Data).score[1],(p->Data).score[2]);
p=p->next;
}
}
建議使用float替換double
㈣ 建立一個動態鏈表,鏈表中每一結點包括:學號、姓名、性別、年齡、成績。( 很急的誰幫幫我)
這個簡單建立一個動態鏈表,鏈表中每一結點包括:學號、姓名…8770
㈤ 每個學生的成績信息包括:學號,語文,數學,英語,總分,加權平均分;採用鏈表存儲若干學生的成績信息;
用excel表格,很好實現。
㈥ 輸入某班20個學生的姓名及數學、英語成績。建立一個鏈表,計算並輸出每個學生的平均分,並找出平均
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
struct node
{
float math;
float english;
float average;
struct node *next;
};
struct node *Init()
{
struct node *head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
return head;
}
void Create(struct node *head)
{
int i;
struct node *p;
for(i=1;i<=SIZE;i++)
{
=(struct node*)malloc(sizeof(struct node));
p->next=NULL;
head->next=p;
head=p;
printf("input No.%d Student score\n",i);
scanf("%f%f",&(p->math),&(p->english));
p->average=((p->math)+(p->english))/2;
}
}
void Visit(struct node *head)
{
head=head->next;
while(head)
{
printf("math=%f,englishi=%f,average=%f\n",head->math,head->english,head->average);
head=head->next;
}
}
void Max(struct node *head)
{
float max=0;
head=head->next;
while(head)
{
if(head->average>max)
max=head->average;
head=head->next;
}
printf("MAX=%f\n",max);
}
int main()
{
struct node *head=Init();
Create(head);
Visit(head);
Max(head);
getchar();
getchar();
return 0;
}
㈦ C語言問題:建立一個由3個學生數據組成的單向動態鏈表,向每個結點輸入學生的數據(學號姓名成績)逐個輸出
struct student*head,*p,*s;
head=p=(struct student*)malloc(LEN);
scanf("%d,%f,&p->num,&p->score");
p= (struct student*)malloc(LEn);
scanf ("%d,%f,&p->num,&p->score");
s= (struct student*)malloc(LEn);
scanf ("%d,%f,&p->num,&p->score"); ------------------>第一個錯誤,p應該為專s
head->next=p;
head->next=s; ------------------>第二個屬錯誤,head應該為p
㈧ C語言問題:建立一個由3個學生數據組成的單向動態鏈表,向每個結點輸入學生的數據(學號姓名成績)並輸出
把main函數的返回類型改成int,就OK了。運行過了沒問題。
㈨ :用C語言鏈表完成學生背單詞的內容,其中有英譯漢,漢譯英,成績統計功能。
給你說一下思路吧~~1個文件~~用一個分隔符分開~~英語和漢語意思~~或者用一個結構體~~讀到鏈表中~~輸入~~比較~~其實還算比較簡單的其實
㈩ 求大神指教 這是用c語言編寫的 基於動態鏈表的學生成績管理系統 其中的錯誤求大神指出
/*
應該建立有頭結點的鏈表,否則,如果刪除的數據剛好是第一個結點時,麻煩就大了。
代碼改動處較多,已經過不完全測試,可以運行。
*/
#include <stdio.h>
#include <stdlib.h>
struct stu {
int num;
char name[20];
float sorce;
struct stu *next;
};
void output_sc(struct stu *head) {
struct stu *p;
for(p = head->next;p;p = p->next)
printf("%d %s %f\n",p->num,p->name,p->sorce);
printf("\n");
}
struct stu *creat() {
struct stu *head,*p;
int i,n,len;
len = sizeof(struct stu);
printf("please input the number of students : ");
scanf("%d",&n);
printf("please input students detials\n");
head = p = (struct stu *)malloc(len);
for(i = 0;i < n;i++) {
p->next = (struct stu *)malloc(len);
scanf("%d%s%f",&p->next->num,p->next->name,&p->next->sorce);
p = p->next;
}
p->next = NULL;
return(head);
}
int del(struct stu *head) {
struct stu *p,*q;
int num;
printf("請輸入要刪除的學號 : ");
scanf("%d",&num);
if(head->next == NULL) {
printf("此鏈表為空\n");
return 0;
}
p = head;
while(p->next != NULL) {
if(p->next->num == num) {
q = p->next;
p->next = q->next;
free(q);
return 1;
}
p = p->next;
}
printf("未找到相關信息\n");
return 0;
}
void output_df(struct stu *head) {
struct stu *p;
FILE *fp;
if((fp = fopen("D:\\data.txt","at+")) == NULL) {
printf("該文件不存在\n");
exit(0);
}
for(p = head->next;p != NULL;p=p->next)
fprintf(fp,"%d %s %f\n",p->num,p->name,p->sorce);
fclose(fp);
}
void df_sc(struct stu *head) {
struct stu s;
FILE *fp;
fp = fopen("D:\\data.txt","r");
if(fp == NULL) {
printf("無法打開文件\n");
exit(0);
}
while(!feof(fp) ) {
fscanf(fp,"%d%s%f",&s.num,s.name,&s.sorce);
printf("%d %s %f\n",s.num,s.name,s.sorce);
}
fclose(fp);
}
void main() {
struct stu *head;
while(1) {
int n;
printf("\t***********************************************\n");
printf("\t\t 歡迎使用學生成績管理系統\n");
printf("\t\t1.creat 2.del\n ");
printf("\t\t3.out-screen 4.out-datafaile\n");
printf("\t\t5.datafaile-screen 6.exit\n ");
printf("\t***********************************************\n");
printf("\t\tplease input selct 1--6\n");
printf("Select please : ");
scanf("%d",&n);
switch(n) {
case 1: head = creat(); break;
case 2: del(head); break;
case 3: output_sc(head); break;
case 4: output_df(head); break;
case 5: df_sc(head); break;
case 6: exit(0); break;
}
}
}