求教下面一道题

icelover 2004-04-01 10:59:02
5个学生,每个学生有3门课。从键盘输入以下数据:学号 姓名 三门课成绩 计算平均成绩,将原有数据和计算出的平均分数存放入以下磁盘文件“stud.dat”中,然后将文件“stud.dat”中的学生成绩按平均分进行排序处理,将已排序的学生数据存入一个新文件“studsort.dat”中。
要求使用链表完成
...全文
67 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
bideyore 2004-04-02
  • 打赏
  • 举报
回复
AGREE WITH Polarislee(北极星)
不会吧?楼主是不是做作业来的?这个问题刚有人问过,我感觉只要有基本的数据结构知识,就可以轻易做出来,我自己是用链表,顺序表各做了一个,高级一点还可以把文件操作,数据库加进去,总之自己做啦,骗分的确不错,不过讨论的意义不大,不知大家怎么想?
hslinux 2004-04-02
  • 打赏
  • 举报
回复
有道理,快动手编啊,现在开始也不晚~:)
北极猩猩 2004-04-02
  • 打赏
  • 举报
回复
怎么好向全国的作业都差不多啊,总是这些东西,早知道编一个全的,至少可以用来骗个几千分
wythust 2004-04-02
  • 打赏
  • 举报
回复
晕,太长了,分几次也贴不完,楼主有兴趣的话,给我你的email,我发给你
wythust 2004-04-02
  • 打赏
  • 举报
回复
我也来贴一个,以前C语言课设时写的,保证可以用:)
C语言课程设计

