C++ Programming Ch.11 Exercise 7 Solution
Problem: 0์์ 127๊น์ง ASCII ์ฝ๋์ ํด๋น ๋ฌธ์๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ผ. ํ๋ฉด์ ์ถ๋ ฅ๊ฐ๋ฅํ์ง ์๋ ASCII ์ฝ๋๋ '.'์ผ๋ก ์ถ๋ ฅํ๋ผ. Execution Result: Objective & Hints: cout์ผ๋ก ํฌ๋งท ์ถ๋ ฅ ์์ฉ ์ฐ์ต ๋ฌธ์๊ฐ ์ถ๋ ฅ ๊ฐ๋ฅํ์ง ์๊ธฐ ์ํด bool isprint(int c); ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค. ๋งค๊ฐ ๋ณ์ c๋ ๋ฌธ์ ์ฝ๋ ๊ฐ์ด๊ณ , ํค๋ ํ์ผ์ include ํด์ผํฉ๋๋ค. 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 #include using namespace std; void showDec(int d) { // 10์ง์ ์ถ๋ ฅ cout << setw(10) << dec << d; } void showHexa(int h) { // 16์ง์ ์ถ๋ ฅ cout << setw(10) << hex << h; } void showChar(int c) { // ASCII ์ถ๋ ฅ int i=0; if( (i = isprint(c)) != 0) // ์ถ๋ ฅ ๊ฐ๋ฅํ ๋ฌธ์์ธ์ง ํ์ธ cout << setw(10) << (char)c; else // ์ถ๋ ฅ ๋ถ๊ฐ๋ฅํ ๋ฌธ์์ด๋ฉด "." ์ถ๋ ฅ cout << setw(10) << "."; } void print() { for(int i=0; i<4; i++){ cout << setw(10) << "dec"; cout << setw(10) << "hexa"; cout << setw(10) << "char"; } cout << endl; for(int i=0; i<4; i++){ cout << setw(10) << "---"; cout << setw(10) << "----"; cout << setw(10) << "----"; } cout << endl; for(int i=0; i<128; i++){ // 127๋ฒ ๋ฐ๋ณตํ์ฌ dec, hexa, ASCII ์ถ๋ ฅ if(i%4==0 && i!=0) cout << endl; showDec(i); showHexa(i); showChar(i); } } int main() { cout.setf(ios::left); // ์ถ๋ ฅ ํฌ๋งท ์ผ์ชฝ ์ ๋ ฌ print(); } Explanation: ...