๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.11 Exercise 10 Solution

Problem: ๋‹ค์Œ์€ ํ”„๋กœ๊ทธ๋žจ๊ณผ Execution Result๋ฅผ ๋ณด์—ฌ์ค€๋‹ค. prompt ์กฐ์ž‘์ž๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์„ ์™„์„ฑํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include #include using namespace std; int main() { string password; while(true) { cin >> prompt >> password; if(password == "C++") { cout << "login success!!" << endl; break; } else cout << "login fail. try again!!" << endl; } } Execution Result: ...

April 2, 2020 ยท 1 min ยท Sobamemil
๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.11 Exercise 9 Solution

Problem: ๋‹ค์Œ์€ Phone ํด๋ž˜์Šค์ด๋‹ค. 1 2 3 4 5 6 7 8 9 10 11 class Phone { // ์ „ํ™” ๋ฒˆํ˜ธ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ํด๋ž˜์Šค string name; string telnum; string address; public: Phone(string name="", string telnum="", string address="") { this->name = name; this->telnum = telnum; this->address = address; } }; Phone ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ์ž…์ถœ๋ ฅํ•˜๋Š” ์•„๋ž˜ ์ฝ”๋“œ์™€ Execution Result๋ฅผ ์ฐธ์กฐํ•˜์—ฌ <<, >> ์—ฐ์‚ฐ์ž๋ฅผ ์ž‘์„ฑํ•˜๊ณ  Phone ํด๋ž˜์Šค๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๋“ฑ ํ”„๋กœ๊ทธ๋žจ์„ ์™„์„ฑํ•˜๋ผ. 1 2 3 Phone girl, boy; cin >> girl >> boy; cout << girl << endl << boy << endl; Execution Result: ...

April 2, 2020 ยท 2 min ยท Sobamemil
๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.10 Exercise 15 Solution

Problem: vector๋ฅผ ์ด์šฉํ•˜์—ฌ ์•„๋ž˜ Circle ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ์‚ฝ์ž…ํ•˜๊ณ  ์‚ญ์ œํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ์‚ญ์ œ ์‹œ์—๋Š” ์ด๋ฆ„์ด ๊ฐ™์€ ๋ชจ๋“  ์›์„ ์‚ญ์ œํ•œ๋‹ค. 1 2 3 4 5 6 7 8 9 10 class Circle { string name; // ์ด๋ฆ„ int radius; // ๋ฐ˜์ง€๋ฆ„ public: Circle(int radius, string name) { this->radius = radius; this->name = name; } double getArea() { return 3.14*radius*radius; } string getName() { return name; } }; Execution Result: ...

March 11, 2020 ยท 2 min ยท Sobamemil
๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.10 Exercise 14 Solution

Problem: ์•”ํ˜ธ ๊ด€๋ฆฌ ์‘์šฉํ”„๋กœ๊ทธ๋žจ์„ map์„ ์ด์šฉํ•˜์—ฌ ์ž‘์„ฑํ•˜๋ผ. ์‹คํ–‰ ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. Execution Result: Objective & Hints: map ์ปจํ…Œ์ด๋„ˆ์— ์‚ฝ์ž… ๋ฐ ์กฐํšŒ ์‘์šฉ ์ด๋ฆ„๊ณผ ์ ์ˆ˜๋ฅผ ์Œ์œผ๋กœ ์ €์žฅํ•  ๋งต ์ปจํ…Œ์ด๋„ˆ๋กœ map<string, string>์„ ์ด์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๋งํฌ์— ์žˆ๋Š” Exercise Problem 10์žฅ 13๋ฒˆ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”. Code: 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; } } } Explanation: ...

March 11, 2020 ยท 2 min ยท Sobamemil