Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. #define MAXANSWERCOUNT 100
  6. #define MAXQUESTIONCOUNT 100
  7.  
  8. using namespace std;
  9.  
  10.  
  11. class HSurvey                               //해성이가 만든 설문조사 클래스
  12. {
  13.     public:
  14.         //void addQuestion(HQuestion question)                  //질문 등록
  15.         //{
  16.        
  17.         //}
  18.  
  19.     private:
  20.  
  21.  
  22. };
  23.  
  24. class HQuestion
  25. {
  26.     public:
  27.    
  28.         void setQuestionData()
  29.         {
  30.             this->setQuestion();
  31.             this->setAnswerCount();                 //내꺼의 setAnswerCount 실행
  32.             //HQuestion::setAnswerCount();
  33.             this->setAnswer();
  34.         }
  35.  
  36.         string getQuestionData()
  37.         {
  38.             return question;
  39.         }
  40.         int getAnswerCount()
  41.         {
  42.             return answerCount;
  43.         }
  44.  
  45.     private:
  46.         int answerCount = 0;
  47.         string question;
  48.         string answer[MAXANSWERCOUNT];
  49.  
  50.  
  51.         void setQuestion()
  52.         {
  53.             cout << "질문의 내용을 입력하세요 \n # ";
  54.             getline(cin, question);
  55.             this->setAnswerCount();                 //내꺼의 setAnswerCount 실행
  56.             //HQuestion::setAnswerCount();
  57.         }
  58.         void setAnswerCount()
  59.         {
  60.             while (answerCount < 1) //answerCount가 1보다 작으면 ㅈㄹ하기
  61.             {
  62.                 cout << "질문의 답변 갯수를 입력하세요 (1보다 같거나 큰 정수) \n # ";
  63.                 string input;
  64.                 getline(cin, input);
  65.                 answerCount = stoi(input);
  66.                 if (answerCount < 1)
  67.                 {
  68.                     cout << "옳바르지 않은 값입니다 \n";
  69.                 }
  70.             }
  71.         }
  72.         void setAnswer()
  73.         {
  74.             for (int i = 0; i < answerCount; i++)
  75.             {
  76.                 cout << i + 1 << "번째 답변을 입력하세요 \n # ";
  77.                 getline(cin, answer[i]);
  78.             }
  79.         }
  80.  
  81. };
  82.  
  83. void printQuestion(HQuestion inputQuestion)
  84. {
  85.     cout << "질문: " << inputQuestion.getQuestionData() << "\n";
  86.    
  87. }
  88.  
  89. int main()
  90. {
  91.     int questionCount = 0;
  92.     while (questionCount < 1)
  93.     {
  94.         cout << "질문의 갯수를 정하세요 (1보다 같거나 큰 정수) \n # ";
  95.         string input;
  96.         getline(cin, input);
  97.         questionCount = stoi(input);
  98.         if (questionCount < 1)
  99.         {
  100.             cout << "옳바르지 않은 값입니다 \n";
  101.         }
  102.     }
  103.  
  104.     HQuestion question[MAXQUESTIONCOUNT];
  105.    
  106.     for (int i = 0; i < questionCount; i++)
  107.     {
  108.         question[i].setQuestionData();
  109.     }
  110.  
  111.  
  112.     printQuestion(question[1]);
  113.  
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement