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

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

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