C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[72009] Re:Re:프로그램 거의 다 만들었는데 이게 잘 안되요...
[] 3458 읽음    2014-11-21 13:51

fflush(stdin);  // 이것만 붙이시면 되겠네요.

테스트해봤는데 잘 되네요.

수고하세요~

빌더입문자 님이 쓰신 글 :
:
: 안녕하세요
:
: 1,2 문항이 동시에 나오는것만 문제라면..
: 입력 버퍼 초기화를 하시면 될 것 같은데요?
:
: 그럼 수고하세요^^
:
:
: 초보자 님이 쓰신 글 :
: : 안녕하세요.
: :
: : 제가 C++프로그램을 하나 만들고 있는데요.
: :
: : 첨부파일 처럼 만들거에요.
: :
: : 지금 거의 만들었는데... 주변 사람들의 조언을 얻어 짜집기한거라 좀 어지럽네요.
: :
: : #include <iostream>
: : #include <cstring>
: :
: : using namespace std;
: :
: :
: : class Question
: : {
: : private:
: :     char*  contents;
: :     char** answerlist;
: :     int*   answercount;
: :     int    answernum;
: : public:
: :     Question()
: :     {
: :         InitQuestion();
: :     }
: :     void InitQuestion()
: :     {
: :         contents    = NULL;
: :         answerlist  = NULL;
: :         answercount = NULL;
: :         answernum   = 0;
: :     }
: :     void SetContents (char* _contents)
: :     {
: :         if(contents != NULL)
: :             delete[] contents;
: :            
: :         contents = new char [ strlen(_contents)+1 ];
: :         strcpy(contents, _contents);
: :     }
: :     char* GetContents ()
: :     {
: :         return contents;
: :     }
: :     void AllocAnswerList (int _size)
: :     {
: :         if(answerlist != NULL)
: :             delete[] answerlist;
: :         if(answercount != NULL)
: :             delete[] answercount;
: :            
: :         answerlist  = new char*[ _size ];
: :         answercount = new int  [ _size ];
: :         answernum = _size;
: :     }
: :     void SetAnswerList (int _num, char* _answer)
: :     {
: :         answerlist[ _num ] = new char [ strlen(_answer)+1 ];
: :         strcpy( answerlist[ _num ], _answer);
: :         answercount[ _num ] = 0;
: :     }
: :     char* GetAnswerlist (int _num)
: :     {
: :         return answerlist[ _num ];
: :     }
: :     int GetAnswerNum ()
: :     {
: :         return answernum;
: :     }
: :     void CountUp (int _num)
: :     {
: :         answercount[_num-1]++;
: :     }
: :     int GetAnswerValue (int _num)
: :     {
: :         return answercount[_num];
: :     }
: :     ~Question()
: :     {
: :         if(contents != NULL)
: :             delete[] contents;
: :         if(answerlist != NULL)
: :             delete[] answerlist;
: :         if(answercount != NULL)
: :             delete[] answercount;
: :         InitQuestion();
: :     }
: : };
: :
: : class QuestionManager
: : {
: : private:
: :     Question* QuestionList;
: :     int QuestionNum;
: : public:
: :     QuestionManager()
: :     {
: :         InitQuestionManager();
: :     }
: :     void InitQuestionManager()
: :     {
: :         QuestionList = NULL;
: :         QuestionNum  = 0;
: :     }
: :     void AllocQuestionList (int _num)
: :     {
: :         QuestionList = new Question[ _num ];
: :         QuestionNum  = _num;
: :     }
: :     void SetQuestionList (int _num)
: :     {
: :         char QuestionTemp[128];
: :         int  distracter_num;
: :        
: :         cout<<_num+1<<"번째 설문내용 작성을 시작합니다."<<endl;
: :         QuestionList[_num].InitQuestion();
: :        
: :         cout<<"등록할 설문 문항을 입력하시오 : ";
: :         cin.getline(QuestionTemp,128);
: :         QuestionList[_num].SetContents(QuestionTemp);
: :        
: :         cout<<"선택할 답항의 수를 입력하시오 : ";
: :         fflush(stdin);
: :         cin>>distracter_num;
: :         QuestionList[_num].AllocAnswerList(distracter_num);
: :        
: :         for(int i=0; i < distracter_num; i++)
: :         {
: :             cout<<"답항 "<<i+1<<"--> ";
: :             cin.getline(QuestionTemp,128); //재활용
: :             QuestionList[_num].SetAnswerList(i,QuestionTemp);
: :         }
: :     }
: :     void ProgressQuestion ()
: :     {
: :         int answervalue;
: :        
: :         cout<<"설문을 시작합니다."<<endl;
: :         system("pause");
: :        
: :         for(int i=0; i<QuestionNum; )
: :         {
: :             system("cls");
: :             cout<<endl<<QuestionList[i].GetContents()<<endl;
: :             for(int j=0; j<QuestionList[i].GetAnswerNum(); j++)
: :             {
: :                 cout<<"["<<j+1<<"] "<<QuestionList[i].GetAnswerlist(j)<<endl;
: :             }
: :             cout<<"선택(0은 종료) : ";
: :             cin>>answervalue;
: :             if(answervalue==0)
: :                 i++;
: :             else if(answervalue > 0 && answervalue <= QuestionList[i].GetAnswerNum() )
: :             {
: :                 QuestionList[i].CountUp(answervalue-1);
: :             }
: :             else
: :             {
: :                 cout<<"잘못된 입력입니다."<<endl;
: :                 system("pause");
: :             }
: :         }
: :     }
: :     void PrintStatistics (int _num)
: :     {
: :         cout<<endl<<endl<<_num+1<<"번째 설문에 대한 통계입니다."<<endl;
: :         cout<<QuestionList[ _num ].GetContents()<<endl;
: :         for(int i=0; i<QuestionList[_num].GetAnswerNum(); i++ )
: :         {
: :             cout<<"["<<i+1<<"] "<<QuestionList[ _num ].GetAnswerlist(i)<<" --> "<<QuestionList[ _num ].GetAnswerValue(i)<<endl;
: :         }
: :     }
: :     ~QuestionManager()
: :     {
: :         if(QuestionList!=NULL)
: :             delete[] QuestionList;
: :         InitQuestionManager();
: :     }
: : };
: :
: : int main ()
: : {
: :     QuestionManager QM;
: :     QM.InitQuestionManager(); // QM 초기화
: :     QM.AllocQuestionList(1); //설문하나 할당
: :     QM.SetQuestionList(0); //0번째 설문의 내용작성
: :     QM.ProgressQuestion(); //설정된 모든 설문을 진행
: :     QM.PrintStatistics(0); //0번째 설문의 통계 출력
: :     system("pause");
: : }
: :
: : 위와 같은데요. 우선 첨부파일처럼 1 문항 --> 문항적고
: :                                                2 문항 --> 문항 적고
: : 하고 싶은데
: : 계속 1,2 문항이 동시에 나오고 2문항 옆에만 쓸 수 있어요.
: :
: : 또 작성할 문항 수에 3이라고 적으면
: :
: : 1,2 문항에서 멈춘다음 3문항이 나와요..
: :
: : 어떻게 해결할 수 있을까요?

+ -

관련 글 리스트
72005 프로그램 거의 다 만들었는데 이게 잘 안되요... 초보자 3502 2014/11/19
72008     Re:프로그램 거의 다 만들었는데 이게 잘 안되요... 빌더입문자 3571 2014/11/21
72009         Re:Re:프로그램 거의 다 만들었는데 이게 잘 안되요... 3458 2014/11/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.