编写一个简单的教务管理程序。该程序具有如下功能:
1. 录入各班学生基本情况(如学号、姓名、性别、年龄、宿舍号码、电话号码等);
2. 插入某班某个学生的基本情况;
3. 修改各班学生基本情况;
4. 删除某班某个学生的基本情况;
5. 删除某班所有学生的基本情况;
6. 登记各班所有学生各门功课的成绩;
7. 修改某个学生某门功课的成绩;
8. 统计每个学生各门功课的平均成绩,并按平均成绩从高到低的次序排名输出每个学生各门功课的成绩和平均成绩(名次、学号、姓名、平均成绩、各门功课的成绩);
9. 统计并输出各班各门功课的平均成绩和总平成绩;
10. 列出不及格学生清单(学号、姓名、不及格的课程和成绩。

rorot 2004-04-02
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 课程名称
const char course[3][10] = { "Chinese", "Maths", "Physics" };
#define CHINESE 0
#define MATHS 1
#define PHYSICS 2

// 学生信息
typedef struct Node
{
// 学号
long number;
// 姓名
char name[20];
// 成绩
float score[3];
// 节点指针
struct Node *next;

}STUDENT;

// 学生链表
typedef struct STU_LINK
{
// 学生数量
int num_students;
// 头节点
struct Node *head;

}SLINK;

void Display();
// 初始化学生链表信息
void InitStudentLink(SLINK *SL);
// 从键盘获取学生信息
void InputStudent(SLINK *SL);
void DisplayStudent(SLINK *SL, long number, char *name);
void SaveStudents(SLINK *SL, const char *stuFile);
void SaveSortedStudents(SLINK *SL, const char *stuSortFile);
// 释放学生节点和学生链表内存
void DestroyStudents(SLINK *SL);
// 学生链表排序
void Sort(SLINK *SL);
// 交换两个节点的数据
void XChangeNode(STUDENT *s1, STUDENT *s2);

int main()
// 读取数据写入文件
{
int go = 1;
char choice;
// 文件名
const char stuFile[] = "e:\\temp\\stu.txt";
const char stuSort[] = "e:\\temp\\stuSort.txt";

// 学生信息链表
SLINK *SL = (SLINK*)malloc(sizeof(SLINK));
if (SL == NULL)
{
printf( "memory get error.\n" );
return -1;
}

// 初始化学生链表信息
InitStudentLink(SL);

while ( go )
{
// 显示基本信息
Display();
while ((choice = getchar()) == '\n');

switch(choice)
{
case 'w':
// 读取学生信息(从键盘输入)
InputStudent(SL);
break;
case 'v':
// 显示具体学生信息
DisplayStudent(SL, 0, "");
break;
case 's':
// 把当前的学生信息存盘
SaveStudents(SL, stuFile);
break;
case 'z':
// 把排好序的学生存盘
SaveSortedStudents(SL, stuSort);
break;
case 'q':
go = 0;
break;
}

}

// 释放内存
DestroyStudents(SL);
SL = NULL;

return 0;
}

// 平均分排序
void Sort(SLINK *SL)
{
float avScore, currentAVE;
STUDENT *next, *ptr = SL->head;
STUDENT tmp;

// 冒泡排序
for (; ptr->next != NULL; ptr=ptr->next )
{
// 冒泡排序的参照节点的平均分
avScore = ( ptr->score[0] +
ptr->score[1] +
ptr->score[2] ) / 3;
for (next = ptr->next; next != NULL; next = next->next)
{
// 当前平局分
currentAVE = ( next->score[0] +
next->score[1] +
next->score[2] ) / 3;
if ( currentAVE > avScore )
// 交换
{
XChangeNode( &tmp, next );
XChangeNode( next, ptr );
XChangeNode( ptr, &tmp );
avScore = currentAVE;
}
}
}
}

// 释放申请到的内存资源
void DestroyStudents(SLINK *SL)
{
STUDENT *ptr = SL->head;
while (ptr != NULL)
{
SL->head = ptr->next;
free(ptr);
ptr = SL->head;
}

SL->head = NULL;
ptr = NULL;
free(SL);
SL = NULL;
}

// 资料存盘
void SaveStudents(SLINK *SL, const char *filePath)
{
int i = 0, num_students = 0;
STUDENT *ptr = SL->head;

// 打开文件
FILE *in_file;
if ((in_file=fopen(filePath, "w")) == NULL)
{
printf( "%s open Error.\n", filePath );
return;
}

// 写入信息
while ( ptr != NULL )
{
fprintf (in_file, "Name: %s\tNumber: %d\n", ptr->name, ptr->number );
for (i=CHINESE; i <= PHYSICS; ++i)
fprintf(in_file, "%8s: %.1f\n", course[i], ptr->score[i] );
fprintf (in_file, "-----------------------------------------\n" );
num_students++;
ptr = ptr->next;
}

// 关闭文件
fclose(in_file);
}

// 给链表排序并存盘
void SaveSortedStudents(SLINK *SL, const char *filePath)
{
// 排序
Sort(SL);
SaveStudents(SL, filePath);
}

// 从键盘获取学生信息
void InputStudent(SLINK *SL)
{
int i = 0;
STUDENT *stu =(STUDENT*)malloc(sizeof(STUDENT));

printf( "Input number: " );
scanf ( "%d", &stu->number );
getchar();
printf( "Input name: " );
scanf ( "%s", stu->name );

for (i=CHINESE; i <= PHYSICS; ++i)
{
printf( "Input %s: ", course[i] );
scanf ( "%f", &stu->score[i] );
}

// 链表指针
stu->next = SL->head;
SL->head = stu;
SL->num_students++;
printf( "success.\n" );
}

// 初始化学生链表信息
void InitStudentLink(SLINK *SL)
{
SL->num_students = 0;
SL->head = NULL;
}

// 显示基本信息
void Display()
{
printf( "+--------------------------------------------+\n" );
printf( "| STUDENT |\n" );
printf( "+--------------------------------------------+\n" );
printf( "\tPress 'w' to write a new student.\n" );
printf( "\tPress 'v' to view student message.\n" );
printf( "\tPress 's' to save student File.\n" );
printf( "\tPress 'z' to sort and save File.\n" );
printf( "\tPress 'q' to quit.\n" );
printf( "Your choice: " );
}

// 显示具体学生的信息
void DisplayStudent(SLINK *SL, long number, char *name)
{
int i = 0;
float AverageScore;
STUDENT *ptr = SL->head;
while ( ptr != NULL )
{
printf ( "-----------------------------------------\n" );
printf ( "Name: %s\tNumber: %d\n", ptr->name, ptr->number );
for (i=CHINESE; i <= PHYSICS; ++i)
printf( "%8s: %.1f\n", course[i], ptr->score[i] );
// 平均分
AverageScore = ( ptr->score[0] +
ptr->score[1] +
ptr->score[2] ) / 3;
printf ( "%8s: %.1f\n", "Average", AverageScore );
// 指针下移
ptr = ptr->next;
}
printf( "There are %d students in all.\n", SL->num_students );
}

// 交换二个节点的数据
void XChangeNode(STUDENT *tmp, STUDENT *next)
{
strcpy(tmp->name, next->name);
tmp->number = next->number;
tmp->score[0] = next->score[0];
tmp->score[1] = next->score[1];
tmp->score[2] = next->score[2];
}
kjbmail 2004-04-02
  • 打赏
  • 举报
回复
5个学生、3门课还要用链表???
hehe
xinxinboy 2004-04-02
  • 打赏
  • 举报
回复
沉默,留下算法啊!我也想学习学习!,但代码太长...
runki 2004-04-02
  • 打赏
  • 举报
回复
学习了
jack_wq 2004-04-02
  • 打赏
  • 举报
回复
呵呵~~~偶向来对作业不感兴趣!
rorot 2004-04-01
  • 打赏
  • 举报
回复
俺本来就是写作业的。
junnyfeng 2004-04-01
  • 打赏
  • 举报
回复
rorot() ,好像很喜欢写作业 :)
rorot 2004-04-01
  • 打赏
  • 举报
