|
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 : 5805 Date : 2011/06/10 03:49
|