有以下程序: class Date { public: Date(int y,int m,int d); { year = y; month = m; day = d; } Date(int y = 2000) { year = y; month = 10; day = 1; } Date(Date d) { year = d.year; month = d.month; day = d.day; } void print() { cout<<year<<"."<<month<<"."<<day<<endl; } private: int year,month,day; }; Date fun(Date d) { Date temp; temp = d; resurn temp; } int main () { Date date1 (2000,1,1),date2 (0,0,0); Date date3 (date1); date2 = fun(date3); return 0; } 程序执行时,Date类的拷贝构造函数被调用的次数是A.2B.3C.4D.5
有以下程序: class Date { public: Date(int y,int m,int d); { year = y; month = m; day = d; } Date(int y = 2000) { year = y; month = 10; day = 1; } Date(Date &d) { year = d.year; month = d.month; day = d.day; } void print() { cout<<year<<"."<<month<<"."<<day<<endl; } private: int year,month,day; }; Date fun(Date d) { Date temp; temp = d; resurn temp; } int main () { Date date1 (2000,1,1),date2 (0,0,0); Date date3 (date1); date2 = fun(date3); return 0; } 程序执行时,Date类的拷贝构造函数被调用的次数是
A.2
B.3
C.4
D.5
相关考题:
有以下程序: Class Date { public: Date(int y,int m,mt d); { year=y; month=m; day=d; } Date(int y=2000) { year=y; month=10; day=1; } Date(Date D) { year=d.year; month=d.month; day=d.day; } Void prinA.2B.3C.4D.5
有以下程序:class Date{public:Date(int y,int m,int d);{year=y;month=mday=d;}Date(int y=2000){year=y;month=10;day=1;}Date(Date d){year=d.year;month=d.month;day=d.day;}void print( ){cout<<year<<"."<<month<<"."<<day<<endl;}private:int year,month,day;};Date fun(Date d){Date temp;temp=d;return temp;}int main( ){Date datel(2000,1,1),date2(0,0,0);Date date3(datel);date2=fun(date3);return 0;}程序执行时,Date类的拷贝构造函数被调用的次数是A.2B.3C.4D.5
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】设计一个日期类Date包括年、月、日等私有数据成员。要求实现日期的基本运算,如某日期加上天数、某日期减去天数、两日期相差的天数等。在Date类中设计如下重载运算符函数:Date operator + (int days) : 返回某日期加上天数得到的日期。Date operator - (int days) : 返回某日期减去天数得到的日期。int operator - (Dateb): 返回两日期相差的天数。【程序】include<iostream.h>int day tab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};//day_tab二维数组存放各月天数,第一行对应非闰年,第二行对应闰年class Date{int year, month, day //年,月,日int leap(int); //判断是否闰年int dton(Date)Date ntod(int)public:Date() { }Date (int y, int mint d) I year = y; month = m; day = d;}void setday(intd){day = d;}void setmonth(int m) {month = m;}void setyear(int y) {year =y;}int getday() {return day;}int getmonth() {return month:}int getyear() {return yea;}Date operator + (int days) //+运算符重载函数{static Date date;int number =(1)date = ntod(number)return date}Date operator - (int days) //-运算符重载函数{staffs Date date;int number=(2);number - = days;date = ntod(number)return date;}int operator - (Date b) //-运算符重载函数{int days=(3);return days;}void disp(){cout<<year<<"."<<month<<". "<<day<<endl;}};int Date: :leap( int year)if((4)) //是闰年return 1; //不是闰年elsereturn0:}int Date:: dton( Date d) //求从公元0年0月0日到d日期的天数{inty,m,days =0;for(y=1;y<=d. year;y++)if((5))days+ =366; //闰年时加366天else days + = 365; //非闰年时加365天for(m =0;m<d. month-1;m++)if((6))days += day_tab[1] [m];elsedays +=day_tab[0] [m];days + = d. day;return days;}Date Date::ntod(intn) //将从元0年0月0日的天数转换成日期{int y=1,m = 1,d,rest = n,lp;while(1){ if(leap(y))if(rest<= 366) break;else rest - = 366;else //非闰年if(rest = 365 ) break;else rest-=365;
有以下程序: class Date { public: Date(int y,int m,int D) ; { year =y; month=m; day=d; } Date(int y=2000) { year=y; month=10; day=1; } Date(Date D) { year=d.year; month=d.month; day=d.day; } void print () { cout<<year<<"."<<month<<"."<<day<<end1; } private: int year,month,day; }; Date fun(Date D) { Date temp; temp=d; return temp; } int main() { Date date1(2000,1,1),date2(0,0,0); Date date3(date1); date2=fun(date3); return 0; } 程序执行时,Date类的拷贝构造函数被调用的次数是A.2B.3C.4D.5
有以下程序: classDate {public: Date(inty,intm,intd); {year=Y; month=m; day=d;} Date(inty=2000) {year=y; month=10; day=1;} Date(Date&d) {year=d.year; month=d.month; day=d.day;} voidprint() {coutyear"."month"." dayendl;} private: intyear,month,day;}; Datefun(Dated) {Datetemp; temp=d; returntemp;} intmain() {Datedatel(2000,1,1),date2(0,0,O); Datedate3(date1); date2=fun(date3); return0;} 程序执行时,Date类的复制构造函数被调用的次数是( )。A.2B.3C.4D.5
有以下程序: Class Date {public: Date(int y,int m,int d); {year=y; month=m; day=d;} Date(int y=2000) {year=y; month=10; day=1;) Date(Date D) {year=d.year; month=d.month; day=d.day;} void print() {cout<<year<<“.”<<moA.2B.3C.4D.5
有以下程序: class Date { public: Date(int y, int m, int d); year = y; month = m; day = d; Date(int y = 2000) year = y; month = 10; day = 1; Date(Date d) { year = d.year; month = d.month; day = a.day; } void print() cout<<year<<"."<<month<<"."<<day<<end1; } private: int year, month,day; }; Date fun(Date d) Date temp; temp = d; return temp; } int main() { Date date 1 (2000,1,1),date2(0,0,0); Date date3(date 1); date2 = fun(date3); return 0; } 程序执行时,Date 类的拷贝构造函数被调用的次数是A.2B.3C.4D.5
有以下程序: classDate { public: Date(inty,intm,intd); { year=Y: month=m; day=d; } Date(inty=2000) { year=y; month=10; day=1; } Date(Date&d){ year=d.year; month=d.month; day=d.day; } voidprint( ) { coutyear"."(month"."dayendl; } private: intyear,month,day; }; Datefun(Dated) { Datetemp; temp=d; returntemp; } intmain( ) { Datedatel(2000,1,1),date2(0,0,0); Datedate3(datel); date2=fun(date3); return0; } 程序执行时,Date类的拷贝构造函数被调用的次数是( )。A.2B.3C.4D.5
有以下程序:classDate{public:Date(inty,intm,intd);{year=Y;month=m;day=d;}Date(inty=2000){year=y;month=10;day=1;}Date(Date&d){year=d.year;month=d.month;day=d.day;}voidprint(){coutyear.month.dayendl;}private:intyear,month,day;};Datefun(Dated){Datetemp;temp=d;returntemp;}intmain(){Datedatel(2000,1,1),date2(0,0,O);Datedate3(date1);date2=fun(date3);return0;}程序执行时,Date类的复制构造函数被调用的次数是( )。A.2B.3C.4D.5