回复
明天给你贴代码
zhangfjj 2004-04-01
  • 打赏
  • 举报
回复
运用C语言编制和调试下列程序

学生成绩管理
1.输入数据并存入数据
2.根据学号查寻成绩
3.根据姓名查寻成绩
4.输出文件内容
5.统计及格和优秀人数
6.退出程序

需求分析:
为用户提供进行功能选择的界面。功能选择包括输入数据(学生的学号、姓名和成绩)并存入文件、根据学号查询成绩、根据姓名查询成绩、显示文件内容、统计分析及结束程序运行。
根据用户的选择,进入相应的操作界面
根据界面的提示,输入相应的数据
为用户返回正确的运行结果
采用模块化程序设计方法,主函数用菜单式调用各功能函数,程序可读性强。界面设计友好,输出形式美观。

源代码:(自己写图形菜单、汉字处理)
#include "stdio.h"
#include "string.h"
typedef struct
{ char name[6];
int num;
int eng,math,tot;
} STUDENT;

readdat(STUDENT *stu,int *nn)
{
int i=0,n=*nn;
FILE *fp;
if((fp=fopen("record.txt","r"))==NULL)
{ printf("The record.txt can't open!");exit(0);
}
while(i<n)
{ stu[i].num=1001+i;
fscanf(fp,"%s %d %d",stu[i].name,&stu[i].eng,&stu[i].math);
if(!strcmp(stu[i].name,"****"))break;
if(stu[i].eng>=0&&stu[i].eng<=100&&stu[i].math>=0&&stu[i].math<=100)
{ stu[i].tot=stu[i].eng+stu[i].math;
i++;
}
}
fclose(fp);
*nn=i;
}

creat(STUDENT *stu,int *nn)
{
int n,i=0;
clrscr();
printf("Please enter the NUMBER of the record(s):(1~10)");
scanf("%d",&n);
if(n<1||n>10)
{ printf("The number is not correct!!");
exit(0);
}
else *nn=n;
printf("Please input the record(s) as following format:\n");
printf("Name English Math\n\n");
while(i<n)
{ stu[i].num=1001+i;
scanf("%s %d %d",stu[i].name,&stu[i].eng,&stu[i].math);
if(stu[n].eng>=0&&stu[n].eng<=100&&stu[n].math>=0&&stu[n].math<=100)
{ stu[i].tot=stu[i].eng+stu[i].math;
i++;
}
}
printf("\nThe record(s) is(are) inputed successfully\n");
}

index()
{ clrscr();
printf("\n\n\t1 Init Record(s)\n");
printf("\t2 List Record(s)\n");
printf("\t3 Insert Record\n");
printf("\t4 Delete Record\n");
printf("\t5 Modify Record\n");
printf("\t6 Search the Max Score\n");
printf("\t0 Exit\n\n");
}

