๐Ÿ’ป Dev & CSC++ Programming

C++ Programming Ch.11 Exercise 11 Solution

Problem: ๋‹ค์Œ์€ ํ”„๋กœ๊ทธ๋žจ๊ณผ Execution Result๋ฅผ ๋ณด์—ฌ์ค€๋‹ค. pos ์กฐ์ž‘์ž๋ฅผ ์ž‘์„ฑํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 #include using namespace std; int main() { int x, y; cin >> pos >> x; cin >> pos >> y; cout << x << ',' << y << endl; } Execution Result: Objective & Hints: ์กฐ์ž‘์ž ์ž‘์„ฑ ์—ฐ์Šต Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include using namespace std; istream& pos (istream& ins) { // pos ์กฐ์ž‘์ž cout << "์œ„์น˜๋Š”? "; return ins; } int main() { int x, y; cin >> pos >> x; cin >> pos >> y; cout << x << ',' << y << endl; }

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

C++ Programming Ch.11 Exercise 3 Solution

Problem: ํ•œ ์ค„์— '์˜์–ด๋ฌธ์žฅ;ํ•œ๊ธ€๋ฌธ์ž' ํ˜•์‹์œผ๋กœ ํ‚ค ์ž…๋ ฅ๋  ๋•Œ, cin.ignore()๋ฅผ ์ด์šฉํ•˜์—ฌ ';' ์ดํ›„์— ์ž…๋ ฅ๋œ ๋ฌธ์ž์—ด์„ ํ™”๋ฉด์— ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ์•„๋ž˜์—์„œ ^Z(ctrl-z) ํ‚ค๋Š” ์ž…๋ ฅ ์ข…๋ฃŒ๋Š” ๋‚˜ํƒ€๋‚ด๋Š” ํ‚ค์ด๋ฉฐ, cin.get()์€ EOF๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค. Execution Result: Objective & Hints: cin.get(), EOF, cin.ignore() ํ™œ์šฉ Code: 1 2 3 4 5 6 7 8 9 10 11 12 #include using namespace std; int main() { int ch; cin.ignore(100, ';'); // ์˜์–ด ๋ฌธ์žฅ์ด ์ตœ๋Œ€ 99๊ฐœ์˜ ๋ฌธ์ž๋กœ ์ž…๋ ฅ๋œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. while((ch=cin.get()) != EOF) { cout.put(ch); if(ch == '\n') cin.ignore(100, ';'); // ์˜์–ด ๋ฌธ์žฅ์ด ์ตœ๋Œ€ 99๊ฐœ์˜ ๋ฌธ์ž๋กœ ์ž…๋ ฅ๋œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. } } Explanation: ...

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

C++ Programming Ch.11 Exercise 2 Solution

Problem: istream& get(char& ch) ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•œ ๋ผ์ธ์„ ์ฝ๊ณ  ๋นˆ์นธ(' ')์ด ๋ช‡ ๊ฐœ์ธ์ง€ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. Execution Result: Objective & Hints: cin์œผ๋กœ ํ‚ค ์ž…๋ ฅ ์—ฐ์Šต Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include using namespace std; int main() { char ch; int cnt; while(true){ cin.get(ch); // ํ‚ค๋ฅผ ch์— ์ฝ์–ด์˜ด if(cin.eof()) // EOF ๋ฌธ์ž ์ฆ‰ ctrl-z ํ‚ค๊ฐ€ ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ, ์ฝ๊ธฐ ์ข…๋ฃŒ break; if(ch == '\n') // ํ‚ค๊ฐ€ ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ ์ฝ๊ธฐ ์ค‘๋‹จ break; else if(ch == ' ') cnt++; } cout << cnt; }

March 27, 2020 ยท 1 min ยท Sobamemil