2013-04-30 3 views
-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: 

퀴즈는

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


      public: 

평가자 변수를 얻을 수

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

문자열 문제 은행에서 qustions를 가져 오는 데 사용 200characters 4answers하고 정확한 답변으로 정수와 질문으로 구성 정답은

   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); 


        } 

주어진 시간 } 코드의

  } 

      return(0); 

최종 내에 응답하지 않을 경우

    else 


        { 

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

주어진 시간 내에 올바른 대답 할 때

+0

정확히 무엇이 오류입니까? – ryrich

+0

헤더 파일에 모든 것을 넣으려고합니까? –

+0

코드를 좀 더 읽기 쉽도록 정리하는 것이 좋습니다. 특히 3 개월 후에 돌아오고 쓴 것을 해독하려고 할 때 배당금을 지불하는 것이 진정한 이점입니다. – eriknelson

답변

0

당신의 TimingElement 클래스 정의가 잘못되었습니다.

C++에서 클래스를 정의하고 사용하는 방법을 이해하려면 class tutorial을 읽어야합니다.

관련 문제