๐Ÿ’ป Dev & CSC++ Programming

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: ...

April 2, 2020 ยท 2 min ยท Sobamemil