파일 입출력과 map 클래스를 활용하여 다음과 같은 데이터베이스를 만들어라.
11월 24일 오후 1시
#### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 1 <name> : <score> ---------------- jiyoo : 95 minho : 90 miok : 85 yoowon : 96 ---------------- #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 2 Enter name : minho Enter score : 100 minho already exists in the database. #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 1 <name> : <score> ---------------- jiyoo : 95 minho : 90 miok : 85 yoowon : 96 ---------------- #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 2 Enter name : cinamorole Enter score : 50 #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 1 <name> : <score> ---------------- jiyoo : 95 minho : 90 miok : 85 yoowon : 96 cinamorole : 50 ---------------- #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 3 Enter name : cinamon cinamon does not exist in the database. #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 3 Enter name : cinamorole #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 1 <name> : <score> ---------------- jiyoo : 95 minho : 90 miok : 85 yoowon : 96 ---------------- #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 4 Enter name : jiyoo jiyoo's score is 95 #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 4 Enter name : jiyoon jiyoon does not exist in the database. #### MENU #### 1. print all 2. insert data 3. remove data 4. search 5. quit Choose >> 5 Good Bye
다음 파일에서 class ScoreBook을 정의한 후, 전체 파일을 cpphw9-<학번>.cpp로 제출한다. 코드의 다른 부분은 건들지 말 것. (단 오류가 있으면 수정하고 수정한 내용을 적어서 제출)
#include <iostream> #include <fstream> #include <string> #include <map> using namespace std; class ScoreBook { ... // 스스로 정의할 것 public: ScoreBook( string filename ); void printall(); void insert( string name, string score ); void remove( string iname ); void search( string iname ); ... // 그 외 필요한 함수들 }; int getSelection() { cout << "#### MENU ####" << endl; cout << "1. print all" << endl; cout << "2. insert data" << endl; cout << "3. remove data" << endl; cout << "4. search" << endl; cout << "5. quit" << endl; cout << "Choose >> "; string line; getline( cin, line ); return stoi( line ); } string getName() { string name; cout << "Enter name : "; getline( cin, name ); return name; } string getScore() { string score; cout << "Enter score : "; getline( cin, score ); return score; } int main() { int selection; string name, score; ScoreBook sb("scorebook.txt"); while( (selection = getSelection()) ) { switch (selection) { case 1: sb.printall(); break; case 2: name = getName(); score = getScore(); sb.insert( name, score ); break; case 3: sb.remove( getName() ); break; case 4: sb.search( getName() ); break; case 5: cout << "Good bye" << endl; system("pause"); exit(1); default: continue; } } }