๐Ÿ’ป Dev & CSC++ Programming

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