C++ Programming Ch.9 Exercise 2 Solution

Problem: The following is an abstract class Converter that converts units. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Converter { protected: double ratio; virtual double convert(double src)=0; // src๋ฅผ ๋‹ค๋ฅธ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. virtual string getSourceString()=0; // src ๋‹จ์œ„ ๋ช…์นญ virtual string getDestString()=0; // dest ๋‹จ์œ„ ๋ช…์นญ public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout << getSourceString() << "์„ " << getDestString() << "๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. "; cout << getSourceString() << "์„ ์ž…๋ ฅํ•˜์„ธ์š”>> "; cin >> src; cout << "๋ณ€ํ™˜ ๊ฒฐ๊ณผ : " << convert(src) << getDestString() << endl; } }; Write a km๋ฅผ mile(๋งˆ์ผ)๋กœ ๋ณ€ํ™˜ํ•˜๋Š” KmToMile class that inherits from the Converter class. The main() function and execution result are as follows. ...

November 20, 2019 ยท 2 min ยท Sobamemil

C++ Programming Ch.9 Exercise 1 Solution

Problem: The following is an abstract class Converter that converts units. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include using namespace std; class Converter { protected: double ratio; virtual double convert(double src)=0; // src๋ฅผ ๋‹ค๋ฅธ ๋‹จ์œ„๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค. virtual string getSourceString()=0; // src ๋‹จ์œ„ ๋ช…์นญ virtual string getDestString()=0; // dest ๋‹จ์œ„ ๋ช…์นญ public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout << getSourceString() << "์„ " << getDestString() << "๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. "; cout << getSourceString() << "์„ ์ž…๋ ฅํ•˜์„ธ์š”>> "; cin >> src; cout << "๋ณ€ํ™˜ ๊ฒฐ๊ณผ : " << convert(src) << getDestString() << endl; } }; Write a ๋‹ฌ๋Ÿฌ๋ฅผ ์›ํ™”๋กœ ํ™˜์‚ฐํ•˜๋Š” WonToDollar class that inherits from the Converter class. The main() function and execution result are as follows. ...

November 20, 2019 ยท 2 min ยท Sobamemil