{"id":207,"date":"2024-05-02T19:37:53","date_gmt":"2024-05-02T11:37:53","guid":{"rendered":"http:\/\/www.cmd137blog.top\/?p=207"},"modified":"2024-05-02T19:37:55","modified_gmt":"2024-05-02T11:37:55","slug":"bjfuoj-c%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1-%e5%ae%9e%e9%aa%8c2-%e7%b1%bb%e4%b8%8e%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"http:\/\/www.cmd137blog.top\/?p=207","title":{"rendered":"BJFUOJ-C++\u7a0b\u5e8f\u8bbe\u8ba1-\u5b9e\u9a8c2-\u7c7b\u4e0e\u5bf9\u8c61"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u5b8c\u6574\u9898\u76ee\u89c1<a href=\"https:\/\/blog.csdn.net\/CMD138\/article\/details\/138397889?spm=1001.2014.3001.5502\">BJFUOJ-C++\u7a0b\u5e8f\u8bbe\u8ba1-\u5b9e\u9a8c2-\u7c7b\u4e0e\u5bf9\u8c61-CSDN\u535a\u5ba2<\/a><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">A \u8bc4\u5206\u7a0b\u5e8f<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b54\u6848\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream&gt;\n#include&lt;cstring&gt;\n\nusing namespace std;\n\nclass Score{\nprivate:\n    string name;\/\/\u8bb0\u5f55\u5b66\u751f\u59d3\u540d\n    double s&#91;4];\/\/\u5b58\u50a84\u6b21\u6210\u7ee9\uff0cs&#91;0]\u548cs&#91;1]\u5b58\u50a82\u6b21\u968f\u5802\u8003\u8bd5\uff0cs&#91;2]\u5b58\u50a8\u671f\u4e2d\u8003\u8bd5\uff0cs&#91;3]\u5b58\u50a8\u671f\u672b\u8003\u8bd5\n    double total;\/\/\u8bb0\u5f55\u603b\u8bc4\u6210\u7ee9\n    char grade='B';  \/\/\u8bb0\u5f55\u5bf9\u5e94\u7684\u7b49\u7ea7\npublic:\n    void Input();\n    void Evalauate();\n    void Output();\n};\n\nvoid Score::Input()\n{\n    string n;\n    double t1 ,t2,t3,t4;\n    cin&gt;&gt;n&gt;&gt;t1&gt;&gt;t2&gt;&gt;t3&gt;&gt;t4;\n    name=n;\n    s&#91;0]=t1;\n    s&#91;1]=t2;\n    s&#91;2]=t3;\n    s&#91;3]=t4;\n    total=t1*0.25+t2*0.25+t3*0.25+t4*0.5;\n}\n\nvoid Score::Evalauate()\n{\n    if(total&gt;=90)\n        grade='A';\n    else if(total&gt;=80)\n        grade='B';\n    else if(total&gt;=70)\n        grade='C';\n    else if(total&gt;=60)\n        grade='D';\n    else\n        grade='E';\n}\n\nvoid Score::Output()\n{\n    if(s&#91;0]&gt;=0&amp;&amp;s&#91;0]&lt;=50&amp;&amp;s&#91;1]&gt;=0&amp;&amp;s&#91;1]&lt;=50&amp;&amp;s&#91;2]&gt;=0&amp;&amp;s&#91;2]&lt;=100&amp;&amp;s&#91;3]&gt;=0&amp;&amp;s&#91;3]&lt;=100)\n        cout&lt;&lt;\"name: \"&lt;&lt;name&lt;&lt;\", total: \"&lt;&lt;total&lt;&lt;\", grade: \"&lt;&lt;grade;\n    else{\n        cout&lt;&lt;\"error\";\n    }\n}\n\nint main()\n{\n    Score *s1=new Score;\n    s1-&gt;Input();\n    s1-&gt;Evalauate();\n    s1-&gt;Output();\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u91cd\u8981\u77e5\u8bc6\u70b9\uff1a<\/h2>\n\n\n\n<p>\u7c7b\u7684\u6307\u9488\u7c7b\u578b\u5bf9\u8c61\uff1a<br>\u4f7f\u7528\u6307\u9488\u7c7b\u578b\u8c03\u7528\u5176\u6210\u5458\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">B \u65e5\u671f\u7c7b\uff08\u9009\u505a\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b54\u6848\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstring>\nusing namespace std;\n\nint getDays(int m, int y)\n{\n    if ((y % 4 == 0 &amp;&amp; y % 100 != 0) || (y % 400 == 0))\n    {\n        switch (m)\n        {\n        case 1:\n        case 3:\n        case 5:\n        case 7:\n        case 8:\n        case 10:\n        case 12:\n            return 31;\n        case 2:\n            return 29;\n        case 4:\n        case 6:\n        case 9:\n        case 11:\n            return 30;\n        }\n    }\n    else\n    {\n        switch (m)\n        {\n        case 1:\n        case 3:\n        case 5:\n        case 7:\n        case 8:\n        case 10:\n        case 12:\n            return 31;\n        case 2:\n            return 28;\n        case 4:\n        case 6:\n        case 9:\n        case 11:\n            return 30;\n        }\n    }\n    return 0;\n}\n\n\nclass Date\n{\npublic:\n   Date(int d = 0, int m = 0, int y = 0); \/\/\u6784\u9020\u51fd\u6570\n   int get_day() const; \/\/ \u8fd4\u56deday\n   int get_month() const; \/\/\u8fd4\u56demonth\n   int get_year() const; \/\/ \u8fd4\u56deyear\n   static void set_default(int, int, int); \/\/\u8bbe\u7f6edefault_date\n   static int get_default_day(); \/\/\u8fd4\u56de\u7f3a\u7701day\n   static int get_default_month(); \/\/\u8fd4\u56de\u7f3a\u7701month\n   static int get_default_year(); \/\/\u8fd4\u56de\u7f3a\u7701year\n   Date &amp; add_year(int n); \/\/\u52a0n\u5e74\n   Date &amp; add_month(int n); \/\/\u52a0n\u6708\uff0c\u8003\u8651\u8d85\u8fc712\u6708\n   Date &amp; add_day(int n); \/\/\u52a0n\u5929\uff0c\u8003\u8651\u8fdb\u4f4d\u6708\u548c\u5e74\uff0c\u8003\u8651\u95f0\u5e74\nprivate:\n   int day, month, year;\n   static Date default_date; \/\/\u521d\u59cb\u5316\u4e3a 1901\u5e741\u67081\u65e5\n};\n\nDate::Date(int d,int m,int y)\n{\n    day=d;\n    month=m;\n    year=y;\n}\n\nint Date::get_day() const\n{\n    return day; \n} \n\nint Date::get_month() const\n{\n    return month;   \n} \n\nint Date::get_year() const\n{\n    return year;    \n} \n\nDate Date::default_date(1, 1, 1901);\n\nvoid Date::set_default(int td, int tm, int ty)\n{\n    default_date=Date(td,tm,ty);\n}\n\nint Date::get_default_day()\n{\n    return default_date.day;\n}\n\nint Date::get_default_month()\n{\n    return default_date.month;\n}\n\nint Date::get_default_year()\n{\n    return default_date.year;\n}\n\nDate &amp; Date::add_day(int n)\n{\n    day+=n;\n    while(day>getDays(month,year))\/\/\u6ce8\u610f\u4f7f\u7528while\u800c\u975eif\uff0c\u4e0b\u540c\n    {   \n        day-=getDays(month,year);\n        add_month(1); \n    }\n    return *this;\n}\n\nDate &amp; Date::add_month(int n)\n{\n    month+=n;\n    while(month>12)\n    {\n        month-=12;\n        year++;\n    }\n    add_day(0);\/\/\u5904\u7406\u52a0\u201c\u6708\u201d\u540e\u201c2\u670830\u65e5\u201d\u3001\u201c4\u670831\u65e5\u201d\u4e4b\u7c7b\u7684\u60c5\u51b5\u3002\u4e0b\u540c\n    return *this;\n}\n\nDate &amp; Date::add_year(int n)\n{\n    year+=n;\n    add_day(0);\n    return *this;\n}\n\n\n\nint main()\n{\n   char type&#91;110];\n   int day,mon,year;\n   int addday,addmon,addyear;\n   while(cin>>type)\n   {\n      if(strcmp(type,\"Date\") == 0)\n      {\n         cin>>day>>mon>>year;\n         Date mydate(day,mon,year);\n         cin>>addday>>addmon>>addyear;\n         mydate.add_day(addday).add_month(addmon).add_year(addyear);\n         cout &lt;&lt; mydate.get_day() &lt;&lt; \" \" &lt;&lt; mydate.get_month() &lt;&lt; \" \" &lt;&lt; mydate.get_year() &lt;&lt; endl;\n      }\n      else if(strcmp(type,\"defaultDate\") == 0) \n      {\n          cout &lt;&lt; Date::get_default_day() &lt;&lt; \" \" &lt;&lt; Date::get_default_month() &lt;&lt; \" \" &lt;&lt; Date::get_default_year() &lt;&lt; endl;\n      }\n      else if(strcmp(type,\"setdefaultDate\") == 0)\n      {\n         cin>>day>>mon>>year;\n         Date::set_default(day,mon,year);\n         cout &lt;&lt; Date::get_default_day() &lt;&lt; \" \" &lt;&lt; Date::get_default_month() &lt;&lt; \" \" &lt;&lt; Date::get_default_year() &lt;&lt; endl;\n      }\n   }\n   return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u91cd\u8981\u77e5\u8bc6\u70b9\uff1a<\/h2>\n\n\n\n<p><del>\u5410\u69fd\u4e00\u4e0b\uff0c\u8fd9\u9898\u51fa\u7684\u771f\u9006\u5929<\/del><br>\u57fa\u672c\u4e0a\u7b97\u662f\u5bf9\u4e4b\u524d\u77e5\u8bc6\u70b9\u7684\u5927\u6742\u70e9<br>\u00b7\u6210\u5458\u51fd\u6570\u8fd4\u56de\u503c\u4e3a\u7c7b\u65f6\uff0c return *this\u8fd4\u56de\u81ea\u8eab\u5bf9\u8c61\u7684\u4f7f\u7528\u3002<br>\u00b7\u90e8\u5206\u4ee3\u7801\u903b\u8f91\u503c\u5f97\u53c2\u8003\uff1a<br>\u5982add_day(0);<br>getDays\u51fd\u6570\u7684\u4f7f\u7528\u4e0e\u5b9e\u73b0\uff1b<br>\u7ecf\u5178\u6613\u9519\u95f0\u5e74\u5224\u65ad\uff1a(y % 4 = = 0 &amp;&amp; y % 100 != 0) || (y % 400 == 0) <del>1800\u5e74\u4e0d\u662f\u95f0\u5e74<\/del><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b8c\u6574\u9898\u76ee\u89c1BJFUOJ-C++\u7a0b\u5e8f\u8bbe\u8ba1-\u5b9e\u9a8c2-\u7c7b\u4e0e\u5bf9\u8c61-CSDN\u535a\u5ba2 A \u8bc4\u5206\u7a0b\u5e8f \u7b54\u6848\uff1a \u91cd\u8981\u77e5\u8bc6\u70b9\uff1a \u7c7b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,5],"tags":[23,21,30],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-c","category-5","tag-c","tag-21","tag-30"],"_links":{"self":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207"}],"version-history":[{"count":1,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":208,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions\/208"}],"wp:attachment":[{"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cmd137blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}