{"id":262,"date":"2011-09-14T13:13:23","date_gmt":"2011-09-14T05:13:23","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=262"},"modified":"2020-06-06T13:15:11","modified_gmt":"2020-06-06T05:15:11","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84_%e9%93%be%e8%a1%a8_%e7%a8%80%e7%96%8f%e5%a4%9a%e9%a1%b9%e5%bc%8f%e6%b1%82%e5%80%bc_c%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=262","title":{"rendered":"\u6570\u636e\u7ed3\u6784_\u94fe\u8868_\u7a00\u758f\u591a\u9879\u5f0f\u6c42\u503c_C++\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u201chead.h\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cmath>\nusing namespace std;\n\nclass PolyTerm\n{\npublic:\n\tPolyTerm();\n\tint coef;\n\tint exp;\n\tPolyTerm *next;\n};\n\nPolyTerm::PolyTerm()\n{\n\tcoef = exp = 0;\n\tnext = NULL;\n}\n\nclass DATA\n{\npublic:\n\tDATA();\n\tvoid GetPoly();\n\tvoid GetX();\n\tvoid GetSum();\nprivate:\n\tint GetPow(int, int);\n\tPolyTerm *head, *p;\n\tint result, x;\n};\n\nDATA::DATA()\n{\n\thead = p = NULL;\n\tx = result = 0;\n}\n\nvoid DATA::GetPoly()\n{\n\tcout &lt;&lt; \"Please Input Data :\" &lt;&lt; endl &lt;&lt; endl;\n\tint coef, exp;\n\tbool first = true;\n\twhile (cin >> coef >> exp)\n\t{\n\t\tif (first)\n\t\t{\n\t\t\thead = new PolyTerm;\n\t\t\thead->coef = coef;\n\t\t\thead->exp = exp;\n\t\t\tp = head;\n\t\t\tfirst = !first;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tp->next = new PolyTerm;\n\t\t\tp = p->next;\n\t\t\tp->coef = coef;\n\t\t\tp->exp = exp;\n\t\t}\n\t}\n\tcin.clear(); \/\/\u89e3\u9664cin\u7684\u5f02\u5e38\u72b6\u6001\n}\n\nvoid DATA::GetX()\n{\n\tcout &lt;&lt; \"GetX Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tif (head == NULL)\n\t{\n\t\tcout &lt;&lt; \"No Data Input !\" &lt;&lt; endl &lt;&lt; endl;\n\t\treturn;\n\t}\n\tcout &lt;&lt; \"Please Input X :\" &lt;&lt; endl &lt;&lt; endl;\n\tcin >> x;\n}\n\nvoid DATA::GetSum()\n{\n\tcout &lt;&lt; \"GetSum Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tif (head == NULL)\n\t\tcout &lt;&lt; \"sum = 0\" &lt;&lt; endl &lt;&lt; endl;\n\telse\n\t{\n\t\tresult = (head->coef) * GetPow(x, head->exp);\n\t\tp = head->next;\n\t\twhile (p != NULL)\n\t\t{\n\t\t\tresult += p->coef * GetPow(x, p->exp);\n\t\t\tp = p->next;\n\t\t}\n\t\tcout &lt;&lt; \"sum = \" &lt;&lt; result &lt;&lt; endl &lt;&lt; endl;\n\t}\n}\n\nint DATA::GetPow(int x, int e)\n{\n\treturn int(pow(double(x), double(e)));\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\"main.cpp\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#include\"head.h\"\n#include&lt;iostream>\nusing namespace std;\n \nint main()\n{\n\tDATA data;\n\tdata.GetPoly();\n\tdata.GetX();\n\tdata.GetSum();\n\tsystem(\"pause\");\n\treturn 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u201chead.h\u201d<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-06-02-"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=262"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}