Problem:
๋ค์ ์ถ์ ํด๋์ค LoopAdder๊ฐ ์๋ค.
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 class LoopAdder { // ์ถ์ ํด๋์ค string name; // ๋ฃจํ์ ์ด๋ฆ int x, y, sum; // x์์ y๊น์ง์ ํฉ์ sum void read(); // x, y ๊ฐ์ ์ฝ์ด ๋ค์ด๋ ํจ์ void write(); // sum์ ์ถ๋ ฅํ๋ ํจ์ protected: LoopAdder(string name="") { // ๋ฃจํ์ ์ด๋ฆ์ ๋ฐ๋๋ค. ์ด๊น๊ฐ์ "" this->name = name; } int getX() { return x; } int getY() { return y; } virtual int calculate() = 0; // ์์ ๊ฐ์ ํจ์. ๋ฃจํ๋ฅผ ๋๋ฉฐ ํฉ์ ๊ตฌํ๋ ํจ์ public: void run(); // ์ฐ์ฐ์ ์งํํ๋ ํจ์ }; void LoopAdder::read() { // x, y ์
๋ ฅ cout << name << ":" << endl; cout << "์ฒ์ ์์์ ๋๋ฒ์งธ ์๊น์ง ๋ํ๋ค. ๋ ์๋ฅผ ์
๋ ฅํ์ธ์ >> "; cin >> x >> y; } void LoopAdder::write() { // ๊ฒฐ๊ณผ sum ์ถ๋ ฅ cout << x << "์์ " << y << "๊น์ง์ ํฉ = " << sum << " ์
๋๋ค" << endl; } void LoopAdder::run() { read(); // x, y๋ฅผ ์ฝ๋๋ค sum = calculate(); // ๋ฃจํ๋ฅผ ๋๋ฉด์ ๊ณ์ฐํ๋ค. write(); // ๊ฒฐ๊ณผ sum์ ์ถ๋ ฅํ๋ค. } Write a ๋ค์ main() ํจ์์ Execution Result์ฒ๋ผ ๋๋๋ก ForLoopAdder class that inherits from the LoopAdder class. ForLoopAdder ํด๋์ค์ calculate() ํจ์๋ for ๋ฌธ์ ์ด์ฉํ์ฌ ํฉ์ ๊ตฌํ๋ค.
...