学生成绩管理系统带保存
⑴ c语言学生成绩管理系统,为什么我的数据保存之后不能读取呢
把你的后两个函数用我的替换一下:
你读取不出来的原因,你没有在保存的文件里面写入一共有多少个信息,你在读取函数那里的读取的studentacount的值是0,所以没有读。另外,既然你读取是rb,保存也应该对应的wb啊。
void
StoreFile(struct
STUDENT
wstudent[])
{
FILE
*fp;
fp=fopen("d:\\student.txt","wb");
if(fp
==
NULL)
{
printf("没有此文件!");
}
fwrite(&studentacount,sizeof(int),1,fp);
fwrite(wstudent,sizeof(struct
STUDENT),studentacount,fp);
fclose(fp);
printf("保存成功!\n");
};
void
OpenFile(struct
STUDENT
wstudent[])
{
FILE
*fp;
fp=fopen("d:\\student.txt","rb");
if(fp
==
NULL)
{
printf("没有此文件!");
}
fread(&studentacount,sizeof(int),1,fp);
fread(wstudent,sizeof(struct
STUDENT),studentacount,fp);
fclose(fp);
printf("打开成功!\n");
};
⑵ 学生成绩管理系统的源代码 但是其中缺少了 排序,插入,保存文件和读文件的函数 求大神帮忙补充!!!!
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定义临时指针*/
temp=head->next; /*将原表的头指针所指的下一个结点作头指针*/
head->next=NULL; /*第一个结点为新表的头结点*/
while(temp!=NULL) /*当原表不为空时,进行排序*/
{
t=temp; /*取原表的头结点*/
temp=temp->next; /*原表头结点指针后移*/
p1=head; /*设定移动指针p1,从头指针开始*/
p2=head; /*设定移动指针p2做为p1的前驱,初值为头指针*/
while(t->average<p1->average&&p1!=NULL) /*作成绩平均分比较*/
{
p2=p1; /*待排序点值小,则新表指针后移*/
p1=p1->next;
}
if(p1==p2) /*p1==p2,说明待排序点值大,应排在首位*/
{
t->next=p1; /*待排序点的后继为p*/
head=t; /*新头结点为待排序点*/
}
else /*待排序点应插入在中间某个位置p2和p1之间,如p为空则是尾部*/
{
t->next=p1; /*t的后继是p1*/
p2->next=t; /*p2的后继是t*/
}
}
p1=head; /*已排好序的头指针赋给p1,准备填写名次*/
while(p1!=NULL) /*当p1不为空时,进行下列操作*/
{
i++; /*结点序号*/
p1->order=i; /*将结点序号赋值给名次*/
p1=p1->next; /*指针后移*/
}
printf("排序成功 Sorting is sucessful.\n"); /*排序成功*/
return (head);
}
/*插入记录函数*/
STUDENT *insert(STUDENT *head,STUDENT *mynew)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一个结点*/
p0=mynew; /*p0指向要插入的结点*/
printf("\nPlease enter a mynew record.\n"); /*提示输入记录信息*/
printf("输入学号Enter the num:");
scanf("%s",mynew->num);
printf("输入名字Enter the name:");
scanf("%s",mynew->name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新记录的总分,初值为0*/
for(i=0;i<3;i++)
{
do{
printf("成绩score%d:",i+1);
scanf("%d",&mynew->score[i]);
if(mynew->score[i]>100||mynew->score[i]<0)
printf("数据错误Data error,please enter again.\n");
}while(mynew->score[i]>100||mynew->score[i]<0);
sum1=sum1+mynew->score[i]; /*累加各门成绩*/
}
mynew->sum=sum1; /*将总分存入新记录中*/
mynew->average=(float)sum1/3;
mynew->order=0;
if(head==NULL) /*原来的链表是空表*/
{head=p0;p0->next=NULL;} /*使p0指向的结点作为头结点*/
else
{while((p0->average<p1->average)&&(p1->next!=NULL))
{p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1->next; /*p1后移一个结点*/
}
if(p0->average>=p1->average)
{if(head==p1)head=p0; /*插到原来第一个结点之前*/
else p2->next=p0; /*插到p2指向的结点之后*/
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;} /*插到最后的结点之后*/
}
n=n+1; /*结点数加1*/
head=sort(head); /*调用排序的函数,将学生成绩重新排序*/
printf("\n学生Student %s 已被更新have been inserted.\n",mynew->name);
printf("不要忘了保存Don't forget to save the mynewfile.\n");
return(head);
}
/*保存数据到文件函数*/
void save(STUDENT *head)
{FILE *fp; /*定义指向文件的指针*/
STUDENT *p; /* 定义移动指针*/
char outfile[10];
printf("输出文件例如:c:\\score Enter outfile name,forexample c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL) /*为输出打开一个二进制文件,为只写方式*/
{
printf("打不开文件Cannot open the file\n");
return; /*若打不开则返回菜单*/
}
printf("\n保存中...Saving the file......\n");
p=head; /*移动指针从头指针开始*/
while(p!=NULL) /*如p不为空*/
{
fwrite(p,LEN,1,fp); /*写入一条记录*/
p=p->next; /*指针后移*/
}
fclose(fp); /*关闭文件*/
printf("保存成功....Save the filesuccessfully!\n");
}
/* 从文件读数据函数*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定义记录指针变量*/
FILE *fp; /* 定义指向文件的指针*/
char infile[10];
printf("倒入文件例如:c:\\score Enter infile name,for examplec:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL) /*打开一个二进制文件,为只读方式*/
{
printf("打不开文件Can not open the file.\n");
return(head);
}
printf("\n寻找文件...Loading the file!\n");
p1=(STUDENT *)malloc(LEN); /*开辟一个新单元*/
if(!p1)
{
printf("内存溢出!Out of memory!\n");
return(head);
}
head=p1; /*申请到空间,将其作为头指针*/
while(!feof(fp)) /*循环读数据直到文件尾结束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果没读到数据,跳出循环*/
p1->next=(STUDENT *)malloc(LEN); /*为下一个结点开辟空间*/
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1->next; /*指针后移,新读入数据链到当前表尾*/
}
p2->next=NULL; /*最后一个结点的后继指针为空*/
fclose(fp);
printf("\n你成功的从文件中读取了数据!\nYou have success to read data fromthe file!\n");
return (head);
}
⑶ 我写了一个学生成绩管理系统,C语言,学生的信息可以顺利保存到文件,但登录注册的用户信息不能保存为文件
tbhzx
com可以免费下载到
⑷ 菜鸟做一个学生成绩管理系统,已经把学生信息保存在文本中,如何根据输入学号,查找某一学生的信息。谢谢
我给你改了两个错误现在可以运行了,不知道还有没有其他逻辑错误,自己进一步修改吧。
第一个,你在排序那个程序里一个for循环不加,这个错误有些幼稚,不像能写出这种程序的人该犯的。
第二个错误,main主函数里if判断语句判等的时候用了赋值号,应该改成==
建议:你要学会调试,这种编译不过调试一下子就可以找到是排序函数的哪句话出错了。调试用F9标记,F5调试F10安步走,F11进入内层函数
#include<iostream>
#include<string>
using namespace std;
struct student //定义一个学生结构体
{
string name;
string sex;
int num;
int math;
int english;
int chinese;
int sum; //个人总分
float pingjun; //个人平均分
};
student stu[3];
int n; //全局变量
void input(student *p, int n) //输入模块
{
int i;
double SUM,PINGJUN;
p=&stu[0];
for(i=0;i<n; i++, p++)
{
cout<<"请依次输入第"<<i+1<<"个学生的姓名,性别,学号,数学分数,英语分数语文分数"<<endl;
cin>>(*p).name;
cin>>(*p).sex;
cin>>(*p).num;
cin>>(*p).math;
cin>>(*p).english;
cin>>(*p).chinese;
(*p).sum=(*p).math+(*p).english+(*p).chinese; //求个人总分
(*p).pingjun=((*p).math+(*p).english+(*p).chinese)/3; //个人平均分
SUM=SUM+(*p).sum; //班级总分
PINGJUN=SUM/3; //班级平均分
} cout<<"班级总分"<<SUM<<endl;
cout<<"班级平均分"<<PINGJUN<<endl;
}
void output(student *p, int n) //输出学生信息
{
for(int i=0;i<n;i++,p++)
{
cout<<"第"<<i+1<<"个学生的信息"<<"\n";
cout<<"姓名"<<p[i].name<<"\n";
cout<<"性别"<<p[i].sex<<"\n";
cout<<"数学分数"<<p[i].math<<"\n";
cout<<"英语分数"<<p[i].english<<"\n";
cout<<"语文分数"<<p[i].chinese<<"\n";
cout<<"个人总分"<<p[i].sum<<"\n";
cout<<"个人平均分"<<p[i].pingjun<<"\n";
}
}
void paixu(student *p, int n) //排序模块
{
int i, j, t;
string g;
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i; j++)
{
if(p[j].sum<p[j+1].sum)
{
g=p[j].name; p[j].name=p[j+1].name; p[j+1].name=g;
g=p[j].sex; p[j].sex=p[j+1].sex; p[j+1].sex=g;
t=p[j].math; p[j].math=p[j+1].math; p[j+1].math=t;
t=p[j].english;p[j].english=p[j+1].english;p[j+1].english=t;
t=p[j].chinese; p[j].chinese=p[j+1].chinese; p[j+1].chinese=t;
t=p[j].sum; p[j].sum=p[j+1].sum; p[j+1].sum=t;
}
}
}
}
void chaozhao(student *p,int n) //查找模块
{
int xh;
while(n==0)
{
cout<<"没有记录,请先输入学生信息"<<endl;
break;
}
if(n!=0)
{
cout<<"输入您要查找的学生学号"<<endl;
cin>>xh; //输入学号
}
if(xh==p[n].num)
{
cout<<"姓名"<<p[n].name<<"\t";
cout<<"性别"<<p[n].sex<<"\t";
cout<<"学号"<<p[n].num<<"\t";
cout<<"数学分数"<<p[n].math<<"\t";
cout<<"英语分数"<<p[n].english<<"\t";
cout<<"语文分数"<<p[n].chinese<<"\t";
cout<<"总分"<<p[n].sum<<"\t";
}
else
cout<<"没有找到您要查找的学生"<<endl;
}
void main() //主函数
{
student *q=&stu[0];
paixu(q,3);
int i;
cout<<"*……………………管理系统……………………*"<<endl;
cout<<"请选择你需要的操作:"<<endl;
cout<<"(1)输入学生信息"<<endl;
cout<<"(2)按学号查找"<<endl;
cout<<"(3)显示所有学生信息"<<endl;
cin>>i;
if(i==1)
input(q,3);
if(i==2)
chaozhao(q,3);
if(i==3)
output(q,3);
}
⑸ c++编写学生成绩管理系统能保存录入的数据
这个问题不是已经发过了么?!
#pragmaonce
#include"Type.h"
#include"Student.h"
classStudentMgr
{
public:
StudentMgr(){}
~StudentMgr()
{
stuVecIteriter=_simpleMemory.begin();
for(;iter!=_simpleMemory.end();++iter)
{
free(*iter);
}
}
staticStudentMgr*GetInstance()
{
if(_studentMgr!=NULL)
{
return_studentMgr;
}
_studentMgr=newStudentMgr();
assert(_studentMgr!=NULL);
return_studentMgr;
}
voidInputStudentInfo();
Student*CreateStucent(stringnum,intmath,inten,intcn,intchem);
boolAddStucent(constStudent*pStudent);
voidInitVector();
boolSort();
intGetAverage(enume_SubjectNamesubject);
voidPrintTopStucent();
voidPrintTopStucent(e_SubjectNamesubject);
voidPrientAverage();
private:
vector<Student*>_simpleMemory;
map<string,Student*>_StuMap;
vector<stuMapPair>_TopVec;
vector<stuMapPair>_MathVec;
vector<stuMapPair>_EnVec;
vector<stuMapPair>_CnVec;
vector<stuMapPair>_ChemVec;
vector<stuMapPair>_subVec[SUBNAME_LEN];
staticStudentMgr*_studentMgr;
};
#include"stdafx.h"
#include"Student.h"
#include"StudentMgr.h"
bool(*g_CmpFun[SUBNAME_LEN])(stuMapPaira,stuMapPairb)={
MathCmp,
EnCmp,
ChCmp,
ChemCmp,
};
Student*StudentMgr::CreateStucent(stringnum,intmath,inten,intcn,intchem)
{
//plz,carethememory!
Student*_student=newStudent(num,math,en,cn,chem);
if(_student==NULL)
{
cout<<"memoryerror!failtocreatenewstucent!"<<endl;
}
else
{
_simpleMemory.push_back(_student);
AddStucent(_student);
}
return_student;
}
voidStudentMgr::PrintTopStucent()
{
cout<<"Toponeinformation:"<<endl;
vector<stuMapPair>::iteratoriter=_TopVec.begin();
if(iter!=_TopVec.end())
{
Student*pStudent=iter->second;
if(pStudent!=NULL)
{
cout<<" num:"<<pStudent->GetNum();
cout<<" Math:"<<pStudent->GetMath();
cout<<" EN:"<<pStudent->GetEN();
cout<<" CN:"<<pStudent->GetCN();
cout<<" Chem:"<<pStudent->GetChem();
cout<<" Total:"<<pStudent->GetTotalScore()<<endl;
}
}
else
{
cout<<"Thereisnonstudentinformation!"<<endl;
}
}
voidStudentMgr::PrintTopStucent(e_SubjectNamesubject)
{
cout<<"Toponeinformationof"<<Subject_name[subject]<<endl;
vector<stuMapPair>::iteratoriter=_subVec[subject].begin();
if(iter!=_subVec[subject].end())
{
Student*pStudent=iter->second;
if(pStudent!=NULL)
{
cout<<" num:"<<pStudent->GetNum();
cout<<" Math:"<<pStudent->GetMath();
cout<<" EN:"<<pStudent->GetEN();
cout<<" CN:"<<pStudent->GetCN();
cout<<" Chem:"<<pStudent->GetChem();
cout<<" Total:"<<pStudent->GetTotalScore()<<endl;
}
}
else
{
cout<<"Thereisnonstudentinformation!"<<endl;
}
}
intStudentMgr::GetAverage(enume_SubjectNamesubject)
{
intsubTotal=0;
stuMapIteriter=_StuMap.begin();
for(;iter!=_StuMap.end();++iter)
{
subTotal+=iter->second->GetScore(subject);
}
returnsubTotal/_StuMap.size();
}
voidStudentMgr::PrientAverage()
{
intaverate=0;
for(inti=0;i<SUBNAME_LEN;++i)
{
averate=GetAverage((enume_SubjectName)i);
cout<<"the"<<Subject_name[i]<<"'saverateis:"<<averate<<endl;
}
}
voidStudentMgr::InputStudentInfo()
{
cout<<"Plz,!e.num,math,en,ch,chem"<<endl;
charc='0';
while(true)
{
structs_SimpDatadata={0};
if(scanf_s("%s%d%d%d%d",data.num,MAX_NUM_LEN,&data.math,&data.en,&data.cn,&data.chem)!=EOF)
{
CreateStucent(data.num,data.math,data.en,data.cn,data.chem);
}
cout<<"'c'continue"<<endl;
cin>>c;
if(c!='c')
{
break;
}
}
}
boolStudentMgr::Sort()
{
std::sort(_TopVec.begin(),_TopVec.end(),TopCmp);
for(inti=0;i<SUBNAME_LEN;++i)
{
std::sort(_subVec[i].begin(),_subVec[i].end(),g_CmpFun[i]);
}
returntrue;
}
voidStudentMgr::InitVector()
{
inti=0;
_TopVec.clear();
for(i=0;i<SUBNAME_LEN;++i)
{
_subVec[i].clear();
}
stuMapIteriter=_StuMap.begin();
for(;iter!=_StuMap.end();++iter)
{
_TopVec.push_back(*iter);
for(i=0;i<SUBNAME_LEN;++i)
{
_subVec[i].push_back(*iter);
}
}
}
boolStudentMgr::AddStucent(constStudent*pStudent)
{
stuMapPair_pair=stuMapPair(pStudent->GetNum(),const_cast<Student*>(pStudent));
_StuMap.insert(_pair);
returntrue;
}
源码地址:http://www.iu8s.com/forum.php?mod=viewthread&tid=18&extra=page%3D1
如果需要源码可以留下邮箱,我直接发你邮箱里面。
⑹ c语言学生管理系统用文件保存
/**********************************************
*File Name:StuHead.h *
*Created:07/11/28 *
*Author:Wen He *
*Description:此文件的指责是程序的头文件描述 *
**********************************************/
/*引入头文件*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100 /*定义学生人数*/
#define MAXSUB 4 /*定义课程数目*/
int length; /*定义学生的实际人数*/
/*定义学生结构体*/
typedef struct tagStudent_t
{
char no[11]; /*学号*/
char name[20]; /*姓名*/
int score[MAXSUB];/*各科成绩*/
int sum; /*总分*/
float average; /*平均分*/
}Student;
/*函数声明*/
char menu_select();
void input(Student stuArray[]);
void output(Student stuArr[]);
void search(Student stuAray[]);
int searchByNo(Student stuArr[]);
void searchByName(Student stuArr[]);
void update(Student stuArray[]);
void delete(Student stuArray[]);
----------------------以上是头文件
/**********************************************
*File Name:stuMain.c *
*Created:07/11/28 *
*Author:Wen He *
*Description:此程序的指责为程序的入口,主函数 *
***********************************************/
#include "stuHead.h"
void main()
{
Student stus[MAXSIZE];
while(1)
{
switch(menu_select())
{
case '1':
input(stus);
break;
case '2':
update(stus);
printf("按任意键继续…");
fflush(stdin);
getchar();
break;
case '3':
search(stus);
printf("按任意键继续…");
fflush(stdin);
getchar();
break;
case '4':
delete(stus);
printf("按任意键继续…");
fflush(stdin);
getchar();
break;
case '5':
output(stus);
printf("按任意键继续…");
fflush(stdin);
getchar();
break;
case '0':
printf("\n 谢谢使用!\n");
exit(0);
}
}
}
以上是MAIN
下面是主程序
/**********************************************
*File Name:stuFun.c *
*Created:07/11/28 *
*Author:Wen He *
*Description:此程序的指责为各函数的定义 *
***********************************************/
#include "stuHead.h"
/**********************************************
*Function Name:menu_select
*Description:菜单选择
*Date:07/11/28
*parameter:无
*Author:Wen He
***********************************************/
char menu_select()
{
char MenuItem;
printf("\n ");
printf(" | *********学生成绩管理系统********* | \n");
printf(" | ---------------------------------- | \n");
printf(" | 主菜单项 | \n");
printf(" | ---------------------------------- | \n");
printf(" | 1 --- 录入学生信息 | \n");
printf(" | 2 --- 修改学生信息 | \n");
printf(" | 3 --- 查询学生信息 | \n");
printf(" | 4 --- 删除学生成绩 | \n");
printf(" | 5 --- 显示学生信息 | \n");
printf(" | 6 --- 统计学生成绩 | \n");
printf(" | 0 --- 退出系统 | \n");
do
{
printf("\n 请输入选项(0-5):");
fflush(stdin);
scanf("%c",&MenuItem);
getchar();
}while(MenuItem<'0'||MenuItem>'5');
return MenuItem;
}
/**********************************************
*Function Name:input
*Description:输入学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void input(Student stuArray[])
{
int i,j,k;
char cContinue;
int flag=1;
fflush(stdin);
for(i=length;i<MAXSIZE-1;i++)
{
printf("请输入第%d名学生的学号:",i+1);
scanf("%s",&stuArray[i].no);
if(i>0)
{
for(k=0;k<length;k++)
if(strcmp(stuArray[k].no,stuArray[i].no)==0)
break;
if(k<length)
{
i--;
printf("学号不能重复,请重新输入!");
continue;
}
}
printf("请输入姓名:");
scanf("%s",&stuArray[i].name);
for(j=0;j<MAXSUB;j++)
{
printf("请输入第%d门成绩:",j+1);
scanf("%d",&stuArray[i].score[j]);
if(stuArray[i].score[j]>100||stuArray[i].score[j]<0)
{
printf("错误数据,请重新输入!");
j--;
}
}
stuArray[i].sum=0;
for(j=0;j<MAXSUB;j++)
stuArray[i].sum+=stuArray[i].score[j];
stuArray[i].average=(float)stuArray[i].sum/MAXSUB;
length++;
do
{
flag=1;
fflush(stdin);
printf("需要继续录入吗?(Y/N)");
scanf("%c",&cContinue);
getchar();
switch(cContinue)
{
case 'Y':
case 'y':
flag=0;
break;
case 'N':
case 'n':
return;
}
}while(flag);
}
}
/**********************************************
*Function Name:output
*Description:输出学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void output(Student stuArray[])
{
int i,j;
printf("| 学号 | 姓名 | 成绩1 | 成绩2 | 成绩3 | 成绩4 | 总分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
for(i=0;i<length;i++)
{
printf("|%-6s|%-14s|", stuArray[i].no,stuArray[i].name);
for(j=0;j<MAXSUB;j++)
printf("%7d|", stuArray[i].score[j]);
printf("%7d%7.2f\n",stuArray[i].sum, stuArray[i].average); /*输出数组中当前学生的信息*/
}
}
/**********************************************
*Function Name:search
*Description:查询学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void search(Student stuArray[])
{
char menuItem;
printf("\n\n\n"); /*输出三个空行*/
/*---------输出菜单界面开始-----------*/
printf(" | --------------------------------------------|\n");
printf(" | 查询子菜单项 |\n");
printf(" | --------------------------------------------|\n");
printf(" | 1---学号查询 |\n");
printf(" | 2---姓名查询 |\n");
printf(" | 0---返回主菜单 |\n");
printf(" | --------------------------------------------|\n");
/*----------菜单界面输出结束-----------*/
do
{
printf("\n 请输入菜单项数字(0~2):");
fflush(stdin);
scanf("%c",&menuItem);
getchar();
}while(menuItem<'0'||menuItem>'2');
switch(menuItem)
{
case '1':
searchByNo(stuArray);
break;
case '2':
searchByName(stuArray);
break;
}
return;
}
/**********************************************
*Function Name:searchByNo
*Description:按学号查询学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
int searchByNo(Student stuArray[])
{
char no[20];
int i;
printf("\n请输入学生的学号:");
scanf("%s",no);
for(i=0;i<length;i++)
if(strcmp(stuArray[i].no,no)==0)
break;
if(i==length)
printf("您输入的学号不存在!\n");
else
{
printf("| 学号 | 姓名 | 成绩1 | 成绩2 | 成绩3 | 成绩4 | 总分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stuArray[i].no,stuArray[i].name,
stuArray[i].score[0], stuArray[i].score[1], stuArray[i].score[2], stuArray[i].score[3],
stuArray[i].sum, stuArray[i].average); /*输出数组中当前学生的信息*/
}
return i;
}
/**********************************************
*Function Name:searchByName
*Description:按姓名查询学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void searchByName(Student stuArray[])
{
Student stu[10];
char searchName[20];
int i,j,k;
printf("\n请输入要查询学生的姓名:");
scanf("%s",searchName);
for(i=0,j=0;i<length;i++)
if(strcmp(stuArray[i].name,searchName)==0)
{
strcpy(stu[j].no,stuArray[i].no);
strcpy(stu[j].name,searchName);
for(k=0;k<4;k++)
stu[j].score[k]=stuArray[i].score[k];
stu[j].sum=stuArray[i].sum;
stu[j].average=stuArray[i].average;
j++;
}
if(j==0)
printf("您输入的姓名不存在!\n");
else
{
printf("| 学号 | 姓名 | 成绩1 | 成绩2 | 成绩3 | 成绩4 | 总分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
for(i=0;i<j;i++)
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stu[i].no,stu[i].name,
stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].score[3],
stu[i].sum, stu[i].average); /*输出数组中当前学生的信息*/
}
}
/**********************************************
*Function Name:update
*Description:修改学生信息
*parameter:stuArray[MAXSIZE]
*Date:07/11/28
*Author:Wen He
***********************************************/
void update(Student stuArray[])
{
char answer;
int i,j;
i=searchByNo(stuArray);
if(i<length)
{
do
{
printf("您要修改的是以上记录吗?(Y/N)");
fflush(stdin);
scanf("%c",&answer);
getchar();
}while(answer!='Y'&&answer!='N'&&answer!='y'&&answer!='n');
if(answer=='Y'||answer=='y')
{
printf("请输入姓名:");
scanf("%s",stuArray[i].name);
stuArray[i].sum=0;
for(j=0;j<MAXSUB;j++)
{
printf("请输入第%d门课程的成绩:",j+1);
scanf("%d",&stuArray[i].score[j]);
stuArray[i].sum+=stuArray[i].score[j];
}
stuArray[i].average=(float)stuArray[i].sum/MAXSUB;
printf("您修改后的信息如下:\n");
printf("| 学号 | 姓名 | 成绩1 | 成绩2 | 成绩3 | 成绩4 | 总分 | 平均分 |\n");
printf("|------|--------------|-------|-------|-------|-------|------|--------|\n");
printf("|%-6s|%-14s|%7d|%7d|%7d|%7d|%7d|%7.2f|\n", stuArray[i].no,stuArray[i].name,
stuArray[i].score[0], stuArray[i].score[1], stuArray[i].score[2], stuArray[i].score[3],
stuArray[i].sum, stuArray[i].average); /*输出数组中当前学生的信息*/
}
}
}
/**********************************************
*Function Name:delete
*Description:删除学生信息
*Date:07/11/28
*parameter:stuArray[MAXSIZE]
*Author:Wen He
***********************************************/
void delete(Student stuArray[])
{
char answer;
int i,j;
i=searchByNo(stuArray);
if(i<length)
{
do
{
printf("您要删除的是以上记录吗?(Y/N)");
fflush(stdin);
scanf("%c",&answer);
getchar();
}while(answer!='Y'&&answer!='N'&&answer!='y'&&answer!='n');
if(answer=='Y'||answer=='y')
{
for(j=i;j<=length-1;j++)
stuArray[j]=stuArray[j+1];
printf("删除成功!");
length--;
}
}
}
⑺ 如何用c语言制作一个学生信息管理系统,要求以文件形式保存
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//链表结点结构体声明
typedef struct subjects
{
char name[20];
float score;
}sub;
typedef struct student
{
int num;
char name[20];
sub subject[3];
struct student* next;
}stu,*pstu;
#define SIZE sizeof(stu)
//函数申明
pstu LoadInfo();
void PrintMenu();
pstu AddStu(pstu );
pstu DeleStu(pstu );
pstu RwrStu(pstu );
void FindStu(pstu , char );
void Count(pstu ,char * ,float ,float );
void Rank(pstu ,char * );
void SaveQuit(pstu );
//创建菜单,进入选择循环
while(1)
{
PrintMenu();
printf("请输入您的选择编号:");
scanf("%d",&n);
getchar();
switch(n)
{
case 1:
{
system("cls");
j=0;
while(4!=j)
{
printf("欢迎进入信息管理版块! ");
printf("