Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #define MAXANSWERCOUNT 100
- #define MAXQUESTIONCOUNT 100
- using namespace std;
- class HSurvey //해성이가 만든 설문조사 클래스
- {
- public:
- //void addQuestion(HQuestion question) //질문 등록
- //{
- //}
- private:
- };
- class HQuestion
- {
- public:
- void setQuestionData()
- {
- this->setQuestion();
- this->setAnswerCount(); //내꺼의 setAnswerCount 실행
- //HQuestion::setAnswerCount();
- this->setAnswer();
- }
- string getQuestionData()
- {
- return question;
- }
- int getAnswerCount()
- {
- return answerCount;
- }
- private:
- int answerCount = 0;
- string question;
- string answer[MAXANSWERCOUNT];
- void setQuestion()
- {
- cout << "질문의 내용을 입력하세요 \n # ";
- getline(cin, question);
- this->setAnswerCount(); //내꺼의 setAnswerCount 실행
- //HQuestion::setAnswerCount();
- }
- void setAnswerCount()
- {
- while (answerCount < 1) //answerCount가 1보다 작으면 ㅈㄹ하기
- {
- cout << "질문의 답변 갯수를 입력하세요 (1보다 같거나 큰 정수) \n # ";
- string input;
- getline(cin, input);
- answerCount = stoi(input);
- if (answerCount < 1)
- {
- cout << "옳바르지 않은 값입니다 \n";
- }
- }
- }
- void setAnswer()
- {
- for (int i = 0; i < answerCount; i++)
- {
- cout << i + 1 << "번째 답변을 입력하세요 \n # ";
- getline(cin, answer[i]);
- }
- }
- };
- void printQuestion(HQuestion inputQuestion)
- {
- cout << "질문: " << inputQuestion.getQuestionData() << "\n";
- }
- int main()
- {
- int questionCount = 0;
- while (questionCount < 1)
- {
- cout << "질문의 갯수를 정하세요 (1보다 같거나 큰 정수) \n # ";
- string input;
- getline(cin, input);
- questionCount = stoi(input);
- if (questionCount < 1)
- {
- cout << "옳바르지 않은 값입니다 \n";
- }
- }
- HQuestion question[MAXQUESTIONCOUNT];
- for (int i = 0; i < questionCount; i++)
- {
- question[i].setQuestionData();
- }
- printQuestion(question[1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement