💻 개발 & CSC++ 프로그래밍

명품 C++ programming 실습 문제 10장 14번

문제 : 암호 관리 응용프로그램을 map을 이용하여 작성하라. 실행 과정은 다음과 같다. 실행 결과 : 목적 및 힌트 : map 컨테이너에 삽입 및 조회 응용 이름과 점수를 쌍으로 저장할 맵 컨테이너로 map<string, string>을 이용하면 됩니다. 아래 링크에 있는 실습 문제 10장 13번을 참고하세요. 코드 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include #include using namespace std; void insert(map<string, string> &pwManager){ string name, pw; cout << "이름 암호>> "; cin >> name >> pw; pwManager.insert(make_pair(name, pw)); } void checkNamePw(map<string, string> &pwManager){ string name, pw; cout << "이름? "; cin >> name; while(true){ cout << "암호? "; cin >> pw; if(pwManager[name] == pw){ cout << "통과!!\n"; break; } else cout << "실패~~\n"; // 틀리면 출력 후 다시 암호 질문 } } int main() { map<string, string> pwManager; cout << "***** 암호 관리 프로그램 WHO를 시작합니다 *****\n"; while(true){ cout << "삽입:1, 검사:2, 종료3>> "; int n; cin >> n; switch(n){ case 1: insert(pwManager); break; case 2: checkNamePw(pwManager); break; case 3: cout << "프로그램을 종료합니다..."; return 0; } } } 설명 : ...

2020년 3월 11일 · 2 분 · Sobamemil