VS C++ 编写学生管理系统 编译没错,运行没问题,可就是输入没结果,求解

图片说明

学生管理系统头文件
student.h

#ifndef _STUDENT
#define _STUDENT
#include
struct studentT{
long int no;
char name[10];
char sex;
char classes[10];
long int firstScore;
};
struct scoreT{
char course[10];
int score;
long int next;
};
void input();
void quiry();
void score();
void initialize();
#pragma comment( lib, "学生成绩管理系统.lib")
#endif

main()

#include "stdafx.h"
#include"stdio.h"
#include
#include "student.h"
void main()
{

int selector;
while (1){
printf("1--输入学生基本信息\n");
printf("2--输入考试成绩\n");
printf("3--查询学生信息\n");
printf("4--系统初始化\n");
printf("0--退出\n");
scanf_s("%d %*c",&selector);
}
switch (selector){
case 1:input();break;
case 2:score();break;
case 3:quiry();break;
case 4:initialize();break;
case 0: return ;
}
}

input()
#include "student.h"
#include
void input(){
FILE *fp;
long int no;
struct studentT s;
int flag=1;
int correct;

if(access("D:\\C语言\\student",0)==-1){
    printf("请先执行初始化\n");
    return ;
}
fp = fopen("D:\\C语言\\student","ab");
fseek(fp,0,SEEK_END);
no = ftell(fp)/sizeof(struct studentT);

while (flag)
{
    s.no=++no;
    s.firstScore=-1;
    do
    { 
        printf("请输入姓名:");
        gets(s.name);
        printf("请输入性别(M:男,F:女): ");
        s.sex=getchar();getchar();
        printf("请输入班级:");
        gets(s.classes);
        printf("%d\t%s\t%c\t%s\n",s.no,s.name,s.sex,s.classes);
        printf("信息正确吗?(0:正确,1:不正确)");
        scanf("%d",&correct);getchar();
    } while (correct);
    fwrite(&s,sizeof(struct studentT),1,fp);
    printf("还需要输入学生信息吗?(1:要,0:不要): ");
    scanf("%d",&flag);getchar();
}
fclose(fp);

}

score()
#include "student.h"
#include
void score(){
struct scoreT sco;
struct studentT stu;
FILE *studentp,*scorep;
long int max;

if(access("D:\\C语言\\student",0)==-1){
    printf("请先执行初始化!\n");
    return;
}

studentp=fopen("D:\\C语言\\student","rb+");
scorep=fopen("D:\\C语言\\student","ab");

fseek(studentp,0,SEEK_END);
max=ftell(studentp)/sizeof(struct studentT);
fseek(scorep,0,SEEK_END);

printf("请输入课程名字; ");
gets(sco.course);
while (1){
    printf("请输入学号: (输入-1表示结束)");
    scanf("%d",&stu.no);
    if (stu.no==-1)   break;
    if (stu.no>max) continue;
    printf("请输入成绩; ");
    scanf("%d",&sco.course);

    fseek(studentp,(stu.no-1)*sizeof(struct studentT),0);
    fread(&stu,sizeof(struct studentT),1,studentp);
    sco.next=stu.firstScore;
    stu.firstScore=ftell(scorep);
    fseek(studentp,(stu.no-1)*sizeof(struct studentT),0);
    fwrite(&stu,sizeof(struct studentT),1,studentp);
    fwrite(&sco,sizeof(struct studentT),1,scorep);
}
fclose(studentp);
fclose(scorep);

}

quiry()

#include "student.h"
#include
void quiry(){
struct scoreT sco;
struct studentT stu;
long int next;
FILE *studentp,*scorep;

if (access("D:\\C语言\\student",0)==-1){
    printf("无学生信息!\n");
    return ;
}

studentp=fopen("D:\\C语言\\student","rb");
scorep=fopen("D:\\C语言\\student","rb");

printf("请输入学号; ");
scanf("%d",&stu.no);
fseek(studentp,0,SEEK_END);
if((unsigned)stu.no * sizeof(struct studentT) > (unsigned)ftell(studentp)){
    printf("无此学号?\n");
    return ;
}

fseek(studentp,(stu.no-1)*sizeof(struct studentT),0);
fread(&stu,sizeof(struct studentT),1,studentp);
printf("%d\t%s\t%c\t%s\n",stu.no,stu.name,stu.sex,stu.classes);
next = stu.firstScore;
while (next!=-1){
    fseek(scorep,next,0);
    fread(&sco,sizeof(struct scoreT),1,scorep);
    printf("%-20s%d\n",sco.course,sco.score);
}
fclose(studentp);
fclose(scorep);

}

initialize()

#include "student.h"
void initialize(){
FILE *fp;
char flag;
printf("初始化操作将会删除所有信息!继续初始化请输入y:\a\a\a");
flag = getchar();
if (flag!='y'&&flag!='Y') return;
fp= fopen("D:\C语言\student","wb");
fclose(fp);
fp= fopen("D:\C语言\student","wb");
fclose(fp);
}

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问