| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 645 人关注过本帖
标题:【求助】这段代码为何会出现c(59) : error C2040: 'Input' : 'struct QUEST ...
只看楼主 加入收藏
kissmy含韵
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-6-28
收藏
 问题点数:0 回复次数:1 
【求助】这段代码为何会出现c(59) : error C2040: 'Input' : 'struct QUESTION *(struct QUESTION *
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>

#define QUE struct QUESTION
#define SIZE sizeof(struct QUESTION)



struct QUESTION
{
    char question[1001];/*题目*/
    char answer[4][100];/*选择题的四个选项*/
    int correctanswer;/*选择题的正确答案*/
    QUE *next;
};

/*下面的MenuChoice函数的功能显示开始界面*/
int MenuChoice(void)
{
    int choice;
    system("cls");
    printf("欢迎使用单项选择题标准化考试系统——made by 黄鸿辉、刘艺\n\n");
    printf("1.添加选择题\n2.回答选择题\n3.退出");
    printf("注意事项:教师可通过功能1录入选择题,请学生只使用功能2,切勿擅自更改题库!\n");
    printf("请输入您的选择\n");
    scanf("%d",&choice);/*输入选择*/
    return choice;/*返回选择值*/
}

/*下面的函数功能为从文件中读取题目和将题目添加到列表中*/
QUE *Openfile(QUE *p, FILE *r)
{
    QUE temp;
    while (fread(&temp,1,SIZE,r))
        p=Input(p,&temp);   
    return p;
}


/*下面的函数的功能为将列表中的题目保存到文件中*/
void Savefile(const QUE *p, FILE *q)
{
    fclose(q);
    if((q=fopen("question.txt","w"))==NULL)/*以写的方式重新打开文件*/
        return;
    while(p)
    {
        fwrite(p, 1, SIZE, q);
        p=p->next;
    }
}


 
/*下面的函数的功能为往列表中插入题目*/
QUE *Input(QUE *p,const QUE *q)
{
    QUE *question=(TEST *)malloc(SIZE);/*申请一段内存*/
    if(question==NULL)
        exit(0);
    *question=*q;
    question->next=p;
    return question;
}


/*下面的函数的功能为输入题目,选项以及正确答案*/
void InputQuestion(QUE *p)
{
    int i=0;
    printf("请输入选择题的题目:\n:");
    scanf("%s",p->question);
    for(i=0;i<4;i++)
    {
        printf("请输入选项%c的答案:\n",i+65);
        scanf("%s", p->answer[i++]);
    }
    p->correctanswer=Inputanswer();
}


/*下面的函数的功能为获答案*/
int Inputanswer()
{
    int i=0;
    fflush(stdin);
    while(i<65||i>68)/*限定选项范围*/
    {
        printf("请输入你的所选择的答案:");
        scanf("%c",&i);
    }
    return i;
}


/*下面的函数的功能为随机从题库中获取题目*/
QUE *Random(QUE *p,int length, int *q)
{
    int i;
    srand(time(NULL));
    i=rand()%length;/*选取读题的随机位置*/
    *q=i;
    while(i--)
        p=p->next;
    return p;
}


/*下面的函数的功能为显示菜单*/
QUE *List(QUE *p,int a)
{
    while(a)
    {
        p=p->next;
        a--;
    }
    return p;
}


/*下面的函数的功能为自动批改学生的答案并输出结果*/
void Correcting(QUE *p,int n,int length)
{
    int i=0;
    int j=0;
    int k=0;
    int l=n;
    int m;
    int flag=1;
    char result[1001];
    char *a=result;
    int record[1001];
    QUE *question;
    for(i=0,j=0;n--;j++)
    {
        flag=1;
        while(flag)/*确保题目随机性*/
        {
            flag=0;
            question=Random(p,length,&m);/*随机从题库中获得题目*/
            for(k=0;k<=j;k++)
            {
                if(record[k]==m)
                {
                    flag=1;
                    break;
                }
            }
        }
        record[j]=m;
        printf("%s\nA.%s\nB.%s\nC.%s\nD.%s\n\n", question->question, question->answer[0], question->answer[1], question->answer[2], question->answer[3]);
        if((*a=question->correctanswer)==(*(a+1)=Inputanswer()))
            ++i;
        a+=2;
    }
    *a='\0';
   
    for(a=result,j=0;*a!='\0';a+=2,j++)
    {
        printf("\n题目 %d\n",j+1);
        question=List(p,record[j]);
        printf("%d\nA.%s\nB.%s\nC.%s\nD.%s\n\n",question->question,question->answer[0],question->answer[1],question->answer[2],question->answer[3]);
        printf("\n%-13s%-13c%s\n","标准答案","你的答案","结果");
        printf("%-13c%-13c%s\n",*a,*(a+1),*a==*(a+1)?"正确":"错误");
        printf("点击回车查看结果");
        getch();/*暂停,点击回车继续*/
    }
    printf("\n你回答了%d道题, 其中答对了%d道题目, 最后成绩: %.2f\n\n", l, i, (float)i / l * 100.00);
    getch();
    system("cls");/*清屏函数 */
}



int main()
{
    QUE *beginning=NULL;
    QUE temp;
    long choice;
    long length=0;
    long i;
    FILE *fp=fopen("question.txt", "a+");
    beginning=Openfile(beginning,fp);
    while((choice=MenuChoice())!=3)
    {
        switch(choice)
        {
        case 1:
            InputQuestion(&temp);
            beginning=Input(beginning,&temp);
            ++length;
            Savefile(beginning,fp);
            fclose(fp);
            break;
        case 2:
            printf("请输入题目的数量:");
            scanf("%d",&i);
            Correcting(beginning,i,length);
            break;
        default:
            break;
        }
    }

    return 0;
}
            



        
搜索更多相关主题的帖子: 考试系统 question include 正确答案 
2012-06-28 12:55
kissmy含韵
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-6-28
收藏
得分:0 
大虾快进啊····
2012-06-28 12:55
快速回复:【求助】这段代码为何会出现c(59) : error C2040: 'Input' : 'struct ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019844 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved