简单c语言问题求助

pjhcn2000 2003-05-06 08:16:49
学生成绩报告单
1,2,3,4四门课,写一程序,任给一学生学号即可打印出该学生的成绩报告单.
成绩报告单
姓名:*** 学号:*** 1:*** 2:*** 3:*** 4:*** 总分:*** 名次:***
题目要求为输入一个学号,就能打印出其如上的成绩报告单,其中包括学号、姓名、四门成绩、总分和名次。要求计算出总分,并根据总分给出名次。

#define NULL 0
struct RECORD
{
char ID[12];
char name[30];
int record1,record2,record3,record4;
int sum;
struct RECORD *next;
};

typedef struct RECORD RECORD_STRUCT;
int main()
{
char option;
RECORD_STRUCT* student = NULL;

printf("Usage: input (i name ID value1 value2 value3 value4 )\n");
printf("Usage: output (o) \n");
printf("Usage: find and print (f ID) \n");
printf("Usage: exit (x) \n");
while(scanf("%c",&option) == 1)
{
switch(option)
{
case 'i':
{
int record[4];
int sum;
char s[12];
char nam[30];
if(scanf("%s %s %d %d %d %d",nam,s,&record[0],&record[1],&record[2],&record[3]) == 6)
{
RECORD_STRUCT* pLeft = student;
RECORD_STRUCT* pTmp = pLeft;
RECORD_STRUCT* pRight = (RECORD_STRUCT*)malloc(sizeof(RECORD_STRUCT));

sum = record[0]+record[1]+record[2]+record[3];
strcpy(pRight->name,nam);
strcpy(pRight->ID,s);
pRight->record1 = record[0];
pRight->record2 = record[1];
pRight->record3 = record[2];
pRight->record4 = record[3];
pRight->sum = sum;
pRight->next = NULL;
while(pTmp != NULL && pTmp->sum > sum)
{
pLeft = pTmp;
pTmp = pTmp->next;
}
pRight->next = pTmp;
if(pTmp == student)
student = pRight;
else if(pLeft != NULL)
pLeft->next = pRight;
pRight = NULL;
}
break;
}
case 'f':
{
char s[12];
char nam[30];
RECORD_STRUCT* pLeft = student;
int index = 1;
scanf("%s",s);
while(pLeft != NULL)
{
if(strcmp(pLeft->ID,s) == 0)
{
printf("Found successfully!\n");
printf(" name ID 1 2 3 4 sum index\n");
printf("%s %s %d %d %d %d %d %d\n",
pLeft->name,pLeft->ID,pLeft->record1,pLeft->record2,pLeft->record3,pLeft->record4,pLeft->sum,index);
break;
}
pLeft = pLeft ->next;
index++;
}
if(pLeft == NULL)
printf("Sorry,can't find the result!\n");
break;
}
case 'o':
{
int index = 1;
RECORD_STRUCT* pLeft = student;
printf("name ID 1 2 3 4 sum index\n");
while(pLeft != NULL)
{
printf("%s %s %d %d %d %d %d %d\n",
pLeft->name,pLeft->ID,pLeft->record1,pLeft->record2,pLeft->record3,pLeft->record4,pLeft->sum,index);
pLeft = pLeft->next;
index++;
}
break;
}
case 'x':
{
printf("Thank you for using this system,bye-bye!");
return;
}
}
}
}
只要解释一下算法
...全文
26 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,266

社区成员

发帖
与我相关
我的任务
社区描述
软件工程/管理 管理版
社区管理员
  • 研发管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