SSL: 1
Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /www/blog/wp-includes/load.php:1646) in /www/blog/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":365,"date":"2016-07-04T19:53:18","date_gmt":"2016-07-04T11:53:18","guid":{"rendered":"https:\/\/blog.weskiller.com\/?p=365"},"modified":"2016-07-12T15:33:01","modified_gmt":"2016-07-12T07:33:01","slug":"c%e7%bc%96%e7%a8%8b%e7%bb%83%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/blog.gamein.vip\/365.html","title":{"rendered":"C++\u7f16\u7a0b\u7ec3\u4e60"},"content":{"rendered":"

\u9898\u76ee\u51fa\u81ea\u300aC++ Primer Plus\u300b\u7b2c5\u7ae0<\/span><\/p>\n

\n\u5047\u8bbe\u8981\u9500\u552e\u300aC++ For Fools\u300b\u4e00\u4e66\u3002\u8bf7\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u8f93\u5165\u5168\u5e74\u4e2d\u6bcf\u4e2a\u6708\u7684\u9500\u552e\u91cf\uff08\u56fe\u4e66\u6570\u91cf\uff0c\u800c\u4e0d\u662f\u9500\u552e\u989d)\u3002\u7a0b\u5e8f\u901a\u8fc7\u5faa\u73af\uff0c\u4f7f\u7528\u521d\u59cb\u5316\u4e3a\u6708\u4efd\u5b57\u7b26\u4e32\u7684char*\u6570\u7ec4\u6216string\u5bf9\u8c61\u6570\u7ec4\uff09\u9010\u6708\u8fdb\u884c\u63d0\u793a\uff0c\u5e76\u5c06\u8f93\u5165\u7684\u6570\u636e\u50a8\u5b58\u5728\u4e00\u4e2aint\u6570\u7ec4\u4e2d\u3002\u7136\u540e\uff0c\u7a0b\u5e8f\u8ba1\u7b97\u6570\u7ec4\u4e2d\u5404\u5143\u7d20\u7684\u603b\u6570\uff0c\u5e76\u62a5\u544a\u8fd9\u4e00\u5e74\u7684\u9500\u552e\u60c5\u51b5\uff08\u6211\u81ea\u5b9a\u4e49\u4e86\u7ed3\u6784\u4f53\u6570\u7ec4\u4e00\u5e76\u5b8c\u6210\u7b2c\u516d\u9898\uff09\u3002<\/span><\/p>\n

\r\n#include <iostream>\r\n#include <cstdio>\r\nconst int this_year = 2017;\r\nconst int years = 3;\r\nconst int per_year = 12;\r\nstruct record\r\n{\r\n        int  years;\r\n        int months;\r\n        long sales;\r\n};\r\nint main()\r\n{\r\n        using namespace std;\r\n        record (*date)[per_year] = new record [years][per_year];\r\n        for (int i = 0;i < years;++i)\r\n                for (int j = 0;j < per_year; ++j)\r\n                {\r\n                        date[i][j].years=this_year+i;\r\n                        date[i][j].months=j+1;\r\n                        cout << "Please input sales for "\r\n                                << date[i][j].years \r\n                                << " year "\r\n                                << date[i][j].months\r\n                                << " month:\\n";\r\n                        cin >> date[i][j].sales;\r\n                }\r\n        long long * sales_per_year = new long long [years];\r\n        for (int i = 0;i < years; ++i)\r\n        {\r\n                for (int j = 0;j < per_year; ++j)\r\n                        sales_per_year[i] += date[i][j].sales;\r\n                cout << this_year + i  \r\n                        << " year had been sale "\r\n                        << sales_per_year[i] \r\n                        << " books." << endl;\r\n        }       \r\n        return 0;\r\n}\r\n<\/pre>\n

\n\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b83\u4f7f\u7528\u4e00\u4e2achar\u6570\u7ec4\u548c\u5faa\u73af\u6765\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5355\u8bcd\uff0c\u76f4\u5230\u7528\u6237\u8f93\u5165done\u4e3a\u6b62\u3002\u968f\u540e\uff0c\u8be5\u7a0b\u5e8f\u6307\u51fa\u7528\u6237\u8f93\u5165\u4e86\u591a\u5c11\u4e2a\u5355\u8bcd\uff08\u4e0d\u5305\u62ecdone\u5728\u5185\uff09\u3002\u4e0b\u9762\u662f\u8be5\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\uff1a<\/span><\/p>\n

\r\nEnter words (to sto p , type the word done) \uff1a<\/span>\r\nanteater birthday category dumpster \r\nenvy finagle geometry done for sure\r\nYou entered a total of 7 words.\r\n<\/pre>\n

