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 6 Solution

Problem: 다음과 같이 정수, 제곱, 제곱근의 값을 형식에 맞추어 출력하는 프로그램을 작성하라. 필드의 간격은 총 15칸이고 제곱근의 유효 숫자는 총 3자리로 한다. 빈칸은 모두 underline(_) 문자로 삽입한다. Execution Result: Objective & Hints: cout으로 포맷 출력 응용 연습 제곱근을 구하려면 헤더 파일을 include 하고 sqrt(double x) 함수를 호출하면 됩니다. 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 #include #include #include using namespace std; void showNumber(const double &num){ cout << setw(15) << setfill('_') << num; } void showSqrt(const double &num){ cout << setprecision(3) << setw(15) << setfill('_') << sqrt(num) << endl; } int main() { cout.setf(ios::left); cout << setw(15) << "Number"; cout << setw(15) << "Square"; cout << setw(15) << "Square Root" << endl; for(double i=0; i<=45; i+=5){ cout.precision(4); showNumber(i); // Number 출력 showNumber(i*i); // Square 출력 showSqrt(i); // Square Root 출력 } } Explanation: ...

March 27, 2020 · 2 min · Sobamemil