C++ Programming Ch.3 Exercise 6 Solution

Problem: ๋ฌธ์ œ 5๋ฒˆ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ง์ˆ˜ ์ •์ˆ˜๋งŒ ๋žœ๋คํ•˜๊ฒŒ ๋ฐœ์ƒ์‹œํ‚ค๋Š” EvenRandom ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๊ณ  EvenRandom ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ 10๊ฐœ์˜ ์ง์ˆ˜๋ฅผ ๋žœ๋คํ•˜๊ฒŒ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์™„์„ฑํ•˜๋ผ. 0๋„ ์ง์ˆ˜๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค. Objective & Hints: ํด๋ž˜์Šค ์ž‘์„ฑ ๋ฐ ํด๋ž˜์Šค ํ™œ์šฉ Execution Result: 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 #include #include #include using namespace std; class EvenRandom{ public: EvenRandom(); int next(); int nextInRange(int a, int b); }; EvenRandom::EvenRandom(){ srand((unsigned)time(0)); } int EvenRandom::next() { int ran = rand(); if(ran%2 == 0) return ran; else return --ran; } int EvenRandom::nextInRange(int a, int b){ int ran = rand()%(b-a+1) + a; if(ran%2 == 0) return ran; else return --ran; } int main(){ EvenRandom r; cout << "-- 0์—์„œ " << RAND_MAX << "๊นŒ์ง€์˜ ๋žœ๋ค ์ •์ˆ˜ 10 ๊ฐœ--" << endl; for(int i=0; i<10; i++) { int n = r.next(); // 0์—์„œ RAND_MAX(32767) ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ •์ˆ˜ cout << n << ' '; } cout << endl << endl << "-- 2์—์„œ " << "10 ๊นŒ์ง€์˜ ๋žœ๋ค ์ •์ˆ˜ 10 ๊ฐœ --" << endl; for(int i=0; i<10; i++) { int n = r.nextInRange(2,10); // 2์—์„œ 10 ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ •์ˆ˜ cout << n << ' '; } cout << endl; } Explanation: ...

March 3, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.3 Exercise 5 Solution

