利用C语言,建立一个五个学生的信息登记表,要求有学号、姓名、和三门课的成绩
发布网友
发布时间:2022-05-09 02:02
我来回答
共4个回答
热心网友
时间:2024-01-27 23:08
绝对能用,VC6.0运行调试可以用,试试就知道了,给点分啊
# include<stdio.h>
#include <string.h>
int presentnum ;
typedef struct student
{
int MATH;
int C;
int ENGLISH;
int TOTAL;
} stu;
char putinstuinfo(stu info[])
{
int i;
char fenshu=0;
for(i=1;i<=5;i++)
{
printf("%s%d%s\n","输入第",i,"个学生信息(科目之间相差一个tab键):");
printf("%s\t%s\t%s\t\n","MATH","C","ENGLISH");
scanf("%d %d %d",&info[i-1].MATH,&info[i-1].C,&info[i-1].ENGLISH);
info[i-1].TOTAL=info[i-1].MATH+info[i-1].C+info[i-1].ENGLISH;
}
printf("%s\n","输入@,回车保存学生信息");
while(getchar()!='@')
{
printf("%s\n","输入@,回车保存学生信息");
printf("请保存信息\n");
}
return '@';
}
void sequencetotal(stu info[],int totls[])
{
int i,j,temptotal,tempxiabiao;
for(i=0;i<5;i++)
{
totls[i]=i;
}
for(i=0;i<5;i++)
for(j=0;j<5-i-1;j++)
if(info[j].TOTAL<info[j+1].TOTAL)
{
temptotal=info[j].TOTAL;
info[j].TOTAL=info[j+1].TOTAL;
info[j+1].TOTAL=temptotal;
tempxiabiao=totls[j];
totls[j]=totls[j+1];
totls[j+1]=tempxiabiao;
}
}
int main(void)
{
char getnum;
stu info[5];
stu tempinfo[5];
int i;
int totls[5];
memset(&totls,0,sizeof(totls));
memset(&info,0,sizeof(info));
presentnum=1;
menu:
printf("%s\n","(1):信息输入(INPUT)");
printf("%s\n","(2):显示信息(DISPLAY)");
printf("%s\n","(3):总分统计(COUNT)");
printf("%s\n","(4):总分排序(SORT)");
printf("%s\n","(5):查询(QUERY)");
printf("%s\n","(@):返回主菜单");
while(1)
{
printf("%s\t","输入命令数字:");
getnum=getchar();
printf("\n");
switch(getnum)
{
case '1':
printf("%s\n","录入信息");
printf("\n");
if(putinstuinfo(info)=='@')
{
printf("保存信息成功\n");
goto menu;
}
break;
case '2':
printf("%s\n","显示信息");
printf("\n");
printf("%s\t%s\t%s\t\n","MATH","C","ENGLISH");
printf("%d\t%d\t%d\t\n",info[presentnum-1].MATH,info[presentnum-1].C,info[presentnum-1].ENGLISH);
break;
case '3':
printf("%s\n","总分统计");
printf("\n");
for(i=0;i<5;i++)
{
printf("%s%d%s\t%d\n","第",i+1,"学生总分:",info[i].TOTAL);
}
break;
case '4':
printf("%s\n","总分排序");
printf("\n");
memcpy(tempinfo,info,sizeof(info));
sequencetotal(info,totls);
memcpy(info,tempinfo,sizeof(tempinfo));
printf("%s\t\t%s\t%s\t%s\t\t%s\n","名称","MATH","C","ENGLISH","TOTAL");
for(i=0;i<5;i++)
{
printf("%s%d%s\t%d\t%d\t%d\t\t%d\t\n","学生",totls[i]+1,"成绩",info[totls[i]].MATH,info[totls[i]].C,info[totls[i]].ENGLISH,info[totls[i]].TOTAL);
}
break;
case '5':
printf("%s\n","查询学生信息");
printf("\n");
printf("%s\t","输入学生序号:");
scanf("%d",&presentnum);
printf("%s\t%s\t%s\t%s\n","MATH","C","ENGLISH","TOTAL");
printf("%d\t%d\t%d\t%d\t\n",info[presentnum-1].MATH,info[presentnum-1].C,info[presentnum-1].ENGLISH,info[presentnum-1].TOTAL);
break;
case '@':
goto menu;
break;
default:
break;
}
}
}
热心网友
时间:2024-01-27 23:08
差不多的,自己修改下。
#include <stdio.h>
#include <string.h>
const int MAX_NUM = 5;
const int MAX_NAME_LEN = 127;
const int MAX_SUBJECT = 3;
const double SUBJECTS = 3.0;
typedef struct _Student
{
char szName[MAX_NAME_LEN + 1];
int nArryScore[MAX_SUBJECT];
int nSum;
double dAverage;
}Student;
void Sort(Student students[], int n)
{
Student stTmp;
int nTmp = 0;
int nPos = 0;
int nIndex = 0;
for (nPos = 0; nPos < n - 1; nPos++)
{
nTmp = nPos;
memset(&stTmp, 0, sizeof(Student));
for (nIndex = nPos + 1; nIndex < n; nIndex++)
{
if (students[nIndex].nSum > students[nTmp].nSum)
{
nTmp = nIndex;
}
}
memcpy(&stTmp, &students[nTmp], sizeof(Student));
memcpy(&students[nTmp], &students[nPos], sizeof(Student));
memcpy(&students[nPos], &stTmp, sizeof(Student));
}
}
int main (void)
{
printf("请输入五个同学三门课的成绩:\n");
Student students[MAX_NUM];
memset(students, 0, sizeof(students));
Student* pStudent = NULL;
int nCnt = 0;
int nPos = 0;
while (MAX_NUM > nCnt)
{
printf("第%d个同学的记录:", nCnt + 1);
pStudent = &students[nCnt];
scanf("%s %d %d %d", pStudent->szName,
&pStudent->nArryScore[0],
&pStudent->nArryScore[1],
&pStudent->nArryScore[2]);
for (nPos = 0; nPos < MAX_SUBJECT; nPos++)
{
pStudent->nSum += pStudent->nArryScore[nPos];
}
pStudent->dAverage = pStudent->nSum / SUBJECTS;
nCnt++;
getchar();
}
Sort(students, MAX_NUM);
printf("------------------------------------------------\n");
printf("输出排序后五个同学的三门成绩:\n");
printf("------------------------------------------------\n");
printf("排序 姓名 课1 课2 课3 总分 平均分\n");
for (nPos = 0; nPos < MAX_NUM; nPos++)
{
pStudent = &students[nPos];
printf("第%d名: %s %d %d %d %d %.2f\n", nPos + 1,
pStudent->szName,
pStudent->nArryScore[0],
pStudent->nArryScore[1],
pStudent->nArryScore[2],
pStudent->nSum,
pStudent->dAverage);
}
return 0;
}
热心网友
时间:2024-01-27 23:09
http://www.google.com/search?q=%E5%88%A9%E7%94%A8C%E8%AF%AD%E8%A8%80%EF%BC%8C%E5%BB%BA%E7%AB%8B%E4%B8%80%E4%B8%AA%E4%BA%94%E4%B8%AA%E5%AD%A6%E7%94%9F%E7%9A%84%E4%BF%A1%E6%81%AF%E7%99%BB%E8%AE%B0%E8%A1%A8%EF%BC%8C%E8%A6%81%E6%B1%82%E6%9C%89%E5%AD%A6%E5%8F%B7%E3%80%81%E5%A7%93%E5%90%8D%E3%80%81%E5%92%8C%E4%B8%89%E9%97%A8%E8%AF%BE%E7%9A%84%E6%88%90%E7%BB%A9&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:zh-CN:official&client=firefox-a
热心网友
时间:2024-01-27 23:09
50分我帮你写