練習(xí)9.51
設(shè)計(jì)一個(gè)類(lèi),它有三個(gè)unsigned成員,分別表示年、月和日。為其編寫(xiě)構(gòu)造函數(shù),接受一個(gè)表示日期的string參數(shù)。你的構(gòu)造函數(shù)應(yīng)該能處理不同的數(shù)據(jù)格式,如January 1,1900、1/1/1990、Jan 1 1900 等。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-410569.html
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class date
{
private:
unsigned year, month, day;
public:
date(const string& s)
{
if (s.find_first_of("/") != string::npos)
convert1(s);
else if (s.find_first_of(",") != string::npos)
convert2(s);
else if (s.find_first_of(" ") != string::npos)
convert3(s);
else
year = 1900, month = 1, day = 1;
}
void print()
{
cout << "day:" << day << " "
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-410569.html
到了這里,關(guān)于C++ Primer第五版_第九章習(xí)題答案(51~52)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!