ÇÁ·Î±×·¡¹Ö

 3198, 1/160 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ksbgenius
   [C++]°ü¸® ÇÁ·Î±×·¥ swich-case¹® °ü·Ã Áú¹®

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=3046 [º¹»ç]


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int MAX_STD =2;
const int MAX_SBJ = 10;

class PersonalInformation {
        int num;
        char *name;
        
public:
        PersonalInformation() {}
        PersonalInformation(int n, char *name);
        PersonalInformation(const PersonalInformation &inf);
        void SetNum(int n) { num = n;}
        void SetName(char *str);
        int GetNum() {return num;}
        char *GetName() {return name;}
        void OutputData();
};

class Score : public PersonalInformation{//»ó¼Ó
        int score[MAX_SBJ];
        bool isInformation;
        double average;
        bool isScore;
public:
        Score(){}
        Score(int n, char *name) : PersonalInformation(n, name)
        {isInformation = false;}
        void SetScore(int i, int sc) {score[i] = sc;}
        void SetIsInformation(bool i) {isInformation = i;}
        void SetAverage(double avr){average = avr;}
        void SetIsScore(bool b){isScore = b;}
        int GetScore(int i){return score[i];}
        bool GetIsInformation() {return isInformation;}
        double GetAverage(){return average;}
        bool GetIsScore(){return isScore;}
};

class ScoreManager{
        Score *pSc[MAX_STD];
        char *subject[MAX_SBJ];
        int std_index;
        int sbj_index;
public:
        ScoreManager();
        void ShowMenu();//¸Þ´º¼±ÅÃ
        void CollegeGraduate();//Çлç
        void ManagementConsult();//»ó´ã°ü¸®
        void Mileage();//¸¶Àϸ®Áö
        void DataManagement();//ÇÐÀûÀÚ·á°ü¸®
        void EditPersonalInformation();//°³ÀÎÁ¤º¸¼öÁ¤
        void Eclass();//Eclass
        void StudentMainScreen();//Çлý¸ÞÀÎÈ­¸é
        void CourseManagement();//¼ö°­°ü¸®
        void CourseSubjectView();//¼ö°­°ú¸ñÁ¶È¸
        void Grademanagement();//¼ºÀû°ü¸®
        void CumulativeGradeReview();//´©Àû¼ºÀûÁ¶È¸
        void ConsultationRequest();//»ó´ã½Åû
        void PointAcquisition();//Æ÷ÀÎÆ® Ãëµæ ÇöȲ
        void OutputScore();//¼ºÀûÁ¶È¸
        void InputScore();//¼ºÀû ÀÔ·Â
};

PersonalInformation::PersonalInformation(int n, char *name)
{
        num = n;
        SetName(name);

}

void PersonalInformation::SetName(char *str)
{
        name = new char[strlen(str)+1];
        
}
ScoreManager::ScoreManager()
{
        std_index = 0;
}
void ScoreManager::OutputScore()
{
        for(int i = 0; i < std_index; i++){
                if(pSc[i] ->GetIsInformation()==true){
                        cout <<">Çйø : " << pSc[i]->GetNum() << endl;
                        cout <<">À̸§ : " << pSc[i]->GetName() << endl;
                }
        }
}


