-3

这是我用来访问测验题库的头文件,问题文件和这个头文件有效,但下一部分代码是我生成一个随机问题并添加一个计时元素不起作用,我想知道为什么。

            #ifndef Question_h // defines question
            #define Question_h // question bank
            #include <iostream> //include iostream
            #include <string> //includes a string
            #include <fstream> 


            using namespace std;
            ofstream file;
            class Question
            {
            private:

测验由 200 个字符 4 个答案和一个整数作为正确答案的问题组成

                char question_text[200];
                char answers_text[4][200];
                int correct_answer;


            public:

用于从问题库中获取问题的评估者变量

                std::string GetQuestionText();
                void SetQuestionText();

字符串以获得正确答案

                std::string GetAnswerText(int answer);
                void SetAnswerText();

答案号码

                int GetCorrectAnswerNo();
                void SetCorrectAnswerNo();


                void SetQuestion(); //nothing returned, and no arguements.


                void createandwritefile();


                char text[201];
                char answerYN;
                int number;


            };




            #endif

            // This is my code which doesnt seem to be working properly 
// should generate random questions and times the person so they only have 15sec

            #include <string> //Adds the string to the code
            #include <iostream> //This is the input and output of the code 
            #include <ctime> //This is the timing element of the code 
            #include <fstream>
            #include "Question.h" /** Access to Leanne's Question Bank 

            }
            int main ( )
            {

            // to randomly generate the quiz questions
            class Randomly generate data
                int q_no;
                int reply;
                int i=0;
                bool already-used=FALSE;
                int q_list[10];

                unsigned seed=time(NULL);
    // Generates a number between 1 and 30
                // with max number 30
//min number 1
//using a pseudo ranom function

                        srand(seed)
                    int min=1;
                    int max=30;
                    int range=max-min+1
                    q_no=rand()/100%range+min
            q_list[0]=rand()/100%range+min;
                    while(i++<10)

                    {
                        do

                        {
                            already_used =FALSE; // if number is already used it generates another random number
                            q_list[i]=rand()/100%range+min;
                            for(int j=0; j<i; j++)

                            {
                                if (q_list[j]==q_list[i])
                                    already_used=TRUE;
                            }
                        }

                        while (already_used==TRUE);
    //if the same number has been used before the loop begins again

                    }

    //gets the questions from the question bank
    //the question comes with 4answers

                cout<<QuestionBank[q_no-1].GetQuestionText();
                cout<<QuestionBank[q_no-1].GetANswerText(0);
                cout<<QuestionBank[q_no-1].GetANswerText(1);
                cout<<QuestionBank[q_no-1].GetANswerText(2);
                cout<<QuestionBank[q_no-1].GetANswerText(3);

                    cin>>reply
                        if (reply==QuestionBank[q_no-1}.GetCorrectAnswerNo());
                    cout<<"Well Done Thats the Right Answer";
                        else
                    cout<<"Not So Smart This Time";

    //if the answer is the right reply the user gets told if not get informed they arent so smart



            class TimingElement

    //determines if the player completes the question within 15seconds if not time is up

            {   // Start time is recorded and the user is given 15sec

                    time_t start = time(NULL);

                    cin >> user_input;

                    delay = time(NULL)-start;

                    if(delay > 15)


                    {
                         cout <<"\n\n\t\t\tYou Took too long this time!! (" << delay << " seconds.)";

                         return(0);

                    }
            If they answer within 15seconds
                    if(operatorA == user_input)


                    {
                         cout<<"\n\n\t\t\tCorrect";
                         return(1);


                    }

在给定时间内回答正确时

                    else


                    {

                           cout <<"\n\n\t\t\tNot so smart this time  ";
                           return(0);

如果在给定时间内没有回答}

            }

             return(0);

代码结束

4

1 回答 1

0

您的TimingElement类定义不正确。

阅读本课程教程,了解如何在 C++ 中定义和使用类。

于 2013-04-30T15:40:47.957 回答