\u60a8\u5e94\u5728\u7a0b\u5e8f\u4e2d\u5305\u542b\u5934\u6587\u4ef6cstring,\u5e76\u4f7f\u7528\u51fd\u6570StrCmp()\u6765\u8fdb\u884c\u6bd4\u8f83\u6d4b\u8bd5<\/span><\/p>\n

\r\n#include <iostream>\r\n#include <cstring>\r\n#include <stdio.h>\r\nusing namespace std;\r\nint main()\r\n{\r\n\tchar * ch = new char;\r\n\tchar * word = new char [100];\r\n\tchar * string = new char [100];\r\n\tint *pcw = new int ;\r\n\tint *pcc = new int ;\r\n\t*pcc=*pcw=0;\r\n\/\/\u786e\u8ba4\u524d\u9762\u7684\u4e00\u4e2a\u5b57\u7b26\u4e0d\u4e3a\u7a7a\r\n\tbool empty=true;\r\n\twhile ( strcmp(word,"done") )\r\n\t{\r\n\t\t*ch=getchar();\r\n\t\tif ( *ch == EOF || *ch == ' ' || *ch == '\\n' )\r\n\t\t{\t\r\n\t\t\tif ( empty )\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tstrcpy(word,string);\r\n\t\t\tstring[0]='\0';\r\n\t\t\t*pcc=0;\r\n\t\t\tif ( word[0] != ' ' || word[0] != '\\n' || word[0] != EOF )\r\n\t\t\t\t++*pcw;\r\n\t\t\tempty=true;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tstring[*pcc]=*ch;\r\n\t\tempty=false;\r\n\t\tstring[(*pcc)+1]='\0';\r\n\t\t(*pcc)+=1;\r\n\t}\r\n\tcout << "You entered a total of " \r\n\t\t<< (*pcw)-1 \r\n\t\t<< " words."\r\n\t\t<< endl;\r\n\treturn 0;\r\n}\r\n<\/pre>\n

\u9898\u76ee\u51fa\u81ea\u300aC++ Primer Plus\u300b\u7b2c6\u7ae0<\/span>
\n\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b83\u6bce\u6b21\u8bfb\u53d6\u4e00\u4e2a\u5355\u8bcd\uff0c\u76f4\u5230\u7528\u6237\u53ea\u8f93\u5165q\u3002\u7136\u540e, \u8be5\u7a0b\u5e8f\u6307\u51fa\u6709\u591a\u5c11\u4e2a\u5355\u8bcd\u4ee5\u5143\u97f3\u6253\u5934\uff0c\u6709\u591a\u5c11\u4e2a\u5355\u8bcd\u4ee5\u8f85\u5485\u6253\u5934\uff0c\u8fd8\u6709\u591a\u5c11\u4e2a\u5355\u8bcd\u4e0d\u5c5e\u4e8e\u8fd9\u4e24\u7c7b\u3002\u4e3a\u6b64\uff0c\u529b\u6cd5\u4e4b\u4e00\u7761\u662f\uff0c\u4f7f\u7528isalpha()\u6765\u533a\u5206\u4ee5\u5b57\u6bcd\u548c\u5176\u4ed6\u5b57\u7b26\u6253\u5934\u7684\u5355\u8bcd,\u7136\u540e\u5bf9\u4e8e\u901a\u8fc7isalpha()\u6d4b\u8bd5\u7684\u5355\u8bcd\uff0c\u4f7f\u7528if\u6216switch\u8bed\u53e5\u6765\u786e\u5b9a\u54ea\u4e9b\u4ee5\u5143\u97f3\u6253\u5934\u3002\u8be5\u7a0b\u5e8f\u7684\u8fd0\u884c\u60c5\u51b5\u5982\u4e0b\uff1a<\/span><\/p>\n

\r\nEnter words (q to quit ) :\r\nThe 12 awesome oxen ambled\r\nquietly across 15 meters of lawn. q\r\n5 words be ginning with vowels \r\n4 words be ginning with consonants\r\n2 other\r\n<\/pre>\n

\n*\u9700\u8981\u5224\u65ad\u6bcf\u4e2a\u5b57\u7b26\u7684\u524d\u9762\u4e00\u4e2a\u5b57\u7b26\u548c\u540e\u9762\u4e00\u4e2a\u5b57\u7b26<\/p>\n

