录入成绩c语言咋弄,成绩录入程序、、、求人讲解

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

师父给的是这个

#include

#include

#define MAX_COUNT 5

#define MAX_NAME_LEN 20

#define BOOL int

#define TRUE 1

#define FALSE 0

#define CMD_ADD 'a'

#define CMD_QUERY 'f'

#define CMD_SORT 's'

#define CMD_QUIT 'q'

#define DATA_FILE "stds.dat"

struct StudentScore

{

int chineseScore;

int mathScore;

int englishScore;

};

struct StudentInfo

{

char name[MAX_NAME_LEN];

struct StudentScore scores;

};

int getScore(char * hint);

void getAStd(struct StudentInfo * std);

void getStds(struct StudentInfo stds[], int arrayCount);

void sortTotalScore(struct StudentInfo stds[], int arrayCount);

int getTotal(struct StudentScore * score);

BOOL fileExists(char * file);

void saveStds();

void loadStds();

void usage();

void add();

void find();

void displayStd(struct StudentInfo* std);

int gCount = 0;

struct StudentInfo gStds[MAX_COUNT];

void main()

{

char cmd;

int i, num;

num = MAX_COUNT;

loadStds();

while(1)

{

fflush(stdin);

printf("please input cmd:");

cmd = getchar();

switch(cmd)

{

case CMD_ADD:

add();

break;

case CMD_QUERY:

find();

break;

case CMD_SORT:

sortTotalScore(gStds, MAX_COUNT);

for (i = 0; i < gCount; i++)

printf("name %s : totoal %d \n", gStds[i].name, getTotal(&(gStds[i].scores)));

printf("\n");

break;

case CMD_QUIT:

return;

default:

usage();

break;

}

printf("\n");

}

}

void usage()

{

printf("find is %c\n", CMD_QUERY);

printf("quit is %c\n", CMD_QUIT);

printf("add is %c\n", CMD_ADD);

printf("sort is %c\n", CMD_SORT);

}

void saveStds()

{

int i;

FILE * fp;

fp = fopen(DATA_FILE, "wb");

if (fp == NULL)

return;

for(i = 0; i < gCount; i++)

fwrite(&gStds[i], sizeof(struct StudentInfo), 1, fp);

fclose(fp);

}

BOOL fileExists(char * file)

{

FILE * fp;

fp = fopen(DATA_FILE, "rb");

if (fp == NULL)

return FALSE;

return TRUE;

}

void loadStds()

{

FILE * fp;

int isEnd;

struct StudentInfo temp;

if (MAX_COUNT == 0)

{

printf("no space\n");

}

if (!fileExists(DATA_FILE))

return;

gCount = 0;

fp = fopen(DATA_FILE, "rb");

if (fp == NULL)

return;

isEnd = 0;

while(1)

{

if (fread(&gStds[gCount], sizeof(struct StudentInfo), 1, fp) == 1)

gCount++;

else

isEnd = 1;

if (isEnd)

{

break;

}

else

{

if (gCount == MAX_COUNT)

{

if (fread(&temp, sizeof(struct StudentInfo), 1, fp) == 1)

printf("no space\n");

break;

}

}

}

fclose(fp);

}

void add()

{

if (gCount == MAX_COUNT)

{

printf("over limit\n");

return;

}

gCount++;

getAStd(&gStds[gCount - 1]);

saveStds();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值