VC++学生管理系统代码谁知道?
人气:
【字体:大 中 小】
发布时间:2007-10-18 15:02:49
>>>>>>>>提问
VC++項目
休 闲 居 编 辑
>>>>>>>>休闲养生网回答:
printf("请输入您需要的功能选项:");
scanf("%d",&select);
int i;
char c;
char id[20],password[20];
admin();
printf("\n\t\t请输入用户名:");
fflush(stdin);
gets(id);
printf("\t\t 请输入密码:");
fflush(stdin);
while((c=getch())!='\r') //密码回显为'*'号
{
password[i++]=c;
putchar('*');
}password[i]='\0';
if((strcmp(id,"yanjie")==0) && (strcmp(password,"123456")==0))
{
printf("\n\t\t你已成功登录!\n");
do
{
system("cls");
switch(select)
{
case 1:
displayData();
break;
case 2:
addData();
break;
case 3:
updateData();
break;
case 4:
deleteData();
break;
case 5:
selectData();
break;
case 0:
exit(0);
default:
printf("\n\t\t您的输入有误!\n\n");
printf("\t\t按任意键继续...\n");
getch();
fflush(stdin);
mainFrame();
}
}while(select <0 ||select >7);
}
else
printf("\n帐号或密码错误!");
}
void print_h()
{
printf("\n\t 学号\t姓 名\t语 文\t数 学\t英 语\t总 分\t平均分\n");
}
void addData()
{
system("cls");
char flag;
do
{
fflush(stdin);
printf("\n\n\t\t请输入学员的编号:");
scanf("%d",&stu[count].stuNo);
printf("\t\t请输入学员的姓名:");
fflush(stdin);
gets(stu[count].stuName);
printf("\t\t请输入语文成绩:");
fflush(stdin);
scanf("%f",&stu[count].ChineseScore);
printf("\t\t请输入数学成绩:");
scanf("%f",&stu[count].MathsScore);
printf("\t\t请输入英语成绩:");
scanf("%f",&stu[count].EnglishScore);
stu[count].totalScore=stu[count].ChineseScore+stu[count].MathsScore+stu[count].EnglishScore;
stu[count].avgScore = (float(stu[count].totalScore)/3);
printf("\t\t是否继续输入?(Y/N):");
fflush(stdin);
flag = getchar();
writeFileA(count);
count ++;
printf("\n");
}while(flag == 'y' || flag == 'Y');
mainFrame();
}
void writeFileA(int i)
{
FILE *fp;
if((fp = fopen("student.txt","a+"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
fprintf(fp,"%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].ChineseScore,stu[i].MathsScore,stu[i].EnglishScore,stu[i].totalScore,stu[i].avgScore);
fclose(fp);
}
void displayData()
{
FILE * fp;
if((fp=fopen("student.txt","r+"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
count = 0;
while(!feof(fp))
{
fscanf(fp,"%d%s%f%f%f%f%f",&stu[count].stuNo,stu[count].stuName,&stu[count].ChineseScore,&stu[count].MathsScore,&stu[count].EnglishScore,&stu[count].totalScore,&stu[count].avgScore);
stu[count].totalScore=stu[count].ChineseScore+stu[count].MathsScore+stu[count].EnglishScore;
stu[count].avgScore = (float(stu[count].totalScore)/3);
count++;
}
fclose(fp);
count--;
system("cls");
print_h();
for(int i=0;i<count;i++)
{
printf("\t %d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].ChineseScore,stu[i].MathsScore,stu[i].EnglishScore,stu[i].totalScore,stu[i].avgScore);
}
printf("\n\n\t\t按任意键继续...\n");
getch();
mainFrame();
}
void updateData()
{
int id;
system("cls");
printf("\n\n\t\t请输入要修改的学员学号:");
fflush(stdin);
scanf("%d",&id);
FILE * fp;
if((fp=fopen("student.txt","r+"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
count = 0;
while(!feof(fp))
{
fscanf(fp,"%d%s%f%f%f%f%f",&stu[count].stuNo,stu[count].stuName,&stu[count].ChineseScore,&stu[count].MathsScore,&stu[count].EnglishScore,&stu[count].totalScore,&stu[count].avgScore);
stu[count].totalScore=stu[count].ChineseScore+stu[count].MathsScore+stu[count].EnglishScore;
stu[count].avgScore = (float(stu[count].totalScore)/3);
count++;
}
fclose(fp);
count--;
for(int i=0;i<count;i++)
{
if(stu[i].stuNo == id)
{
break;
}
}
if(i != count)
{
update(i);
}
else
{
printf("\n\n\t\t没有找到你要修改的原始记录!\n");
}
printf("\n\t\t按任意键继续...\n");
getch();
system("cls");
mainFrame();
}
void update(int id)
{
fflush(stdin);
printf("\n\n\t\t请输入学员的姓名:");
fflush(stdin);
gets(stu[id].stuName);
printf("\t\t请输入语文成绩:");
fflush(stdin);
scanf("%f",&stu[id].ChineseScore);
printf("\t\t请输入数学成绩:");
scanf("%f",&stu[id].MathsScore);
printf("\t\t请输入英语成绩:");
scanf("%f",&stu[id].EnglishScore);
stu[count].totalScore=stu[count].ChineseScore+stu[count].MathsScore+stu[count].EnglishScore;
stu[count].avgScore = (float(stu[count].totalScore)/3);
writeFileW();
}
void writeFileW()
{
FILE *fp;
if((fp=fopen("student.txt","w"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
for(int i=0;i<count;i++)
{
fprintf(fp,"%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].ChineseScore,stu[i].MathsScore,stu[i].EnglishScore,stu[i].totalScore,stu[i].avgScore);
}
fclose(fp);
}
void deleteData()
{
int id;
system("cls");
printf("\n\n\t\t请输入要删除的学员学号:");
scanf("%d",&id);
FILE * fp;
if((fp=fopen("student.txt","r+"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
count = 0;
while(!feof(fp))
{
fscanf(fp,"%d%s%f%f%f%f%f",&stu[count].stuNo,stu[count].stuName,&stu[count].ChineseScore,&stu[count].MathsScore,&stu[count].EnglishScore,&stu[count].totalScore,&stu[count].avgScore);
count++;
}
fclose(fp);
count--;
for(int i=0;i<count;i++)
{
if(stu[i].stuNo == id)
{
break;
}
}
if(i != count)
{
delData(i);
}
else
{
printf("\n\n\t\t没有找到你要删除的原始记录!\n");
}
printf("\n\t\t按任意键继续...\n");
getch();
system("cls");
mainFrame();
}
void delData(int id)
{
if(id == count-1)
{
count--;
writeFileW();
}
else
{
for(int i = id;i<count;i++)
{
stu[i] = stu[i+1];
}
count--;
writeFileW();
}
}
void selectData()
{
int id;
system("cls");
printf("\n\n\t\t请输入要查询的学员学号:");
scanf("%d",&id);
FILE * fp;
if((fp=fopen("student.txt","r+"))==NULL)
{
printf("文件打开失败!\n");
exit(0);
}
count = 0;
while(!feof(fp))
{
fscanf(fp,"%d%s%f%f%f%f%f",&stu[count].stuNo,stu[count].stuName,&stu[count].ChineseScore,&stu[count].MathsScore,&stu[count].EnglishScore,&stu[count].totalScore,&stu[count].avgScore);
count++;
}
fclose(fp);
count--;
for(int i=0;i<count;i++)
{
if(stu[i].stuNo == id)
{
break;
}
}
if(i != count)
{
printf("\n");
print_h();
printf("\t %d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].ChineseScore,stu[i].MathsScore,stu[i].EnglishScore,stu[i].totalScore,stu[i].avgScore);
}
else
{
printf("\n\n\t\t没有找到你要查询的相关记录!\n");
}
printf("\n\t\t按任意键继续...\n");
getch();
system("cls");
mainFrame();
}
≡ 查看、发表评论 ≡