C++ Window Class: Elegant Code with English Comments for Setting Title and Size
#include\x20
class\x20Size\x20{ public: \x20\x20int\x20width,\x20height; \x20\x20Size(const\x20int&\x20width,\x20const\x20int&\x20height) \x20\x20\x20\x20:\x20width(width),\x20height(height)\x20{ \x20\x20\x20\x20 \x20\x20} };
class\x20Window\x20{ private: \x20\x20std::string\x20title; \x20\x20Size\x20windowSize;
public: \x20\x20Window()\x20{ \x20\x20} \x20\x20 \x20\x20//\x20Constructor\x20that\x20sets\x20the\x20window\x20size \x20\x20Window(const\x20Size&\x20size) \x20\x20\x20\x20:\x20windowSize(size)\x20{ \x20\x20\x20\x20SetWindowSize(size); \x20\x20} \x20\x20 \x20\x20//\x20Constructor\x20that\x20sets\x20the\x20window\x20title \x20\x20Window(const\x20std::string&\x20title) \x20\x20\x20\x20:\x20title(title)\x20{ \x20\x20\x20\x20SetWindowTitle(title); \x20\x20} \x20\x20 \x20\x20//\x20Constructor\x20that\x20sets\x20both\x20the\x20window\x20title\x20and\x20size \x20\x20Window(const\x20std::string&\x20title,\x20const\x20Size&\x20size) \x20\x20\x20\x20:\x20title(title),\x20windowSize(size)\x20{ \x20\x20\x20\x20SetWindowTitle(title); \x20\x20\x20\x20SetWindowSize(size); \x20\x20}
\x20\x20//\x20Method\x20to\x20set\x20the\x20window\x20title \x20\x20void\x20SetWindowTitle(const\x20std::string&\x20newTitle)\x20{ \x20\x20\x20\x20title\x20=\x20newTitle; \x20\x20\x20\x20std::string\x20command\x20=\x20"title\x20"\x20+\x20title; \x20\x20\x20\x20system(command.c_str()); \x20\x20} \x20\x20 \x20\x20//\x20Method\x20to\x20get\x20the\x20window\x20title \x20\x20std::string\x20GetWindowTitle()\x20const\x20{ \x20\x20\x20\x20return\x20title; \x20\x20}
\x20\x20//\x20Method\x20to\x20set\x20the\x20window\x20size \x20\x20void\x20SetWindowSize(const\x20Size&\x20newSize)\x20{ \x20\x20\x20\x20windowSize\x20=\x20newSize; \x20\x20\x20\x20std::string\x20command\x20=\x20"mode\x20con\x20cols="\x20+\x20std::to_string(windowSize.width)\x20+\x20"\x20lines="\x20+\x20std::to_string(windowSize.height); \x20\x20\x20\x20system(command.c_str()); \x20\x20} \x20\x20 \x20\x20//\x20Method\x20to\x20get\x20the\x20window\x20size \x20\x20Size\x20GetWindowSize()\x20const\x20{ \x20\x20\x20\x20return\x20windowSize; \x20\x20} };
原文地址: https://www.cveoy.top/t/topic/qd4n 著作权归作者所有。请勿转载和采集!