list(STUDENT *stu,int n)
{
int i;
clrscr();
printf(" Num Name English Math TotalScore\n\n");
for(i=0;i<n;i++)
printf(" %-10d%-10s%-10d%-10d%-12d\n",stu[i].num,stu[i].name,stu[i].eng,stu[i].math,stu[i].tot);
}

insert(STUDENT **student,int *nn)
{
int i,n=*nn;
STUDENT *stu=*student;
clrscr();
if(n>=10)
{ stu=(STUDENT *)realloc(stu,(sizeof(STUDENT))*(n+1));
if(!stu) {printf("Insert Failed!!"); exit(0);}
*student=stu;
}
stu[n].num=stu[n-1].num+1;
printf("Please enter the Student's Name and English and Math's Score\n");
scanf("%s %d %d",stu[n].name,&stu[n].eng,&stu[n].math);
if(stu[n].eng>=0&&stu[n].eng<=100&&stu[n].math>=0&&stu[n].math<=100)
{ stu[n].tot=stu[n].eng+stu[n].math;
(*nn)+=1;
printf("\n\nThe record is inserted successfully");
}
else printf("\n\nThe score is(are) Error\n");
}

delete(STUDENT *stu,int *nn)
{
int i,m;
list(stu,*nn);
printf("\n\nPlease Enter the Num that you want to delete:");
getchar();
scanf("%d",&m);
if( (m>1000) && (m<=*nn+1000) )
{ for(i=0;i<*nn;i++)
if(stu[i].num==m)break;
if(i==*nn)
printf("\n\nThe %4d's record is not exist\n" ,m);
else
{ for(;i<*nn-1;i++)
stu[i]=stu[i+1];
(*nn)-=1;
printf("\n\nThe record is deleted successfully\n");
}
}
else printf("\n\nThe %4d's record is not exist\n" ,m);
}

modify(STUDENT *stu,int n)
{
int m,i;
STUDENT a;
list(stu,n);
printf("\n\nPlease Enter the Num that you want to delete(Enter n)to Cancer:");
getchar();
scanf("%d",&m);
if((m>1000)&&m<=n+1000)
{ for(i=0;i<n;i++)
if(stu[i].num==m)break;
if(i==n)
{ printf("\n\nThe %4d's record is not exist\n" ,m);
exit(0);
}
printf("Please enter the English and Math's Score\n");
scanf("%d %d",&a.eng,&a.math);
if(a.eng>=0&&a.eng<=100&&a.math>=0&&a.math<=100)
{ m=m-1;
stu[i].eng=a.eng;
stu[i].math=a.math;
stu[i].tot=stu[i].eng+stu[i].math;
printf("\n\nThe record is modified successfully\n");
}
else printf("\n\nThe score is(are) Error\n");
}
else printf("\n\nThe %4d's record is not exist\n" ,m);
}

search(STUDENT *stu,int n)
{
int i,k=0;
clrscr();
for(i=1;i<n;i++)
if(stu[i].tot>stu[k].tot) k=i;
printf("The best score is:\t%5d\n\n",stu[k].tot);
printf("The record's detail is(are): \n");
printf(" Num Name English Math TotalScore\n\n");
for(i=0;i<n;i++)
if(stu[i].tot==stu[k].tot)
printf(" %-10d%-10s%-10d%-10d%-12d\n",stu[i].num,stu[i].name,stu[i].eng,stu[i].math,stu[i].tot);
}

main()
{
STUDENT *stu;
int i,n=10,r;
stu=(STUDENT *)malloc(sizeof(STUDENT)*n);
if(!stu)
{ printf("ERROR\n"); exit(0); }
readdat(stu,&n);
while(1)
{ index();
printf(" Please choose the operation's number you want:");
scanf("%d",&r);
switch(r)
{ case 0: exit(0);
case 1: { creat(stu,&n); break; }
case 2: { list(stu,n); break; }
case 3: { insert(&stu,&n); break; }
case 4: { delete(stu,&n); break; }
case 5: { modify(stu,n); break; }
case 6: { search(stu,n); break; }
default: continue;
}
printf("\n\n\nPlease press Enter to continue...");
getchar();getchar();
}
}
//没有试过,是从某个贴子上(具体是哪一个,我倒忘了)能不能通过编译,我可不知道呀,一句话,谨供参考。你可以模仿着写一个试看看。

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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