帮忙把下段C程序改成由C++ 编译的程序! 谢谢啦
#include
#include
#include
struct question {
char ask[200];/*选择题题目*/
char answer[4][80];/*选择题选项*/
int right;/*正确答案*/
struct question *next;
};
int MenuChoice(void);
struct question *InsertList(struct question *fst, const struct question *ad);
struct question *ListRandSeek(struct question *seek, int len, int *posi);
struct question *ListSeek(struct question *seek, int posi);
void GetQuestion(struct question *src);
void SaveFile(const struct question *ed, FILE *saf);
struct question *LoadFile(struct question *td, long *count, FILE *laf);
int GetAnswer(void);
void ExplainQuestion(struct question *que, int n, int len);
main()
{
struct question *start = NULL, temp;
long choice, line = 0, c;
FILE *fp = fopen("kstm.dat", "a+");
start = LoadFile(start, &line, fp);
while ((choice = MenuChoice()) != 3)
if (choice == 1) {
GetQuestion(&temp);
start = InsertList(start, &temp);
++line;/*统计列表的长度*/
}
else if (choice == 2){
c =600;
while (c > 500 || c > line) {
printf("请输入要回答的问题数量: ");
scanf("%d", &c);
}
ExplainQuestion(start, c, line);
}
SaveFile(start, fp);/*进行最后的工作*/
fclose(fp);
return 0;
}
/*ListSeek函数确定一个读取答案的位置,len代表要读取的答案数,max代表列表的长度*/
struct question *ListRandSeek(struct question *seek, int len, int *posi)
{
int i;
srand(time(NULL));
i = rand() % len; /*随机选取一个读题目的位置*/
*posi = i;
while (i--)
seek = seek->next;/*找到指定的位置*/
return seek;
}
struct question *ListSeek(struct question *seek, int posi)
{
while (posi)
{
seek = seek->next;
posi--;
}
return seek;
}
/*向列表中插入试题*/
struct question *InsertList(struct question *fst, const struct question *ad)
{
struct question *newPtr = (struct question *)malloc(sizeof(struct question));
if (newPtr == NULL)
exit(0);
*newPtr = *ad;
newPtr->next = fst;
return newPtr;
}
/*获取问题,选项,以及正确答案*/
void GetQuestion(struct question *src)
{
int i = 0;
printf("请输入选择题题目:\n");
scanf("%s", src->ask);
while (i answer[i++]);
}
src->right = GetAnswer();
}
/*从文件中读取题目,将题目添加到列表中*/
struct question *LoadFile(struct question *td, long *count, FILE *laf)
}
后面还有段传不上来 超过字数了 请加QQ23779278 帮忙也改下 谢谢了!
|