int main(void)
{
        int menu;
        ScoreManager sm;

        while(1) {
                sm.ShowMenu();
                cout << "¸Þ´º¼±Åà : ";
                cin >> menu;
                
        switch(menu){
                case 1 :
                        sm.CollegeGraduate();                
                        int menu1 ;

                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu1;
                        switch(menu1){
                case 1 :
                        sm.DataManagement();

                        int menu2;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu2;

                        switch(menu2){
                case 1:
                        sm.EditPersonalInformation();
                        break;
                case 2:
                        return 0;                
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;
                        
                
                case 2:
                        sm.Eclass();
                        int menu3;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu3;
                        switch(menu3){
                case 1:
                        sm.StudentMainScreen();
                        break;
                case 2:
                        return 0;        
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;

                case 3:
                        sm.CourseManagement();
                        int menu4;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu4;
                        switch(menu4){
                case 1:
                        sm.CourseSubjectView();
                        break;
                case 2:
                        return 0;        
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;

                case 4:
                        sm.Grademanagement();
                        int menu5;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu5;
                        switch(menu5){
                case 1:
                        sm.InputScore();
                        break;
                case 2:
                        sm.CumulativeGradeReview();
                        break;
                case 3:
                        return 0;        
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;

                case 5:
                        return 0;
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        }
                        break;

                case 2:
                        sm.ManagementConsult();
                        int menu6;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu6;
                        switch(menu6){
                case 1:
                        sm.ConsultationRequest();
                        break;
                case 2:
                        return 0;        
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;

                case 3:
                        sm.Mileage();
                        int menu7;        
                        while(1){
                                cout << "¸Þ´º¼±Åà : ";
                                cin >> menu7;
                        switch(menu7){
                case 1:
                        sm.PointAcquisition();
                        break;
                case 2:
                        return 0;
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
                        }
                        break;
                        }
                        break;

                case 4:
                        return 0;
                default:
                        cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
        }
        break;

        }
return 0;
}


void ScoreManager::ShowMenu(void)//¼±Åà ¸Þ´º ÇÁ¸°Æ®
{
        cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. ÇР   »ç" << endl;
        cout << "2. »ó´ã°ü¸®" << endl;
        cout << "3. ¸¶Àϸ®Áö" << endl;
        cout << "4. Á¾    ·á" << endl;
}
void ScoreManager::CollegeGraduate(void)//Çлç
{
        cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. ÇÐÀû°ü¸®" << endl;
        cout << "2. E-Class" << endl;
        cout << "3. ¼ö°­°ü¸®" << endl;
        cout << "4. ¼ºÀû°ü¸®" << endl;
        cout << "5. Á¾    ·á" << endl;
}
void ScoreManager::DataManagement(void)//ÇÐÀû°ü¸®
{
        cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. °³ÀÎ Á¤º¸ ¼öÁ¤" << endl;
        cout << "2. Á¾    ·á" << endl;
}
void ScoreManager::EditPersonalInformation(void)//°³ÀÎÁ¤º¸¼öÁ¤
{
        int n;
        char s[10];
        cout << "-----°³ÀÎÁ¤º¸µî·Ï" << endl;
        cout << "Çйø : " ; cin >> n;
        cout << "À̸§ : " ; cin >> s;


        pSc[std_index] = new Score(n,s);//Score °´Ã¼ µ¿Àû ¸Þ¸ð¸® ÇÒ´ç

        std_index++;
        for(int i = 0; i < std_index; i++){
                if(pSc[i] ->GetNum() == n){
                        if(pSc[i]->GetIsInformation() == true){
                                cout <<"!!!ÀÌ¹Ì µî·ÏµÈ ÇлýÀÔ´Ï´Ù."<<endl;
                                return ;
                        }
                        pSc[i]->SetIsInformation(true);//Á¤º¸ ÀÔ·Â ¿©ºÎ Ç¥½Ã.
                        return;
                        
                }
        }
}


void ScoreManager::Eclass(void)//Eclass
{
        cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. Çлý¸ÞÀÎÈ­¸é" << endl;
        cout << "2. Á¾    ·á" << endl;
}

void ScoreManager::StudentMainScreen(void)//Çлý¸ÞÀÎÈ­¸é
{
        
        char s;
        ifstream fi;
        fi.open("StudentMainScreen.txt");//ÀÔ·Â ÆÄÀÏ °³¹æ
        if (!fi){
                cout << "!Can't open input file <StudentMainScreen.txt>\n";
                exit(1);
        }
        fi.unsetf(ios::skipws);
        while (!fi.eof()){                
                fi >> s;
                if (s==' ' )        
                        s = ' ';//°ø¹éµµ Æ÷ÇÔÇØ¼­ Ãâ·Â.
                cout << s;
        }
}
void ScoreManager::CourseManagement(void)//¼ö°­°ü¸®
{
        cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. ¼ö°­°ú¸ñÁ¶È¸" << endl;
        cout << "2. Á¾    ·á" << endl;
}
void ScoreManager::CourseSubjectView(void)//¼ö°­°ú¸ñÁ¶È¸
{
        char s;
        ifstream fi;
        fi.open("CourseSubjectView.txt");//ÀÔ·Â ÆÄÀÏ °³¹æ
        if (!fi){
                cout << "!Can't open input file <CourseSubjectView.txt>\n";
                exit(1);
        }
        fi.unsetf(ios::skipws);
        while (!fi.eof()){                
                fi >> s;
                if (s==' ' )        
                        s = ' ';
                cout << s;
        }
}
void ScoreManager::Grademanagement(void)//¼ºÀû°ü¸®
{
    cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. ¼ºÀû ÀÔ·Â" << endl;
        cout << "2. ´©Àû¼ºÀûÁ¶È¸" << endl;
        cout << "3. Á¾    ·á" << endl;
}
void ScoreManager::CumulativeGradeReview(void)//¼ºÀû ÅëÁö¼­
{

        char s;
        ifstream fi;
        fi.open("CumulativeGradeReview.txt");//ÀÔ·Â ÆÄÀÏ °³¹æ
        if (!fi){
                cout << "!Can't open input file <CumulativeGradeReview.txt>\n";
                exit(1);
        }
        fi.unsetf(ios::skipws);
        while (!fi.eof()){                
                fi >> s;
                if (s==' ' )        
                        s = ' ';
                cout << s;
        }
}
void ScoreManager::InputScore()//¼ºÀûÀÔ·Â ¹× ±³°ú¸ñ µî·Ï ÀÛ¾÷Áß.......
{
        int n, sc, total = 0;
        char s[20];
        cout <<"===±³°ú¸ñ µî·Ï===" << endl;
        cout <<"°ú¸ñ ¼ö : " ; cin >>n;
        
        for (int i = 0; i < n; i++){
                cout <<"±³°ú¸ñ ¸í : " << i+1 << " : " ; cin >>s;
                subject[i] = new char[strlen(s)+1];
                
        }
        sbj_index = n;
        return;

        cout <<"===¼ºÀûÀÔ·Â===" << endl;
        cout <<"Çйø : " ; cin >> n;

        for(int i = 0;  i < std_index; i++){
                if (pSc[i]->GetNum() == n){
                        if(pSc[i]->GetIsScore()==true){
                                cout << "!!! ÀÌ¹Ì ¼ºÀûÀÌ ÀԷµǾú½À´Ï´Ù.\n";
                                        return;
                        }
                        cout <<"À̸§ :  " <<pSc[i]->GetName() << endl;
                        
                        for(int j=0; j < sbj_index; j++){
                                cout << "> " << subject[j] << " : ";
                                cin >>sc;
                                pSc[i]->SetScore(j,sc);
                                total += sc;
                        }
                        pSc[i]->SetAverage(total / double(sbj_index));
                        pSc[i]->SetIsInformation(true);
                        return;

                }
        }
}
void ScoreManager::ManagementConsult(void)//»ó´ã°ü¸®
{
    cout << "========== ¸Þ   ´º ==========" << endl;
          cout << "1. »ó´ã½Åû" << endl;
        cout << "2. Á¾    ·á" << endl;
}

void ScoreManager::ConsultationRequest(void)//»ó´ã½Åû
{
        char s;
        ifstream fi;
        fi.open("ConsultationRequest.txt");//ÀÔ·Â ÆÄÀÏ °³¹æ
        if(!fi){
                cout <<"!Can't open input file <ConsultationRequest.txt>\n";
                        exit(1);
        }
        fi.unsetf(ios::skipws);
        while(!fi.eof()){
                fi >> s;
                if( s ==' ')
                        s = ' ';
                cout << s;
        }
}

void ScoreManager::Mileage(void)//¸¶Àϸ®Áö
{
    cout << "========== ¸Þ   ´º ==========" << endl;
        cout << "1. Æ÷ÀÎÆ® Ãëµæ ÇöȲ" << endl;
        cout << "2. Á¾    ·á" << endl;
}
void ScoreManager::PointAcquisition(void)//Æ÷ÀÎÆ® ÃëµæÇöȲ
{

        char s;
        ifstream fi;
        fi.open("PointAcquistion.txt");//ÀÔ·Â ÆÄÀÏ °³¹æ
        if(!fi){
                cout <<"!Can't open input file <PointAcquistion.txt>\n";
                        exit(1);
        }
        fi.unsetf(ios::skipws);
        while(!fi.eof()){
                fi >> s;
                if( s ==' ')
                        s = ' ';
                cout << s;
        }
}

Á¦°¡ °ü¸® ÇÁ·Î±×·¥ ¸¸µé°í Àִµ¥,
switch - case¹®¿¡¼­ Àú´Â Áߺ¹ ½ºÀ§Ä¡ ¹®À» »ç¿ëÇÏ¿´½À´Ï´Ù.
±Ã±ÝÇÑ °ÍÀº
¸Þ´º¸¦ ¼±ÅÃÇÏ¿© ÇÏÀ§ ¸Þ´º·Î µé¾î °¬À¸¸é, ´Ù½Ã »óÀ§¸Þ´º·Î °¡°í ½ÍÀºµ¥.. ¾î¶»°Ô ÇØ¾ß ÇÒÁö...
¸¸¾à Çлç-ÇÐÀû°ü¸®-°³ÀÎÁ¤º¸¼öÁ¤ ÀÌ·¸°Ô µé¾î °¡¼­ µî·ÏÀ» ÇÑ ´ÙÀ½¿¡ ´Ù½Ã ¸Ç »óÀ§ ¸Þ´º·Î ´Ù½Ã µ¹¾Æ°¥ ¼ö ¾ø³ª¿ä??

  Hit : 5515     Date : 2011/06/10 03:49



    
º°ºûÀ»´ã¾Æ goto¹® ¾²¼¼¿ä
³Ê¹« ³²¹ßÇÏÁö¸¸ ¾ÊÀ¸¸é goto¹®µµ ±¦Âú½À´Ï´Ù.
2011/06/10  
ksbgenius goto À̹æ¹ý ¸»°í´Â ¾ø´Â °É±î¿ä.....
ÀÌ°Ç Á¦´ë·Î ¸ø¹è¿ö¼­ ÀÚ½ÅÀÌ ¾ø´Âµ¥..
2011/06/10  
profreez Ç÷¡±×¸¦ Çϳª µÎ¼¼¿ä.
while(1)
{ switch() ...
} ºÎºÐÀ»

bool bQuit = false;
while(bQuit == false)
{
switch(.)
{
case 5: // Á¾·á.
bQuit = true;
break;
}
}
2011/06/11  
ksbgenius º»¹®ÀÇ case¹®À» ¼öÁ¤ÇÏ¿©¼­ »óÀ§ ¸Þ´º·Î °¡´Â ¹æ¹ýÀº ¾ø³ª¿ä...? 2011/06/11  
prosthetics ¸Þ´º Ãâ·ÂÇÏ´Â ÇÔ¼ö ¾È¿¡´Ù ³ÖÀ¸½Ã°í
¸ÞÀÎ ¸Þ´º¸¦ Á¦¿ÜÇÑ ¸ðµç¸Þ´º¿¡¼­ "Á¾·á" ºÎºÐ¿¡ return 0; ´ë½Å break;¸¦ ³ÖÀ¸½Ã¸é µË´Ï´Ù.
defaultÀÇ °æ¿ì continue;¸¦ ³Ö¾î¼­ ´Ù½Ã while¹® ¾ÈÀ¸·Î µ¹¾Æ°¡°Ô ÇÕ´Ï´Ù.
Áú¹®ÀÚ´ÔÀÇ °æ¿ì break;Çϳª¸¦ À߸ø ³ÖÀ¸¼Å¼­ ÁÖ¼®Ã³¸® Çß½À´Ï´Ù.

¾Æ·¡´Â mainÇÔ¼ö ºÎºÐÀÔ´Ï´Ù.

int main(void)
{
int menu;
ScoreManager sm;

while(1) //Àüü
{
sm.ShowMenu();
cout << "¸Þ´º¼±Åà : ";
cin >> menu;

switch(menu)//Àüü ¸Þ´º
{
case 1 : //Çлç

int menu1 ;

while(1) //Çлç
{
sm.CollegeGraduate();
cout << "¸Þ´º¼±Åà : ";
cin >> menu1;
switch(menu1)//Çлç¸Þ´º
{
case 1 : //ÇÐÀû
int menu2;
while(1)//ÇÐÀû¸Þ´º
{
sm.DataManagement();
cout << "¸Þ´º¼±Åà : ";
cin >> menu2;

switch(menu2)
{
case 1:
sm.EditPersonalInformation();
break;
case 2:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;


case 2:

int menu3;
while(1)
{
sm.Eclass();
cout << "¸Þ´º¼±Åà : ";
cin >> menu3;
switch(menu3)
{
case 1:
sm.StudentMainScreen();
break;
case 2:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 3:

int menu4;
while(1)
{
sm.CourseManagement();
cout << "¸Þ´º¼±Åà : ";
cin >> menu4;
switch(menu4)
{
case 1:
sm.CourseSubjectView();
break;
case 2:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 4:

int menu5;
while(1)
{
sm.Grademanagement();
cout << "¸Þ´º¼±Åà : ";
cin >> menu5;
switch(menu5)
{
case 1:
sm.InputScore();
break;
case 2:
sm.CumulativeGradeReview();
break;
case 3:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 5:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 2:

int menu6;
while(1)
{
sm.ManagementConsult();
cout << "¸Þ´º¼±Åà : ";
cin >> menu6;
switch(menu6)
{
case 1:
sm.ConsultationRequest();
break;
case 2:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 3:

int menu7;
while(1)
{
sm.Mileage();
cout << "¸Þ´º¼±Åà : ";
cin >> menu7;
switch(menu7)
{
case 1:
sm.PointAcquisition();
break;
case 2:
break;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
break;
}
break;

case 4:
return 0;
default:
cout <<"À߸ø ÀÔ·Â Çϼ̽À´Ï´Ù." << endl;
continue;
}
//break;
}
return 0;
}
2011/06/11  
prosthetics Ãß°¡·Î ¸»¾¸µå¸®°í ½ÍÀº°ÍÀº mainÇÔ¼ö¾È¿¡´Ù°¡ Àú·¸°Ô ±ä ÄÚµå ³ÖÁö ¸¶¼¼¿ä.

¶ÇÇÑ ¸Þ´º È£ÃâÇÒ¶§¸¶´Ù È­¸éÀ» Áö¿ì½Ã¸é ±ò²ûÇÑ ÇÁ·Î±×·¥ÀÌ µË´Ï´Ù.
2011/06/11  
ksbgenius °¨»çÇÕ´Ï´Ù. ¤¾¤¾ 2011/06/11