C++课程设计 学生管理系统

2024-12-18 10:30:02
推荐回答(5个)
回答1:

#include
基本上和你的一模一样,运行完全正确

#include
#include
#include

struct student_info
{ char number[15]; /*学号*/
char name[20]; /*姓名*/
char gender[8]; /*性别*/
char sushe_no[10]; /*宿舍号*/
char tel[20];
};

struct student_grade
{
char number[15];
char courseno[10]; /*课程号*/
char coursename[20]; /*课程名称*/
int xuefen;
int pingshicj;
int shiyancj;
int juanmiancj;
float zonghecj;
float shidecj;
};

typedef struct student_info stu_info;
typedef struct student_grade stu_grade;

int CourseInfoIndex=0;
int StudentInfoIndex=0;

stu_info *StuInfo=NULL;
stu_grade *StuCour=NULL;

int ReadStuInfo(void) //从原有的学生信息文件中读取信息
{
FILE *fp;

StudentInfoIndex=0;

if((fp=fopen("a.txt","rb"))==NULL)
{
return -1;
}
else
{
while(!feof(fp))
{
if(fread(&StuInfo[StudentInfoIndex],sizeof(stu_info),1,fp)==1)
{
StudentInfoIndex++;
}
}
fclose(fp);

return 0;
}
}

int WriteStuInfo(void) //将学生信息写入到文件中
{
FILE *fp;

if(StudentInfoIndex>=0)
{
if((fp=fopen("a.txt","wb"))==NULL)
{
return -1;
}
else
{
fwrite(StuInfo,sizeof(stu_info)*StudentInfoIndex,1,fp);
fclose(fp);
return 0;
}
}

return 0;
}

void PrintStuInfo(int index)
{
int i=0;

ReadStuInfo();

printf("\nNow print the data of student infomation:\n");
printf("StuNO StuName Gender SuSheHao Telphone\n");
if (index==-1)
{
for(i=0;i<=StudentInfoIndex-1;i++)
{
printf("%s ",StuInfo[i].number);
printf("%s ",StuInfo[i].name);
printf("%s ",StuInfo[i].gender);
printf("%s ",StuInfo[i].sushe_no);
printf("%s\n",StuInfo[i].tel);
}
}
else
{
printf("%s ",StuInfo[index].number);
printf("%s ",StuInfo[index].name);
printf("%s ",StuInfo[index].gender);
printf("%s ",StuInfo[index].sushe_no);
printf("%s\n",StuInfo[index].tel);
}
}

void InStuInfo(void) //添加学生信息
{
int t=0;
char str[20];

ReadStuInfo();

//PrintStuInfo(-1); //测试代码,打印学生信息

printf("Now you will input some new student infomation records,\n end with a * for begin of a record.\n");

while(str[0]!='*')
{
t++;

printf("-------------------------------------\n");
printf("Now Please input the %dth record:\n",t);

printf(" Student no:");
gets(str);
if(str[0]=='*')
{
continue;
} //如果碰到结束标志

strcpy(StuInfo[StudentInfoIndex].number,str);

printf("\n Student name:");
gets(StuInfo[StudentInfoIndex].name);

printf("\n Student gender:");
gets(StuInfo[StudentInfoIndex].gender);

printf("\n sushe_no:");
gets(StuInfo[StudentInfoIndex].sushe_no);

printf("\n tel:");
gets(StuInfo[StudentInfoIndex].tel);

StudentInfoIndex++;

}

WriteStuInfo();

}

int ReadCourseInfo(void) //从原有的学生成绩信息文件中读取信息
{
FILE *fp;

CourseInfoIndex=0;

if((fp=fopen("b.txt","rb"))==NULL)
{
return -1;
}
else
{
while(!feof(fp))
{
if(fread(&StuCour[CourseInfoIndex],sizeof(stu_grade),1,fp)==1)
{
CourseInfoIndex++;
}
}
fclose(fp);

return 0;
}
}

int WriteCourseInfo(void) //将成绩信息写入到文件中
{
FILE *fp;

if(CourseInfoIndex>=0)
{
if((fp=fopen("b.txt","wb"))==NULL)
{
return -1;
}
else
{
fwrite(StuCour,sizeof(stu_grade)*CourseInfoIndex,1,fp);
fclose(fp);
return 0;
}
}

return 0;
}

void PrintCourseInfo(int index)
{
int i=0;

ReadCourseInfo();

printf("\nNow print the data of course infomation:\n");
printf("StuNO CourseNo CourseName XueFen PingShiCJ ShiYanCJ JuanMianCJ ZongHeCJ ShiDeCJ\n");
if (index==-1)
{
for(i=0;i<=CourseInfoIndex-1;i++)
{
printf("%s ",StuCour[i].number);
printf("%s ",StuCour[i].courseno);
printf("%s ",StuCour[i].coursename);
printf("%d ",StuCour[i].xuefen);
printf("%d ",StuCour[i].pingshicj);
printf("%d ",StuCour[i].shiyancj);
printf("%d ",StuCour[i].juanmiancj);
printf("%f ",StuCour[i].zonghecj);
printf("%f\n",StuCour[i].shidecj);
}
}
else
{
printf("%s ",StuCour[index].number);
printf("%s ",StuCour[index].courseno);
printf("%s ",StuCour[index].coursename);
printf("%d ",StuCour[index].xuefen);
printf("%d ",StuCour[index].pingshicj);
printf("%d ",StuCour[index].shiyancj);
printf("%d ",StuCour[index].juanmiancj);
printf("%f ",StuCour[index].zonghecj);
printf("%f\n",StuCour[index].shidecj);
}
}