\r\n#include <iostream>\r\n#include <cctype>\r\n#include <cstdio>\r\nusing namespace std;\r\nint main()\r\n{\r\n\tcout << "Enter words (q to quit):" << endl;\r\n\tchar ch;\r\n\tbool empty = true;\r\n\tint vowels,consonants,others;\r\n\tothers=vowels=consonants=0;\r\n\twhile ( ch = cin.get() )\r\n\t{\r\n\t\tcin.clear();\r\n\t\tif (empty)\r\n\t\t{\r\n\t\t\tif ( isalpha(ch) )\r\n\t\t\t{\r\n\t\t\t\tif ( ch == 'q' )\r\n\t\t\t\t{\r\n\t\t\t\t\tchar temp;\r\n\t\t\t\t\ttemp=cin.get();\r\n\t\t\t\t\tif (temp == '\\n' || temp == ' ' || temp == EOF)\r\n\t\t\t\t\t{\t\r\n\t\t\t\t\t\tempty = true;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\t\r\n\t\t\t\t\t\t++consonants;\r\n\t\t\t\t\t\tempty = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch =='u')\r\n\t\t\t\t{\r\n\t\t\t\t\t\t++vowels;\r\n\t\t\t\t\t\tempty = false;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t++consonants;\r\n\t\t\t\t\tempty = false;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t++others;\r\n\t\t\t\tchar temp;\r\n\t\t\t\tif ((temp = cin.get()) != '\\n' || temp != ' ' || temp != EOF)\r\n\t\t\t\t{\r\n\t\t\t\t\tempty = false;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tempty = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (ch == '\\n' || ch == ' ' || ch == EOF)\r\n\t\t\tempty = true;\r\n\t\telse\r\n\t\t{\r\n\t\t\tempty = false;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t}\r\n\tcout << vowels << " words beginning with vowels" << endl;\r\n\tcout << consonants << " words begining with consonants" << endl;\r\n\tcout << others << " others" << endl;\r\n\treturn 0;\r\n}\r\n<\/pre>\n

\u9898\u76ee\u51fa\u81ea\u300aC++ Primer Plus\u300b\u7b2c8\u7ae0<\/span>
\n\u51fd\u6570\u91cd\u8f7d(\u591a\u6001)\uff0c\u51fd\u6570\u6a21\u677f<\/span><\/p>\n

\r\n#include <iostream>\r\ntemplate <typename T> void ShowArray(T arr[],int n);\r\ntemplate <typename T> void ShowArray(T * arr[],int n);\r\nint SumArray(int * ,int n);\r\ndouble SumArray(double * *,int n);\r\nstruct debts\r\n{\r\n\tchar name[50];\r\n\tdouble amount;\r\n};\r\nint main()\r\n{\r\n\tusing namespace std;\r\n\tint things[6] = { 13,31,103,301,310,130 };\r\n\tstruct debts mr_E[3] = \r\n\t{\r\n\t\t{ "Ima Wolfa", 2400.0 },\r\n\t\t{ "Ura Foxe", 1300.0 },\r\n\t\t{ "Iby Stout", 1800.0 }\r\n\t};\r\n\tdouble * pd[3];\r\n\tfor (int i = 0; i < 3; i++)\r\n\t\tpd[i] = &mr_E[i].amount;\r\n\tcout << "Listing Mr. E's counts of things:\\n";\r\n\tShowArray(things,6);\r\n\tcout << "Listing Mr. E's debts:\\n";\r\n\tShowArray(pd,3);\r\n\tcout << SumArray(things,6) << endl;\r\n\tcout << SumArray(pd,3) << endl;\r\n\treturn 0;\r\n}\r\ntemplate <typename T> void ShowArray(T arr [], int n)\r\n{\r\n\tusing namespace std;\r\n\tcout << "template A\\n";\r\n\tfor(int i = 0;i < n;i++)\r\n\t\tcout << arr[i] << ' ';\r\n\tcout << endl;\r\n\treturn ;\r\n}\r\ntemplate <typename T> void ShowArray(T * arr [] ,int n)\r\n{\r\n\tusing namespace std;\r\n\tcout << "template B\\n";\r\n\tfor(int i = 0;i < n;i++)\r\n\t\tcout << *arr[i] << ' ';\r\n\tcout << endl;\r\n\treturn ;\r\n}\r\nint SumArray(int * arr, int n)\r\n{\r\n\tint result = 0;\r\n\tfor (int i = 0;i < n;i++)\r\n\t\tresult +=  arr[i];\r\n\treturn result;\r\n}\r\ndouble SumArray(double * * arr,int n)\r\n{\r\n\tdouble result = 0;\r\n\tfor(int i = 0;i < n;i++)\r\n\t\tresult += *arr[i];\r\n\treturn result;\r\n}\r\n<\/pre>\n

\u9646\u7eed\u66f4\u65b0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u9898\u76ee\u51fa\u81ea\u300aC++ Primer Plus\u300b\u7b2c5\u7ae0 \u5047\u8bbe\u8981\u9500\u552e\u300aC++ For Fools\u300b\u4e00\u4e66\u3002\u8bf7\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[23],"class_list":["post-365","post","type-post","status-publish","format-standard","hentry","category-c","tag-c"],"_links":{"self":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/comments?post=365"}],"version-history":[{"count":36,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/365\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/posts\/365\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/media?parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/categories?post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamein.vip\/wp-json\/wp\/v2\/tags?post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}