Problem: ๋žœ๋ค ์ˆ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” Random ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์ž. Random ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ ๋žœ๋ค ํ•œ ์ •์ˆ˜๋ฅผ 10๊ฐœ ์ถœ๋ ฅํ•˜๋Š” ์‚ฌ๋ก€๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. Random ํด๋ž˜์Šค๊ฐ€ ์ƒ์„ฑ์ž, next(), nextInRange()์˜ 3๊ฐœ์˜ ๋ฉค๋ฒ„ ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ง€๋„๋ก ์ž‘์„ฑํ•˜๊ณ  main() ํ•จ์ˆ˜์™€ ํ•ฉ์ณ ํ•˜๋‚˜์˜ cpp ํŒŒ์ผ์— ๊ตฌํ˜„ํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 int main() { Random r; cout << "-- 0์—์„œ " << RAND_MAX << "๊นŒ์ง€์˜ ๋žœ๋ค ์ •์ˆ˜ 10 ๊ฐœ--" << endl; for(int i=0; i<10; i++) { int n = r.next(); // 0์—์„œ RAND_MAX(32767) ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ •์ˆ˜ cout << n << ' '; } cout << endl << endl << "-- 2์—์„œ " << "4 ๊นŒ์ง€์˜ ๋žœ๋ค ์ •์ˆ˜ 10 ๊ฐœ --" << endl; for(int i=0; i<10; i++) { int n = r.nextInRange(2,4); // 2์—์„œ 4 ์‚ฌ์ด์˜ ๋žœ๋คํ•œ ์ •์ˆ˜ cout << n << ' '; } cout << endl; } Objective & Hints: ...

March 3, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.3 Exercise 4 Solution

Problem: CoffeeMachine ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž. main() ํ•จ์ˆ˜์™€ Execution Result๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™๋„๋ก CoffeeMachine ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๋ผ. ์—์Šคํ”„๋ ˆ์†Œ ํ•œ ์ž”์—๋Š” ์ปคํ”ผ์™€ ๋ฌผ์ด ๊ฐ๊ฐ 1์”ฉ ์†Œ๋น„๋˜๊ณ , ์•„๋ฉ”๋ฆฌ์นด๋…ธ์˜ ๊ฒฝ์šฐ ์ปคํ”ผ๋Š” 1, ๋ฌผ์€ 2๊ฐ€ ์†Œ๋น„๋˜๊ณ , ์„คํƒ• ์ปคํ”ผ๋Š” ์ปคํ”ผ 1, ๋ฌผ 2, ์„คํƒ• 1์ด ์†Œ๋น„๋œ๋‹ค. CoffeeMachine ํด๋ž˜์Šค์—๋Š” ์–ด๋–ค ๋ฉค๋ฒ„ ๋ณ€์ˆ˜์™€ ์–ด๋–ค ๋ฉค๋ฒ„ ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•œ์ง€ ์ž˜ ํŒ๋‹จํ•˜์—ฌ ์ž‘์„ฑํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include using namespace std; int main() { CoffeeMachine java(5, 10, 3); // ์ปคํ”ผ๋Ÿ‰:5, ๋ฌผ๋Ÿ‰:10, ์„คํƒ•:6 ์œผ๋กœ ์ดˆ๊ธฐํ™” java.drinkEspresso(); // ์ปคํ”ผ 1, ๋ฌผ 1 ์†Œ๋น„ java.show(); // ํ˜„์žฌ ์ปคํ”ผ ๋จธ์‹ ์˜ ์ƒํƒœ ์ถœ๋ ฅ java.drinkAmericano(); // ์ปคํ”ผ 1, ๋ฌผ 2 ์†Œ๋น„ java.show(); // ํ˜„์žฌ ์ปคํ”ผ ๋จธ์‹ ์˜ ์ƒํƒœ ์ถœ๋ ฅ java.drinkSugarCoffee(); // ์ปคํ”ผ 1, ๋ฌผ 2, ์„คํƒ• 1 ์†Œ๋น„ java.show(); // ํ˜„์žฌ ์ปคํ”ผ ๋จธ์‹ ์˜ ์ƒํƒœ ์ถœ๋ ฅ java.fill(); // ์ปคํ”ผ 10, ๋ฌผ 10, ์„คํƒ• 10 ์œผ๋กœ ์ฑ„์šฐ๊ธฐ java.show(); // ํ˜„์žฌ ์ปคํ”ผ ๋จธ์‹ ์˜ ์ƒํƒœ ์ถœ๋ ฅ Execution Result: ...

March 3, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.3 Exercise 3 Solution

Problem: ์€ํ–‰์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด, ์€ํ–‰ ๊ณ„์ขŒ ํ•˜๋‚˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ํด๋ž˜์Šค Account๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๊ณ„์ขŒ ์ •๋ณด๋Š” ๊ณ„์ขŒ์˜ ์ฃผ์ธ, ๊ณ„์ขŒ ๋ฒˆํ˜ธ, ์ž”์•ก์„ ๋‚˜ํƒ€๋‚ด๋Š” 3 ๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค. main() ํ•จ์ˆ˜์˜ ์‹คํ–‰๊ณผ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™๋„๋ก Account ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 10 #include using namespace std; int main() { Account a("Kitae", 1, 5000); // id 1๋ฒˆ, ์ž”์•ก 5000์›, ์ด๋ฆ„์ด Kitae์ธ ๊ณ„์ขŒ ์„ฑ a.deposit(50000); // 50000์› ์ €๊ธˆ cout << a.getOwner() << "์˜ ์ž”์•ก์€ " << a.inquiry() << endl; int money = a.withdraw(20000); // 20000์› ์ถœ๊ธˆ. withdraw()๋Š” ์ถœ๊ธˆํ•œ ์‹ค์ œ ๊ธˆ์•ก ๋ฆฌํ„ด cout << a.getOwner() << "์˜ ์ž”์•ก์€ " << a.inquiry() << endl; } Execution Result: ...

March 2, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.3 Exercise 2 Solution

Problem: ๋‚ ์งœ๋ฅผ ๋‹ค๋ฃจ๋Š” Date ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค. Date๋ฅผ ์ด์šฉํ•˜๋Š” main()๊ณผ Execution Result๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. ํด๋ž˜์Šค Date๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์•„๋ž˜ ํ”„๋กœ๊ทธ๋žจ์— ์ถ”๊ฐ€ํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 #include using namespace std; int main() { Date virth(2014, 3, 20); Date independenceDay("1945/8/15"); independenceDay.show(); cout << birth.getYear() << ',' << birth.getMonth() << ',' << birth.getDay() << endl; } Execution Result: Objective & Hints: 2๊ฐœ์˜ ์ƒ์„ฑ์ž์™€ ์—ฌ๋Ÿฌ ๋ฉค๋ฒ„๋ฅผ ๊ฐ€์ง„ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ ...

March 2, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.3 Exercise 1 Solution

Problem: ์•„๋ž˜ main()์˜ Execution Result๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™๋„๋ก Tower ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๋ผ. 1 2 3 4 5 6 7 8 9 #include using namespace std; int main() { Tower myTower; // 1 ๋ฏธํ„ฐ Tower seoulTower(100); // 100 ๋ฏธํ„ฐ cout << "๋†’์ด๋Š” " << myTower.getHeight() << "๋ฏธํ„ฐ" << endl; cout << "๋†’์ด๋Š” " << seoulTower.getHeight() << "๋ฏธํ„ฐ" << endl; } Objective & Hints: 2๊ฐœ์˜ ์ƒ์„ฑ์ž์™€ ์—ฌ๋Ÿฌ ๋ฉค๋ฒ„๋ฅผ ๊ฐ€์ง„ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ ...

March 2, 2020 ยท 1 min ยท Sobamemil

C++ Programming Ch.2 Exercise 16 Solution

Problem: ์˜๋ฌธ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ์•ŒํŒŒ๋ฒณ ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๊ทธ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ๋Œ€๋ฌธ์ž๋Š” ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ์ง‘๊ณ„ํ•˜๋ฉฐ, ํ…์ŠคํŠธ ์ž…๋ ฅ์˜ ๋์€ ';' ๋ฌธ์ž๋กœ ํ•œ๋‹ค. Objective & Hints: ๋ฌธ์ž์—ด ์ฝ๊ธฐ, C++ ํ”„๋กœ๊ทธ๋žจ ์ข…ํ•ฉ ์‘์šฉ Input File: ์ž…๋ ฅํ•  ํ…์ŠคํŠธ ํŒŒ์ผ์„ ์ฒจ๋ถ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค. [2-16.txt 0.00MB](https://blog.kakaocdn.net/dna/EsAHK/btqChFfPBnw/AAAAAAAAAAAAAAAAAAAAAOhcwRebixdRiSrFB2r5c8Z4mBZDeCt4ibUUEp2n5aCw/2-16.txt?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&expires=1788188399&allow_ip=&allow_referer=&signature=PEoHUr5ktP9MyFLvskuQj0jS1Q8%3D&attach=1&knm=tfile.txt) Execution Result: 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 #include #include using namespace std; int main() { int tot=0; // ์ด ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜ int alpha[27]={0}; // ๊ฐ๊ฐ์˜ ์•ŒํŒŒ๋ฒณ์„ ๋‚˜ํƒ€๋ƒ„ char text[10000]; // text๋ฅผ ์ €์žฅํ•  ๋ฐฐ์—ด cout << "์˜๋ฌธ ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”. ํžˆ์Šคํ† ๊ทธ๋žจ์„ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค.\nํ…์ŠคํŠธ์˜ ๋์€ ; ์ž…๋‹ˆ๋‹ค. 10000๊ฐœ๊นŒ์ง€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.\n"; cin.getline(text,10000,';'); // ์ตœ๋Œ€ 10,000๊ฐœ์˜ ์˜๋ฌธ ํ…์ŠคํŠธ๋ฅผ ';'์ „๊นŒ์ง€ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค for (int i = 0; i<strlen(text); i++) { // text[0]๋ถ€ํ„ฐ text์˜ ๋๊นŒ์ง€ if (isalpha(text[i])) { // text[i]๊ฐ€ ์•ŒํŒŒ๋ฒณ์ด๋ฉด ์ฐธ if(text[i]<91) text[i] = tolower(text[i]); // text[i]๊ฐ€ ๋Œ€๋ฌธ์ž์ด๋ฉด ์†Œ๋ฌธ์ž๋กœ ๋ณ€๊ฒฝ tot++; alpha[text[i] - 97]++; // ๊ฐ๊ฐ์˜ ์•ŒํŒŒ๋ฒณ์ด ๋ช‡๊ฐœ์ธ์ง€ ์นด์šดํŠธ } } cout << "์ด ์•ŒํŒŒ๋ฒณ ์ˆ˜ " << tot << endl << endl; for (int i = 0; i < 26; ++i) { // ์•ŒํŒŒ๋ฒณ์˜ ์†Œ๋ฌธ์ž ์ด ๊ฐœ์ˆ˜๋Š” 26๊ฐœ (a~z) cout << (char)(i+'a') << "(" << alpha[i] << ")"; // a๋ถ€ํ„ฐ z๊นŒ์ง€ ์ถœ๋ ฅ ํ›„ ๊ฐ (์•ŒํŒŒ๋ฒณ์˜ ๊ฐœ์ˆ˜) ์ถœ๋ ฅ cout << "\t: "; // ํฌ๋งท์„ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ํƒญ๊ณผ ":" ์ถœ๋ ฅ for (int j = 1; j <= alpha[i]; j++) // ๊ฐ ์•ŒํŒŒ๋ฒณ์˜ ๊ฐœ์ˆ˜๋งŒํผ "*" ์ถœ๋ ฅ cout << "*"; cout << endl; } } Explanation: ...

February 28, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.2 Exercise 15 Solution

Problem: ๋ง์…ˆ(+), ๋บ„์…ˆ(-), ๊ณฑ์…ˆ(*), ๋‚˜๋ˆ—์…ˆ(/), ๋‚˜๋จธ์ง€(%)์˜ ์ •์ˆ˜ 5์ฒ™ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. ์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ์ž…๋ ฅ๋œ๋‹ค. ์ •์ˆ˜์™€ ์—ฐ์‚ฐ์ž๋Š” ํ•˜๋‚˜์˜ ๋นˆ์นธ์œผ๋กœ ๋ถ„๋ฆฌ๋œ๋‹ค. Objective & Hints: ๊ณต๋ฐฑ์„ ํฌํ•จํ•˜๋Š” ๋ฌธ์ž์—ด ์ฝ๊ธฐ, C++ ํ”„๋กœ๊ทธ๋žจ ์ข…ํ•ฉ ์‘์šฉ ํ•œ ์ค„์„ ๋ฌธ์ž์—ด๋กœ ์ฝ๊ณ , ๊ณต๋ฐฑ ๋ฌธ์ž๋ฅผ ์ฐพ์•„ ์—ฐ์‚ฐ์ž์™€ ๋‘ ๊ฐœ์˜ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ๊ตฌ๋ถ„ํ•œ ํ›„, ๊ณ„์‚ฐํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์„ ์ •์ˆ˜๋กœ ๋ฐ”๊ฟ€ ๋•Œ atoi() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด atoi("34") = 34 ์ž…๋‹ˆ๋‹ค. Execution Result: 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 #include #include #include using namespace std; int main(){ char sic[100]; char *symbol; int front,rear; while(true){ cout << "? "; cin.getline(sic,100); front = atoi(strtok(sic, " ")); symbol = strtok(NULL, " "); rear = atoi(strtok(NULL, " ")); if(*symbol == '+'){ cout << front << " + " << rear << " = " << front+rear << endl; } else if(*symbol == '-'){ cout << front << " - " << rear << " = " << front-rear << endl; } else if(*symbol == '*'){ cout << front << " * " << rear << " = " << front*rear << endl; } else if(*symbol == '/'){ cout << front << " / " << rear << " = " << front/rear << endl; } else if(*symbol == '%'){ cout << front << " % " << rear << " = " << front%rear << endl; } } return 0; } Explanation: ...

February 28, 2020 ยท 2 min ยท Sobamemil

C++ Programming Ch.2 Exercise 14 Solution

Problem: ์ปคํ”ผ๋ฅผ ์ฃผ๋ฌธํ•˜๋Š” ๊ฐ„๋‹จํ•œ C++ ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด์ž. ์ปคํ”ผ ์ข…๋ฅ˜๋Š” "์—์Šคํ”„๋ ˆ์†Œ", "์•„๋ฉ”๋ฆฌ์นด๋…ธ", "์นดํ‘ธ์น˜๋…ธ"์˜ 3๊ฐ€์ง€์ด๋ฉฐ ๊ฐ€๊ฒฉ์€ ๊ฐ๊ฐ 2000์›, 2300์›, 2500์›์ด๋‹ค. ํ•˜๋ฃจ์— 20000์› ์ด์ƒ ๋ฒŒ๊ฒŒ ๋˜๋ฉด ์นดํŽ˜๋ฅผ ๋‹ซ๋Š”๋‹ค. Execution Result์™€ ๊ฐ™์ด ์ž‘๋™ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜๋ผ. Objective & Hints: C++ ํ”„๋กœ๊ทธ๋žจ ๊ตฌ์„ฑ. cin, strcmp() ํ™œ์šฉ ์ข…ํ•ฉ ์—ฐ์Šต char coffee[100]; int num; cin >> coffee >> num; ์œผ๋กœ ์ปคํ”ผ ์ด๋ฆ„๊ณผ ์ž” ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ปคํ”ผ๋Š” if(strcmp(coffee, "์—์Šคํ”„๋ ˆ์†Œ") == 0 )๊ณผ ๊ฐ™์ด ๋น„๊ตํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. Execution Result: ...

February 28, 2020 ยท 1 min ยท Sobamemil

C++ Programming Ch.2 Exercise 13 Solution

Problem: ์ค‘์‹๋‹น์˜ ์ฃผ๋ฌธ ๊ณผ์ •์„ C++ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์ž‘์„ฑํ•ด๋ณด์ž. ๋‹ค์Œ Execution Result์™€ ๊ฐ™์ด ๋ฉ”๋‰ด์™€ ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  ์ด๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค. ์ž˜๋ชป๋œ ์ž…๋ ฅ์„ ๊ฐ€๋ ค๋‚ด๋Š” ๋ถ€๋ถ„๋„ ์ฝ”๋“œ์— ์ถ”๊ฐ€ํ•˜๋ผ. Objective & Hints: C++ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ๊ตฌ์„ฑ, ํ‚ค ์ž…๋ ฅ ๋“ฑ ์ข…ํ•ฉ ์—ฐ์Šต Execution Result: 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 #include using namespace std; int main() { int num,tot; cout << "***** ์Šน๋ฆฌ์žฅ์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค. ***** \n"; while(true){ cout << "์งฌ๋ฝ•:1, ์งœ์žฅ:2, ๊ตฐ๋งŒ๋‘:3, ์ข…๋ฃŒ:4>> "; cin >> num; if(num == 4) { cout << "์˜ค๋Š˜ ์˜์—…์€ ๋๋‚ฌ์Šต๋‹ˆ๋‹ค."; break; } if(num > 4) { cout << "๋‹ค์‹œ ์ฃผ๋ฌธํ•˜์„ธ์š”!!\n"; continue; } cout << "๋ช‡์ธ๋ถ„?"; cin >> tot; if(num==1) cout << "์งฌ๋ฝ• " << tot << "์ธ๋ถ„ ๋‚˜์™”์Šต๋‹ˆ๋‹ค\n"; else if(num==2) cout << "์งœ์žฅ " << tot << "์ธ๋ถ„ ๋‚˜์™”์Šต๋‹ˆ๋‹ค\n"; else if(num==3) cout << "๊ตฐ๋งŒ๋‘ " << tot << "์ธ๋ถ„ ๋‚˜์™”์Šต๋‹ˆ๋‹ค\n"; } return 0; } Explanation: ...

February 28, 2020 ยท 1 min ยท Sobamemil