void InStuCourseInfo(void) //输入新的学生成绩信息
{
int t=0;
char str[20];

ReadCourseInfo(); //先把原先文件中存在的记录读到内存中

// PrintCourseInfo(-1); //测试代码过程

printf("Now you will input some new student course records,\n end with a * for begin of a record.\n");

while(str[0]!='*')
{
t++;
printf("-------------------------------------\n");
printf("Now Please input the %dth record:\n",t);

printf(" Student no:");
gets(str);
if(str[0]=='*')
{
//if(CourseInfoIndex!=0) CourseInfoIndex--;
continue;
} //如果碰到结束标志

strcpy(StuCour[CourseInfoIndex].number,str);

printf("\n Course no:");
gets(StuCour[CourseInfoIndex].courseno);

printf("\n Course name:");
gets(StuCour[CourseInfoIndex].coursename);

printf("\n XueFen:");
gets(str);
StuCour[CourseInfoIndex].xuefen=(int)atof(str);

printf("\n PingShiChengJi:");
gets(str);
StuCour[CourseInfoIndex].pingshicj=(int)atof(str);

printf("\n ShiYanChengJi:");
gets(str);
StuCour[CourseInfoIndex].shiyancj=(int)atof(str);

printf("\n JuanMianChengJi:");
gets(str);
StuCour[CourseInfoIndex].juanmiancj=(int)atof(str);

//下面计算综合成绩和实得成绩

if(StuCour[CourseInfoIndex].shiyancj==-1)
{
StuCour[CourseInfoIndex].zonghecj=StuCour[CourseInfoIndex].pingshicj*0.3+StuCour[CourseInfoIndex].juanmiancj*0.7;
}
else
{
StuCour[CourseInfoIndex].zonghecj=StuCour[CourseInfoIndex].shiyancj*0.15+StuCour[CourseInfoIndex].pingshicj*0.15+StuCour[CourseInfoIndex].juanmiancj*0.7;
}

if(StuCour[CourseInfoIndex].zonghecj>=90)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*1.0;
}
else
{
if(StuCour[CourseInfoIndex].zonghecj>=70)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*0.8;
}
else
{
if(StuCour[CourseInfoIndex].zonghecj>=60)
{
StuCour[CourseInfoIndex].shidecj=StuCour[CourseInfoIndex].xuefen*0.6;
}
else
{
StuCour[CourseInfoIndex].shidecj=0.0;
}
}
}

CourseInfoIndex++;
}

WriteCourseInfo();// 保存到文件中
}

/* 将src指向的一条记录复制给dest指向的记录 */
void CopyStuInfo(stu_info *src,stu_info *dest)
{
int j;
strcpy(dest->number,src->number);
strcpy(dest->name,src->name);
strcpy(dest->gender,src->gender);
strcpy(dest->sushe_no,src->sushe_no);
strcpy(dest->tel,src->tel);
}

void Del(void)
{
char strdel[15];
int p=0;
int flag=0;
int t=StudentInfoIndex;

printf("Delete a student infomation record:\n");

ReadCourseInfo();
ReadStuInfo();
PrintStuInfo(-1); //打印学生信息

printf("Please input the student number which you will delete:");
gets(strdel);

while(p<=t && flag==0)
{
if(strcmp(strdel,StuInfo[p].number)==0)
{
flag=1; //找到该学号的记录
CopyStuInfo(&StuInfo[t-1],&StuInfo[p]); //将最后一个记录覆盖当前记录,如果找到的是最后一个记录,则直接丢失
t--;
StudentInfoIndex--;
}
else
{
p++;
}
}

if(flag==1) //如果删除了a文件的记录,则应相应的删除b文件的记录
{
p=0;
t=CourseInfoIndex;
while(p<=t && CourseInfoIndex>=0 )
{
if(strcmp(strdel,StuCour[p].number)==0)
{
CopyStuInfo(&StuCour[CourseInfoIndex-1],&StuCour[p]);
CourseInfoIndex--;
t--;
}
else
{
p++;
}
}
}

WriteStuInfo();
WriteCourseInfo();

PrintStuInfo(-1);
PrintCourseInfo(-1);

}

/* 将src指向的一条记录复制给dest指向的记录 */
void CopyCourseInfo(stu_grade *src,stu_grade *dest)
{
int j;
strcpy(dest->number,src->number);
strcpy(dest->courseno,src->courseno);
strcpy(dest->coursename,src->coursename);
dest->xuefen=src->xuefen;
dest->pingshicj=src->pingshicj;
dest->juanmiancj=src->juanmiancj;
dest->zonghecj=src->zonghecj;
dest->shidecj=src->shidecj;
}

void SortInfo(void)
{
char str[5];
int i,j;
stu_grade tmps;

printf("Pease select a sorting way:\n");
printf("1.with zonghecj in inc order\n");

此部分被隐藏。。。给分数后再发给你
}

回答2:

我们也是这个啊,命苦哦~~~
如果可以也发给我一份吧!!
就当是江湖救急啊~~
谢谢了!!!
molinyuaner@126.com

回答3:

同是天涯沦落人

回答4:

有缘啊,我也要做这个,做好了发给我好么?我的邮箱是blueskyflycoco@163.com

回答5:

我会帮你看看的