📄 chencong.c
字号:
for(i=0;i<NUMOFCOURSE;i++) /* 以每门课为单位输出 */
{
printf("\nNO.%d\'s Usualscore:%-5d",i+1,p->ususcore[i]);
printf("\nNO.%d\'s Textscore:%-5d",i+1,p->textscore[i]);
printf("\nNO.%d\'s Score:%-8.2f",i+1,p->score[i]);
}
printf("\nSumscore:%-10.2f",p->sum);
printf("\nAveragescore:%-15.2f",p->average);
printf("\nStudyscore:%-10d",p->stscore);
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
p=p->next; /* 下一个节点 */
}
}
}
void allsumaverage(STU *head) /* 求六门课的总成绩和平均分 */
{
STU *p;
double a=0,b=0,c=0,d=0,e=0,f=0; /* 六门课的总分参数 */
float g,h,k,l,m,n; /* 六门课的平均分参数 */
int i=0;
p=head->next;
if(p==NULL)
{
printf("\nThe Record is empty!");
}
else
while(p!=NULL)
{
{ a=a+p->score[0];
b=b+p->score[1];
c=c+p->score[2];
d=d+p->score[3];
e=e+p->score[4];
f=f+p->score[5];
++i;
}
p=p->next;
}
g=a/i;
h=b/i;
k=c/i;
l=d/i;
m=e/i;
n=f/i;
printf("\nNO.1\'s allsumscore:%f",a);
printf("\nNO.1\'s allaveragescore:%f",g);
printf("\nNO.2\'s allsumscore:%f",b);
printf("\nNO.2\'s allaveragescore:%f",h);
printf("\nNO.3\'s allsumscore:%f",c);
printf("\nNO.3\'s allaveragescore:%f",k);
printf("\nNO.4\'s allsumscore:%f",d);
printf("\nNO.4\'s allaveragescore:%f",l);
printf("\nNO.5\'s allsumscore:%f",e);
printf("\nNO.5\'s allaveragescore:%f",m);
printf("\nNO.6\'s allsumscore:%f",f);
printf("\nNO.6\'s allaveragescore:%f",n);
}
void AppendNode(STU *head) /* 添加节点 */
{
char c;
int size;
STU *p,*newnode,*last;
if(!OkOrNot("Append"))return;
last=head; /* last为最后一个节点的指针 */
p=head->next; /* p为新节点的指针 */
while(p!=NULL) /* 从头节点到最后的节点 */
{
last=p;
p=p->next;
}
size=GetNodeNumber(head); /* 将节点数目赋值给size */
newnode=(STU*)malloc(sizeof(STU)); /* 给新节点分配空间 */
newnode->next=NULL;
p=InputNewRecord(newnode);
newnode->number=size;
last->next=p;
}
STU *InputNewRecord(STU *node) /* 输入一个新节点 */
{
int i;
printf("\nInput Number:"); /* 打印要求并输入 */
scanf("%d",&node->number);
printf("\nInput StudentNumber:");
scanf("%s",node->sn);
printf("\nInput Name:");
scanf("%s",node->name);
printf("\nInput Sex:");
scanf("%s",node->sex);
printf("\nInput Age:");
scanf("%d",&node->age);
printf("\nInput Roomnumber:");
scanf("%s",node->room);
printf("\nInput Phonenumber:");
scanf("%s",node->phone);
for(i=0;i<NUMOFCOURSE;i++)
{
printf("\nInput NO.%d\'s Usualscore:",i+1);
scanf("%d",&node->ususcore[i]);
printf("\nInput NO.%d\'s Textscore:",i+1);
scanf("%d",&node->textscore[i]);
}
Score(node); /* 输入最后分数 */
SumAverage(node); /* 输入总分和平均成绩 */
Studyscore(node); /* 输入学分 */
return node; /* 返回节点 */
}
void DeleteNode(STU *head) /* 删除节点 */
{
STU *nownode; /* 定义当前节点 */
char name[20];
printf("\nInput the name that you want to delete:");
scanf("%s",name);
if(!OkOrNot("delete")) /* 确定是否删除 */
return;
nownode=FindOneNode(head,name); /* 将找到的节点赋给当前节点 */
if(nownode!=NULL&&nownode==head)
{
firsthead=nownode->next;
head->next=nownode->next;
}
if(nownode!=NULL&&nownode->next==NULL)
FindPreNode(nownode)->next=NULL;
else
FindPreNode(nownode)->next=nownode->next;
printf("\nThe record of %s has been delete",name);
if(nownode==NULL)
printf("\nCan't find the record of %s",name);
}
void ChangeNode(STU *head) /* 更改节点 */
{
STU *nownode;
int i;
char name[20];
printf("\nInput the name of changing record:");
scanf("%s",name);
if(!OkOrNot("change")) /* 确定是否更改 */
return;
nownode=FindOneNode(head,name); /* 将找到的节点赋给当前节点 */
if (nownode!=NULL) /* 打印该节点对应的数据 */
{
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\nNumber:%-4d",nownode->number);
printf("\nStudynumber:%-15s",nownode->sn);
printf("\nName:%-20s",nownode->name);
printf("\nSex:%-6s",nownode->sex);
printf("\nAge:%-8d",nownode->age);
printf("\nRoomnumber:%-20s",nownode->room);
printf("\nTelephonenumber:%-15s",nownode->phone);
for(i=0;i<NUMOFCOURSE;i++)
{
printf("\nNO.%d\'s Usualscore:%-5d",i+1,nownode->ususcore[i]);
printf("\nNO.%d\'s Textscore:%-5d",i+1,nownode->textscore[i]);
printf("\nNO.%d\'s Score:%-8.2f",i+1,nownode->score[i]);
}
printf("\nSumscore:%-10.2f",nownode->sum);
printf("\nAveragescore:%-15.2f",nownode->average);
printf("\nStudyscore:%-10d",nownode->stscore);
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
InputNewRecord(nownode); /* 输入新的数据 */
}
}
void Sort(STU *head) /* 按平均分从大到小排序 */
{
STU *temp;
STU temp1;
int flag=0,i;
for( ; ;)
{
flag=0;
temp=head->next;
while(temp->next!=NULL) /* 冒泡排序法 */
{
if(temp->sum<temp->next->sum) /* 如果前一个节点的总分比后面的小 */
{
strcpy(temp1.sn,temp->sn); /* 交换 */
strcpy(temp1.name,temp->name);
strcpy(temp1.sex,temp->sex);
temp1.age=temp->age;
strcpy(temp1.room,temp->room);
strcpy(temp1.phone,temp->phone);
for(i=0;i<NUMOFCOURSE;i++)
{
temp1.ususcore[i]=temp->ususcore[i];
temp1.textscore[i]=temp->textscore[i];
temp1.score[i]=temp->score[i];
}
temp1.sum=temp->sum;
temp1.average=temp->average;
temp1.stscore=temp->stscore;
strcpy(temp->sn,temp->next->sn);
strcpy(temp->name,temp->next->name);
strcpy(temp->sex,temp->next->sex);
temp->age=temp->next->age;
strcpy(temp->room,temp->next->room);
strcpy(temp->phone,temp->next->phone);
for(i=0;i<NUMOFCOURSE;i++)
{
temp->ususcore[i]=temp->next->ususcore[i];
temp->textscore[i]=temp->next->textscore[i];
temp->score[i]=temp->next->score[i];
}
temp->sum=temp->next->sum;
temp->average=temp->next->average;
temp->stscore=temp->next->stscore;
strcpy(temp->next->sn,temp1.sn);
strcpy(temp->next->name,temp1.name);
strcpy(temp->next->sex,temp1.sex);
temp->next->age=temp1.age;
strcpy(temp->next->room,temp1.room);
strcpy(temp->next->phone,temp1.phone);
for(i=0;i<NUMOFCOURSE;i++)
{
temp->next->ususcore[i]=temp1.ususcore[i];
temp->next->textscore[i]=temp1.textscore[i];
temp->next->score[i]=temp1.score[i];
}
temp->next->sum=temp1.sum;
temp->next->average=temp1.average;
temp->next->stscore=temp1.stscore;
flag=1;
}
temp=temp->next; /* 到下一个节点 */
}
if(!flag)break;
}
printf("\nSort success");
}
void SearchNode(STU *head) /* 搜索节点并打印 */
{
int i;
STU *nownode;
char name[20],c;
printf("\nInput the name for searching:"); /* 按名字查找 */
scanf("%s",name);
nownode=FindOneNode(head,name);
if(nownode!=NULL) /* 找到后打印 */
{
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\nNumber:%-4d",nownode->number);
printf("\nStudynumber:%-15s",nownode->sn);
printf("\nName:%-20s",nownode->name);
printf("\nSex:%-6s",nownode->sex);
printf("\nAge:%-8d",nownode->age);
printf("\nRoomnumber:%-20s",nownode->room);
printf("\nTelephone:%-15s",nownode->phone);
for(i=0;i<NUMOFCOURSE;i++)
{
printf("\nNO.%d\'s Usualscore:%-5d",i+1,nownode->ususcore[i]);
printf("\nNO.%d\'s Textscore:%-5d",i+1,nownode->textscore[i]);
printf("\nNO.%d\'s Score:%-8.2f",i+1,nownode->score[i]);
}
printf("\nSumscore:%-10.2f",nownode->sum);
printf("\nAveragescore:%-15.2f",nownode->average);
printf("\nStudyscore:%-10d",nownode->stscore);
}
else
{
printf("\nCan't find %s",name);
}
}
STU *FindOneNode(STU *head ,char *name) /* 查找节点,返回节点地址 */
{
STU *next=head;
while(strcmp(next->name,name)!=0&&next->next!=NULL) /* 当名字不同时到下一节点 */
{
next=next->next;
}
if(strcmp(next->name,name)==0) /* 当名字相同时,返回节点地址 */
return next;
return NULL;
}
STU *FindNextNode(STU *head) /* 查找下一个节点 */
{
return head->next;
}
STU *FindPreNode(STU *head) /* 查找前一个节点 */
{
STU *next;
next=firsthead;
while(next->next!=NULL)
{
if(next->next==head)
return next;
next=next->next;
}
return NULL;
}
void SumAverage(STU *head) /* 计算一个学生的总分和平均成绩 */
{
int i;
STU *nownode;
float sum=0,average;
nownode=head;
for(i=0;i<NUMOFCOURSE;i++) /* 遍历六门课 */
sum=sum+nownode->score[i];
average=sum/NUMOFCOURSE;
nownode->sum=sum;
nownode->average=average;
}
void Score(STU *head) /* 计算一门课的最后成绩 */
{
int i;
STU *nownode;
float score;
nownode=head;
for(i=0;i<NUMOFCOURSE;i++) /* 六门课 */
{
score=(nownode->ususcore[i])*0.3+(nownode->textscore[i])*0.7;
/* 平时成绩占30%,考试占70% */
nownode->score[i]=score; /* 将分数赋值到结构中 */
}
}
void Studyscore(STU *head) /* 求学分 */
{
STU *nownode;
int stscore=0;
nownode=head;
if(nownode->score[0]>60) /* 第一门课成绩大于60分时 */
stscore=stscore+1; /* 学分加1,第一课1个学分 */
if(nownode->score[1]>60) /* 第二门课成绩大于60分时 */
stscore=stscore+2; /* 学分加2,第一课2个学分 */
if(nownode->score[2]>60) /* 第三门课成绩大于60分时 */
stscore=stscore+3; /* 学分加3,第一课3个学分 */
if(nownode->score[3]>60) /* 第四门课成绩大于60分时 */
stscore=stscore+4; /* 学分加4,第一课4个学分 */
if(nownode->score[4]>60) /* 第五门课成绩大于60分时 */
stscore=stscore+5; /* 学分加5,第一课5个学分 */
if(nownode->score[5]>60) /* 第六门课成绩大于60分时 */
stscore=stscore+2; /* 学分加2,第一课2个学分 */
nownode->stscore=stscore; /* 将学分赋值到结构中 */
}
int OkOrNot(char *name) /* 确定是否 */
{
char c;
printf("\nDo you really want to %s ?(y/n)",name);
c=getch();
if(c=='y'||c=='Y')
return TRUE;
else
return FALSE;
}
void Exit() /* 返回到DOS */
{
char c;
printf("\nDo you want to return to Dos?(y/n)");
c=getch();
if(c=='y'||c=='Y')
exit(0); /* 离开 */
else
return;
}
void listfail(STU *head) /* 列举不及格的学生信息 */
{
int flag=1; /* 选择参数 */
STU *p;
int i;
p=head->next;
if(p==NULL)
printf("The Record is empty!"); /* 没有学生信息记录 */
else
{
while(p!=NULL) /* 从头开始 */
{
if(p->stscore<17) /* 当学分不足17个满学分时 */
{flag=0;
printf("\n%-12s has some failing course\n:",p->name);
for(i=0;i<NUMOFCOURSE;i++) /* 分析每一门课 */
{
if(p->score[i]<60) /* 不及格即小于60 */
printf("NO.%d:%-8.2f",i+1,p->score[i]); /* 打印挂科科目和成绩 */
}
}
p=p->next;
}
}
if(flag)
printf("Nobody has failed!"); /* 当没有挂科时 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -