數據結構c學生成績管理系統
① 高分急求一個C++數據結構課設 學生成績管理系統
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
#define max 100;
class student
{
public:
student *next;
public:
string name;//姓名
long num;//學號
int x,y,z;//數學,語文,英語
int AA;//總分
void play(){cout<<name<<"學生的學號是"<<num<<",數學:"<<x<<",語文:"<<y<<",英語:"<<z<<",總分:"<<AA<<endl;};
student(string sname,long snum,int sx,int sy,int sz)
{
name=sname;
num=snum;
x=sx;
y=sy;
z=sz;
}
};
class cla
{
public:
cla()//構造函數
{
stu=0;
sload();
}
~cla()//析構函數
{
student *p;
p=stu;
while(p)
{
p=p->next;
delete stu;
stu=p;
}
stu=0;
}
void sadd(); //添加
void sremove(); //刪除
void samend(); //修改
void ssearch(); //查詢
void staxis(); //排序
void ssave(); //保存
void sload(); //讀取
//排序函數
void pxh();
void psx();
void pyw();
void pyy();
void pAA();
private:
student *stu; //頭接點
};
void cla::sadd()//添加
{
student *q;
string name1;
long num1;
int x1,y1,z1;
system("cls");
cout<<"\n **增加的學生** \n"<<endl;
cout<<"請輸入學生的(中間用空格間隔) "<<endl;
cout<<"姓名 學號 數學成績 語文成績 英語成績:"<<endl;
cin>>name1>>num1>>x1>>y1>>z1;
q=new student(name1,num1,x1,y1,z1);
q->next=0;
q->AA=x1+y1+z1;
if(stu)
{
student *t;
t=stu;
if(t->num==num1)
{
cout<<"學號已存在,請重新輸入"<<endl;
return;
}
while(t->next)
{
if(t->num==num1)
{
cout<<"學號已存在,請重新輸入"<<endl;
return;
}
t=t->next;
}
t->next=q;
}
else
{
stu=q;
}
cout<<"輸入完畢"<<endl;
}
void cla::sremove()//刪除
{
system("cls");
int num1;
cout<<"\n** 刪除學生信息 **\n";
cout<<"請輸入想要刪除學生的學號:";
cin>>num1;
//查找要刪除的結點
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
//刪除結點
if(p1!=NULL)//若找到結點,則刪除
{
p1->play();
cout<<"確定刪除嗎?[Y/N]"<<endl;
char c;cin>>c;
if(toupper(c)!='Y') return;
if(p1==stu) //若要刪除的結點是第一個結點
{
stu=p1->next;
delete p1;
}
else //若要刪除的結點是後續結點
{
p2->next=p1->next;
delete p1;
}
cout<<"找到學號為"<<num1<<"的學生,並刪除\n";
}
else //未找到結點
cout<<"未找到想要刪除的學生!\n";
}
void cla::samend()//修改
{
system("cls");
long num1;
cout<<"\n** 修改學生信息 **\n";
cout<<"輸入要修改學生的學號";
cin>>num1;
//查找要修改的結點
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<"學號是"<<num1<<"的學生的信息"<<endl;
cout<<"姓名 "<<p1->name<<"數學"<<p1->x<<"語文"<<p1->y<<"英語"<<p1->z<<endl;
cout<<"請輸入修改後的信息:姓名 數學成績 語文成績 英語成績"<<endl;
cin>>p1->name>>p1->x>>p1->y>>p1->z;
p1->AA=p1->x+p1->y+p1->z;
cout<<"修改成功"<<endl;
}
else //未找到接點
cout<<"未找到!\n";
}
void cla::ssearch()//查詢
{
system("cls");
cout<<"\n** 查詢學生信息 **\n"<<endl;
cout<<"請輸入查詢方式:"<<endl;
cout<<"1.按學號查詢"<<endl;
cout<<"2.按姓名查詢"<<endl;
cout<<"3.返回"<<endl;
char c; cin>>c;
switch (c)
{
case '1':
{
long num1;
cout<<"要查詢的學號"<<endl;
cin>>num1;
//查找要查詢的結點
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->num==num1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<"學號是"<<num1<<"的學生的信息"<<endl;
cout<<"姓名:"<<p1->name<<" 數學:"<<p1->x<<" 語文:"<<p1->y<<" 英語:"<<p1->z<<endl;
cout<<"查詢完畢...";
}
else //未找到接點
cout<<"未找到!\n";
break;
}
case '2':
{
string name1;
cout<<"要查詢的學生姓名"<<endl;
cin>>name1;
//查找要查詢的結點
student *p1,*p2;
p1=stu;
while(p1)
{
if(p1->name==name1)
break;
else
{
p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{
cout<<name1<<"的學生的信息"<<endl;
cout<<"學號:"<<p1->num<<" 數學:"<<p1->x<<" 語文:"<<p1->y<<" 英語:"<<p1->z<<endl;
cout<<"查詢完畢...";
}
else //未找到接點
cout<<"未找到!\n";
break;
}
case '3': return;
}
}
void cla::pxh() //按學號排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"條信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{
p1=stu;
if (p1->num>p1->next->num) // 如果頭結點大於第二個的
{
p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //頭結點交換
stu=p2;
}
p1=stu;
while(p1->next->next) //中間的交換
{
p2=p1;
p1=p1->next;
if(p1->num>p1->next->num)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交換
}
}
}
p1=stu;
do
{
p1->play();
p1=p1->next;
}while(p1);
}
void cla::psx()//按數學成績排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"條信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->x>p1->next->x) // 如果頭結點大於第二個的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //頭結點交換
stu=p2;
}
p1=stu;
while(p1->next->next) //中間的交換
{ p2=p1;
p1=p1->next;
if(p1->x>p1->next->x)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交換
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
void cla::pyw()//按語文成績排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"條信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->y>p1->next->y) // 如果頭結點大於第二個的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //頭結點交換
stu=p2;
}
p1=stu;
while(p1->next->next) //中間的交換
{ p2=p1;
p1=p1->next;
if(p1->y>p1->next->y)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交換
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
void cla::pyy()//按英語成績排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"條信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->z>p1->next->z) // 如果頭結點大於第二個的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //頭結點交換
stu=p2;
}
p1=stu;
while(p1->next->next) //中間的交換
{ p2=p1;
p1=p1->next;
if(p1->z>p1->next->z)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交換
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
void cla::pAA()//按總分排序
{
student *p1,*p2;
int n;
p1=stu;
n=1;
while(p1->next)
{ n++; p1=p1->next; }
cout<<"共有"<<n<<"條信息..."<<endl;
int i;
p1=stu;
for(i=1;i<n;i++)
{ p1=stu;
if (p1->AA>p1->next->AA) // 如果頭結點大於第二個的
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1; //頭結點交換
stu=p2;
}
p1=stu;
while(p1->next->next) //中間的交換
{ p2=p1;
p1=p1->next;
if(p1->AA>p1->next->AA)
{
p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next; //交換
}
}
}
p1=stu;
do
{ p1->play();
p1=p1->next;
}while(p1);
}
void cla::staxis()//排序
{
system("cls");
char c;
cout<<"請選擇以何種方式排序:"<<endl;
cout<<"1……以學號排序"<<endl;
cout<<"2……以數學成績排序"<<endl;
cout<<"3……以語文成績排序"<<endl;
cout<<"4……以英語成績排序"<<endl;
cout<<"5……以總分排序"<<endl;
cout<<"6……返回"<<endl;
cout<<"請選擇(1-6)"<<endl;
cin>>c;
switch (c)
{
case '1':pxh(); break;
case '2':psx(); break;
case '3':pyw(); break;
case '4':pyy(); break;
case '5':pAA(); break;
case '6':return;
}
}
void cla::ssave() //保存到文件
{
system("cls");
char c;
cout<<"\n保存學生信息(將覆蓋原文件),是否繼續?[Y/N]:"; cin>>c;
if(toupper(c)!='Y') return;
ofstream tfile("date.txt",ios_base::binary);
student *p=stu;
while(p)// 寫入文件
{
tfile<<p->name<<"\t"<<p->num<<"\t"<<p->x<<"\t"<<p->y<<"\t"<<p->z;
tfile<<endl;
p=p->next;
}
tfile.close();
cout<<"保存完畢..."<<endl;
}
void cla::sload() //讀取
{
student *p;
p=stu;
while(p)
{
stu=p->next;
delete p;
p=stu;
}
ifstream tfile("date.txt",ios_base::binary);
string name1;
long num1;
int x1,y1,z1;
tfile>>name1>>num1>>x1>>y1>>z1;
while(tfile.good())
{
//創建學生接點
student *s;
s=stu;
s=new student(name1,num1,x1,y1,z1);
s->next=0;
s->AA=x1+y1+z1;
if(stu) //若已經存在結點
{
student *p2;
p2=stu;
while(p2->next) //查找尾結點
{
p2=p2->next;
}
p2->next=s; //連接
}
else //若不存在結點(表空)
{
stu=s; //連接
}
tfile>>name1>>num1>>x1>>y1>>z1;
}
tfile.close();
cout<<"\n學生信息已經裝入...\n";
}
void main()
{
char c;
cla a;
do
{
cout<<"\n 學 生 成 績 管 理 系 統 \n";
cout<<"**************************************\n";
cout<<" 作者:軟體工程06110119:zgjxwl \n";
cout<<" 1……增加學生 \n";
cout<<" 2……刪除學生 \n";
cout<<" 3……修改學生 \n";
cout<<" 4……查詢學生信息 \n";
cout<<" 5……排序 \n";
cout<<" 6……保存信息 \n";
cout<<" 7……讀取信息 \n";
cout<<" 8……退出 \n";
cout<<"**************************************\n";
cout<<"請選擇(1-8):";
cin>>c;
switch(c)
{
case '1': a.sadd();break;
case '2': a.sremove();break;
case '3': a.samend();break;
case '4': a.ssearch();break;
case '5': a.staxis();break;
case '6': a.ssave();break;
case '7': a.sload();break;
}
}while(c!='8');
}
② 數據結構用C語言編寫學生成績管理系統
我上個學期的實習作業,要求基本一樣,不過你還是要改改的
③ 數據結構鏈表c語言建立學生成績管理系統
#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include<string.h>
typedefstructdata{
intnumber;
charname[20];
charid[20];
doublescore[3];
}dataType;
typedefstructlist{
dataTypepauline;
structlist*next;
}*LinkList,*pNode,Node;
void*getMemory(size_tsize){
returnmalloc(size);
}
LinkListgetEmptyList(){
LinkListhead=(pNode)getMemory(sizeof(Node));
memset(head,0,sizeof(Node));
returnhead;
}
intaddNode(LinkListhead,pNodepnode){
pNodeq;
for(q=head;q->next;q=q->next)
if(q->next->pauline.number==pnode->pauline.number){
printf("重復的學號:%d ",pnode->pauline.number);
return0;
}
q->next=pnode;
pnode->next=NULL;
return1;
}
//按學號升排序
voidsortNumber(LinkListhead){
pNodep,q,pt,qt;
p=head;
while(p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.number>q->next->pauline.number)
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
p=p->next;
}
}
//按第th門成績降排序,th=1,2,3
voidsortScore(LinkListhead,intth){
pNodep,q,pt,qt;
inti;
if(th<1||th>3)return;
i=th-1;
for(p=head;p->next;p=p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.score[i]<q->next->pauline.score[i])
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
}
}
voidshow(LinkListhead){
pNodep;
for(p=head->next;p;p=p->next ){
printf("%d %s %s %.2lf %.2lf %.2lf ",
p->pauline.number,p->pauline.name,p->pauline.id,
p->pauline.score[0],p->pauline.score[1],p->pauline.score[2]);
}
}
pNodereadData(){
pNodepnode=(pNode)getMemory(sizeof(Node));
inti;
printf("學號:");
scanf("%d",&pnode->pauline.number);
printf("姓名:");
scanf("%s",pnode->pauline.name);
printf("身份證:");
scanf("%s",pnode->pauline.id);
for(i=0;i<3;++i){
printf("第%d門成績:",i+1);
scanf("%lf",&pnode->pauline.score[i]);
}
returnpnode;
}
voidmenu(){
printf("******************************** ");
printf("******學生成績管理系統****** ");
printf("******************************** ");
printf("*1、添加學生信息* ");
printf("*2、顯示學生信息* ");
printf("*3、按學號排序* ");
printf("*4、按成績排序* ");
printf("******************************** ");
printf("*0、退出* ");
printf("******************************** ");
}
intmain(){
charop[20];
intselect;
LinkListhead=getEmptyList();
do{
menu();
printf("請選擇:");
fflush(stdin);
fgets(op,20,stdin);
fflush(stdin);
switch(op[0]-'0'){
case1:addNode(head,readData());break;
case2:show(head);break;
case3:sortNumber(head);break;
case4:printf("按第幾門功課排序;");
scanf("%d",&select);
sortScore(head,select);
break;
}
}while(op[0]-'0');
printf("END ");
return0;
}
④ c語言數據結構學生成績管理系統怎麼限制學號范圍
你用int類型來當作學號的類型,首先學號的第一位如果是0則無法顯示出來專,其次是int類型能表示屬的數的范圍問題。去掉這些問題,8位數的最大數字為99999999,只需要判斷這個數小於99999999即可。
⑤ 數據結構,用C語言實現,基於鏈表的學生成績管理系統,根據學號和姓名創建索引
看可以不咯?#includeintavgGrade(inta[50]){inti,sum=0,max=0,min=0;doubleavg=0.0;max=a[0];min=a[0];for(i=0;imax)max=a[i];if(a[i]a[i]){temp=a[i];a[i]=a[j];a[j]=temp;}}else{if(a[j]a[i]){for(s=49;s>=i;s--)a[s+1]=a[s];break;}a[i]=n;}intdeleteGrade(inta[50]){intx,i,j;printf("請輸入你要刪除的成績:\n");scanf("%d",&x);for(i=0;i<10;i++){if(a[i]==x)for(j=i+1;j<10;j++)a[i]=a[j];a[j]='\0';}}voidmain(){intn,i,a[50];printf("請輸入50個學生的成績:\n");for(i=0;i<50;i++){scanf("%d",&a[i]);}while(1){printf("--------------------------\n");printf("請選擇您的功能:\n\n");printf("0錄入成績\n");printf("1輸出成績\n");printf("2輸出平均分、最高分、最低分\n");printf("3成績降序或升序排列\n");printf("4插入一個成績\n");printf("5刪除用戶給定的成績\n");printf("6退出\n\n");printf("--------------------------\n");scanf("%d",n);switch(n){case0:printf("請輸入50個學生的成績:\n");for(i=0;i<50;i++){scanf("%d",&a[i]);}break;case1:for(i=0;i<50;i++){printf("%d",a[i]);}break;case2:avgGrade(a);break;case3:compositor(a);break;case4:insertGrade(a);break;case5:deleteGrade(a);break;case6:exit(0);}}return0;}
⑥ C語言數據結構 編寫【學生成績管理系統】
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <memory.h>
#include <string.h>
#define FILE1 "1.txt"
#define FILE2 "2.txt"
#define FILE3 "3.txt"
#define FILE4 "4.txt"
struct STUDENT
{
char name[20];
int number;
int chinese;
int math;
int english;
int total;
};
typedef STUDENT student;
int count = 0;
student *ss = NULL;
void combine2files()
{
FILE *in, *out;
student s;
out = fopen(FILE3, "w");
in = fopen(FILE1, "r");
if (! || !out)
{
printf("can't open file(s)\n");
exit(-1);
}
while (1)
{
s.name[0] = '\0';
fscanf(in, "%s %d %d %d %d", s.name, &s.number, &s.chinese, &s.math, &s.english);
if (s.name[0] == '\0')
break;
++count;
fprintf(out, "%s %d %d %d %d\n", s.name, s.number, s.chinese, s.math, s.english);
/* printf("%s %d %d %d %d\n", s.name, s.number, s.chinese, s.math, s.english); */
}
fclose(in);
fflush(in);
in = fopen(FILE2, "r");
if (!in)
{
fclose(out);
printf("can't open file\n");
exit(-1);
}
while (1)
{
s.name[0] = '\0';
fscanf(in, "%s %d %d %d %d", s.name, &s.number, &s.chinese, &s.math, &s.english);
if (s.name[0] == '\0')
break;
++count;
fprintf(out, "%s %d %d %d %d\n", s.name, s.number, s.chinese, s.math, s.english);
/* printf("%s %d %d %d %d\n", s.name, s.number, s.chinese, s.math, s.english); */
}
fclose(in);
fclose(out);
}
void check4makeup()
{
FILE *in, *out;
student s;
out = fopen(FILE4, "w");
in = fopen(FILE3, "r");
if (!in || !out)
{
printf("can't open file(s)\n");
exit(-1);
}
while (1)
{
s.name[0] = '\0';
fscanf(in, "%s %d %d %d %d", s.name, &s.number, &s.chinese, &s.math, &s.english);
if (s.name[0] == '\0')
break;
if (s.chinese < 60 || s.math < 60 || s.english < 60)
fprintf(out, "%s %d %d %d %d\n", s.name, s.number, s.chinese, s.math, s.english);
}
fclose(in);
fclose(out);
}
void selectsort(int type = 0)
{
int i, j, k;
student s;
for (i = 0; i < count - 1; ++i)
{
k = i;
for (j = i + 1; j < count; ++j)
{
if (type == 0)
{
if (ss[k].total < ss[j].total)
k = j;
}
else
{
if (strcmp(ss[k].name, ss[j].name) < 0)
k = j;
}
}
if (k != i)
{
memcpy(&s, &ss[i], sizeof(student));
memcpy(&ss[i], &ss[k], sizeof(student));
memcpy(&ss[k], &s, sizeof(student));
}
}
}
void bubblesort()
{
int i, j;
student s;
for (i = 0; i < count - 1; ++i)
{
for (j = count - 1; j > i; --j)
if (ss[j].total > ss[j-1].total)
{
memcpy(&s, &ss[j-1], sizeof(student));
memcpy(&ss[j-1], &ss[j], sizeof(student));
memcpy(&ss[j], &s, sizeof(student));
}
}
}
void outputrecords()
{
int i;
printf("No:\tName:\t\tTotal:\tChinese:\tMath:\tEnglish:\n");
for (i = 0; i < count; ++i)
{
printf("%d\t%s\t\t%d\t%d\t\t%d\t%d\n",
ss[i].number, ss[i].name, ss[i].total, ss[i].chinese, ss[i].math, ss[i].english);
}
}
void sortrecords()
{
int i = 0;
FILE *fp;
char choice;
fp = fopen(FILE3, "r+");
if (!fp)
{
printf("can't open file\n");
exit(-1);
}
while (1)
{
fscanf(fp, "%s %d %d %d %d", ss[i].name, &ss[i].number,
&ss[i].chinese, &ss[i].math, &ss[i].english);
if (i == count)
break;
ss[i].total = ss[i].chinese + ss[i].math + ss[i].english;
++i;
}
rewind(fp);
puts("Please select the sort method:");
puts("1. Bubble Sort");
puts("2. Selection Sort");
choice = getchar();
if (choice == '1')
bubblesort();
else
selectsort();
rewind(fp);
fclose(fp);
}
int binsearch(const char *name)
{
int low = 0;
int high = count - 1;
while (low <= high)
{
int mid = (low + high) / 2;
if (!strcmp(ss[mid].name, name))
{
return mid;
}
else
{
if (strcmp(ss[mid].name, name) > 0)
high = mid - 1;
else
low = mid + 1;
}
}
return -1;
}
int seqsearch(const char *name)
{
int i;
for (i = 0; i < count; ++i)
{
if (!strcmp(ss[i].name, name))
return i;
}
return -1;
}
void findrecord()
{
char nm[20], choice;
int i;
putchar('\n');
selectsort(1);
while (1)
{
printf("Please input the student name you want to find(!=end):\n");
scanf("%s", nm);
if (nm[0] == '!')
break;
puts("Please select the search method:");
puts("1. binary Search");
puts("2. Sequence Search");
choice = getchar();
getchar();
if (choice == '1')
i = binsearch(nm);
else
i = seqsearch(nm);
if (i != -1)
printf("No: %d Name: %s Total: %d Chinese: %d Math: %d English %d\n",
ss[i].number, ss[i].name, ss[i].total, ss[i].chinese, ss[i].math, ss[i].english);
else
printf("Not Found\n");
}
}
void main()
{
combine2files();
ss = (student *)malloc(sizeof(student) * count);
check4makeup();
sortrecords();
outputrecords();
findrecord();
free(ss);
}
⑦ 數據結構寫學生成績管理系統
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "windows.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 學號 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
⑧ 數據結構(學生成績管理系統)
http://wenku..com/view/dc69e8ef5ef7ba0d4a733bff.html
⑨ 求c語言版數據結構課題 學生成績管理系統的程序
|#include<stdio.h>
#include"malloc.h"
#include"string.h"
struct stu{
char name[20];
char stuno[10];
int yw;
int sx;
int yy;
};
struct link{
stu *astu;
link *next;
};
void printfile(link *head,char *s)
{
FILE *p=fopen(s,"w");
link *temp=head;
fprintf(p,"姓名\t學號\t語文\t數學\t英語\n");
while(temp->next!=NULL)
{
temp=temp->next;
fprintf(p,"%s\t%s\t%d\t%d\t%d\n",temp->astu->name,temp->astu->stuno,temp->astu->yw,temp->astu->sx,temp->astu->yy);
}
fclose(p);
}
link *getlink(char *s)
{
FILE *p=fopen(s,"r");
link *head=(link *)malloc(sizeof(link));
int pf;
head->astu=NULL;
head->next=NULL;
link *tail=head;
stu *temp;
fseek(p,sizeof("姓名\t學號\t語文\t數學\t英語\n"),0);
while(!feof(p))
{
pf=ftell(p);
temp=(stu *)malloc(sizeof(stu));
fscanf(p,"%s\t%s\t%d\t%d\t%d\n",temp->name,temp->stuno,&(temp->yw),&(temp->sx),&(temp->yy));
if(pf==ftell(p))break;
tail->next=(link *)malloc(sizeof(link));
tail=tail->next;
tail->astu=temp;
tail->next=NULL;
}
fclose(p);
return head;
}
int allscore(stu *astu)
{
return astu->sx+astu->yw+astu->yy;
}
bool fail(stu *astu)
{
return astu->sx<60||astu->yw<60||astu->yw<60;
}
link *input(char *s)
{
link *head=(link *)malloc(sizeof(link));
head->astu=NULL;
head->next=NULL;
link *tail=head;
stu *temp;
while(true)
{
temp=(stu *)malloc(sizeof(stu));
printf("請輸入學生姓名或者輸入0結束:");
scanf("%s",temp->name);
if(strcmp(temp->name,"0")==0)break;
printf("請輸入學生學號:");
scanf("%s",temp->stuno);
printf("請輸入學生語文成績:");
scanf("%d",&(temp->yw));
printf("請輸入學生數學成績:");
scanf("%d",&(temp->sx));
printf("請輸入學生英語成績:");
scanf("%d",&(temp->yy));
tail->next=(link *)malloc(sizeof(link));
tail=tail->next;
tail->astu=temp;
tail->next=NULL;
}
printfile(head,s);
printf("已成功保存至文件%中\n",s);
return head;
}
void main()
{
link *p1,*p2,*p3,*p4,*temp1,*temp2,*temp3,*temp4;
stu *temp;
printf("請輸入1.txt中的數據:\n");
input("1.txt");
printf("請輸入2.txt中的數據:\n");
input("2.txt");
char s[20];
p1=getlink("1.txt");
p2=getlink("2.txt");
temp1=p1;
while(temp1->next!=NULL)temp1=temp1->next;
temp1->next=p2->next;
for(temp1=p1->next;temp1!=NULL;temp1=temp1->next)
for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
if(allscore(temp1->astu)<allscore(temp2->astu))
{
temp=temp1->astu;
temp1->astu=temp2->astu;
temp2->astu=temp;
}
printfile(p1,"3.txt");
temp1=p1;
for(temp2=p1->next;temp2!=NULL;temp2=temp2->next)
if(fail(temp2->astu))
{
temp1->next=temp2;
temp1=temp2;
}
temp1->next=NULL;
printfile(p1,"4.txt");
p1=getlink("3.txt");
printf("結果已保存至文件\n");
printf("請輸入要尋找的學生姓名:");
scanf("%s",s);
for(temp1=p1->next;temp1!=NULL;temp1=temp1->next)
if(strcmp(temp1->astu->name,s)==0)
printf("%s\t%s\t%d\t%d\t%d\n",temp1->astu->name,temp1->astu->stuno,temp1->astu->yw,temp1->astu->sx,temp1->astu->yy);
}