有以下程序: 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( ) { cout<<year<<"."<(month<<"."<<day<<endl; } 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.2

B.3

C.4

D.5


相关考题:

●试题八阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】设计一个日期类Date包括年、月、日等私有数据成员。要求实现日期的基本运算,如某日期加上天数、某日期减去天数、两日期相差的天数等。在Date类中设计如下重载运算符函数:Date operator+(int days):返回某日期加上天数得到的日期。Date operator-(int days):返回某日期减去天数得到的日期。int operator-(Date&b):返回两日期相差的天数。【程序】#includeiostream.hint 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){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 year;)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(){coutyear"."month"."dayendl;}};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;md.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;y++;}y--;Ip=Ieap(y);while (1){if(Ip)∥闰年if(restday_tab[1][m-1])rest-=day_tab[1][m-1];else break;else∥非闰年if(restday_tab[0][m-1])rest-=day_tab[0][m-1];else break;m++;}d=rest;return Date(y;m,d);}void main(){Date now(2003,10,1),then(2005,6,5);cout"now:";now.disp();cout"then:";then.disp();cout"相差天数:"(then-now)endl;Date dl=now+1000,d2=now-1000;cout"now+1000:";d1.disp();cout"now-1000:":d2.disp();}

有以下程序: 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

使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day。分别表示年、月、日,类型为int。请在注释1后添加适当的语句。 (2)完成构造函数,分别给year、month、day赋值,请在注释2后添加适当的语句。 (3)完成重载符号“十=”的定义,请在注释3后添加适当的语句。 (4)完成print打印函数,输出到屏幕和文件的格式相同,请在注释4后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。 程序正常运行,输出的结果为2008年11月813。 试题程序: include(iostream.h) include(fstream) include(iomanip) includecmath) usingnamespacestd; voidWriteFile(intc) { ofstreamout1; out1.open("3.txt",ios_base::app); out1C; out1.close; } voidWriteFile(char*str) { ofstreamoutl; out1.open("3.txt",ios_base::app); out1str; out1.close; } voidClearFile { ofstreamout1; out1.open("3.txt"); out1.close; } classDate { public: Date(inty,intm,intd) { //********1******** } voidprint; //********2******** { month+=m; inti=month/12: intj=month%12; if(j==0) {year+=(i-1); month=12; } else { year+=i: month=j; } return*this; } private: //********3******** }; voidDate::print { //********4******** WriteFile(year): WriteFile("年"); WriteFile(month); WriteFile("月"); WriteFile(day); WriteFile("日"); } intmain { ClearFile; DateOly_day(2008,8,8); Olyday+=3: Oly_day.print; return0; }

在下面程序的横线处填上______,使程序执行后的输出结果为1/2005。 include using nam 在下面程序的横线处填上______,使程序执行后的输出结果为1/2005。include<iostream.h>using namespace std;class Date{Public:Date(int m=1,int y=0): month(m),year(y){}void Print(){cout<<month<<"/"<<year<<end1;}______operator+(const Dated1,const Dated2);private:int month, year;};Date operator+(const Dated1,const Dated2){int year,month;year=d1.year+d2.year;month=d1.month+d2.month;year+=(month-1)/12;month=(month-1)%12+1;return Date(month,year);}void main(){Date d1(3,2004),d2,d3(10);d2=d3+d1;d2.Print();}

下列程序的运行结果是()。 include main() {stmct date {int year,month,day; }today; 下列程序的运行结果是( )。#include<stdio.h>main(){stmct date{int year,month,day;}today;primf("%d\n",sizeof(struct date));}A.8B.6C.10D.12

有以下程序: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;

为使下列程序的正确输出结果为: Now is 2004-7-6 12:12:12 那么应该在程序划线处填入的语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } void DateTime(TIME t); private: int year,month, day; }; class TIME { public: TIME(int h=0,int m=0,int s=0) { hour=h; minute=m; second=s; } ______________; //将类 DATE 中成员函数 DateTime 声明为类 TIME 的友元函数 private: int hour,minute, second; }; void DATE: :DateTime(TIME t) { cout<<"Now is "<<year<<'-'<<month<<'-'<<day<< ' '<<t.hour<<":"<<t.minute<<': '<<t.seoond<<'.'<<end1; } int main ( ) { DATE d(2004,7,6); TIME t (12, 12, 12); d. DateTime (t); return 0; }A.friend void DateTime(TIME t);B.friend void DATE::DateTime(TIME 0;C.void DateTime(TIME t);D.friend void DateTime(TIME t);

给出如下类定义和函数fclassDate{private:intd,m,y;public:Date(intdd,intmm,intyy);voidadd_year(intyy);voidadd_month(intmm);voidadd_day(intdd);}#include"Date.h"voidf(){Datetoday=Date(15,8,2004);//1Datethis_day(15,8,2004);//2Dateother_daA、第1行B、第2行C、第3行D、第4行

在下面程序的画线处填上适当的内容,使程序执行后的输出结果为1/2005。 include usin 在下面程序的画线处填上适当的内容,使程序执行后的输出结果为1/2005。include <iostream>using namespace std;class Date{public:Date(int m=1,int y=0):month(m),year(y){}void Print( ){cout<<month<<"/"<<year<<endl;}(9) operator+(const Datedl,const Date d2);private:int month,year;};(10) operator+(const Date dl,const Date d2){int year,month;year=d1.year+d2.year;month=d1.month+d2.month;year+=(month-1)/12;month=(month-1)%12+1;return Date(month,year);}void main( ){Date dl(3,2004),d2,d3(10);d2=d3+dl;d2.Print( );}

为了使程序的输出的正确结果为: Now is 2004.7.10 10:10:10. 那么应在下列程序划线处填入的正确语句是( )。 那么应在下列程序划线处填入的正确语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } friend void DateTime(DATE d, TIME t); private: int year, month, day; }; class TIME { public: TIME(iht h=0, int m=0,int s=0) { hour=h; minute=m; second=s; } friend void DateTime(DATE d,TIME t); private: int hour,minute, second; }; ______________________ //函数 DateTime 的首部 { cout<<"Now is"<<d.year<<'.'<<d.month<<'.'<<d.day<< ' '<<t.hour<<":"<<t.minute<<':'<<t.second<<'.'<<end1; } int main ( ) { DATE d(2004,7,10); TIME t(10, 10, 10); DateTime(d,t); return 0; }A.void DateTime(DATE d,TIME t)B.void TIME::DateTime(DATE d,TIME t) constC.friend void DateTime(DATE d,TIME t)D.void DATE::DateTime(DATE d,TIME t)

在下面程序的横线处填上适当的内容,使程序执行后的输出结果果为1/2005。 include using 在下面程序的横线处填上适当的内容,使程序执行后的输出结果果为1/2005。include<iostmam>using namespace std;class Date{public:Date(int m=1,int y=0):month(m),year(y){}void Print(){cout<<month<<"/"<<year<<endl;}operator+(const Dated1.const Date d2);private:int month,year;};operator+(const Dated1,const Date d2){int year,month;year=d1.year+d2.year;month=d1.month+d2.month;year+=(month-1)/12;month=(month-1)%12+1;return Date(month,year);}void main(){Date d1(3,2004),d2,d3(10);d2=d3+d1;d2.Print();}

有以下程序: 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

下面结构体的定义语句中,不正确的是______。A.structdate { int month; int day; int year; } Struct date datel;B.stmctdate { intmonth; int day; int year; } datel;C.struct { int month; int day; int year; } date 1;D.#define DATE stmct date DATE { int month; int day; int year; }datel;

有以下程序include using namespace std;static int days[]= { 31,28,31,30,31,30,31 有以下程序 #include <iostream> using namespace std; static int days[]= { 31,28,31,30,31,30,31,31,30,31,30,31 }; class date { private: int month, day, year; public: date( int m, int d, int y ) { month = m; day = d; year = y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+( int day ) { date dt = *this; day+= dt.day; while ( day > days[dt.month - 1 ] ) { day -= days[ dt.month - 1 ]; if ( ++dt.month == 13 ) { dt.month = 1; dt.year++; } } dt.day = day; return dt; }; int main() { date d1( 6, 20, 2004 ), d2; d2: d1 + 20; d2.disp(); return 0; } 执行后的输出结果是A.2004-7-10B.2004-6-20C.2004-7-20D.程序编译时出错

有以下程序include usingnamespacestd;static int days []={31,28.31,30,31,30,31,31 有以下程序 #include <iostream> using namespace std; static int days []={31,28.31,30,31,30,31,31,30,31,30,31}; class date { private: int month, day, year: public: date (int m, int d, int y { month = m; day = d; year = y; } date{} {} void disp {) { cout <<year<<" - "<<month<< "- "<<day<<end1; } date operator+(int day) { date dt = *this: day += dt.day; while { day > days[ dt.month - 1 ] ) { day -= tays[ dt.month - 1 ]; if ( ++dt.month == 13 { dt.month = 1; dt.yeare++; } } dr. day = day; return dt; } }; int main() { date d1( 6, 20, 2004 ), d2; d2.= d1 + 20; d2.disp (); return 0; } 执行后的输出结果是A.2004-7-10B.2004-6-20C.2004-7-20D.程序编译时出错

阅读以下说明和C++抖程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】下面程序的功能是计算并输出某年某月的天数。【C++程序】include<iostream>using namespace std;(1) Month{Jan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};class Date{public:Date(int year,Month m_month){(2) =year;if (m_month<Jan‖m_month>Dec) month=Jan;else month=m_month;};~Date(){};bool IsLeapYear(){return ((year%4==0 year%1001!=0)‖year%400==0);};int CaculateDays(){switch( (3) ){case Feb:{if( (4) )return29;e1Se return 28;}case Jan:case Mar:case May:case Jul:case AUg:case Oct:case Dec:retllrn 31;case Apr:case Jun:Case Sep:case Nov:roturu30;}};private:int year;Month month;};void main(){Date day(2000,Feb);tout<<day. (5) ();}

在下面程序的横线处填上适当的内容,使程序执行后的输出结果为1/2005。includeusing n 在下面程序的横线处填上适当的内容,使程序执行后的输出结果为1/2005。include <iostream.h>using namespace std:class Datepublic:Date (int m=1,int y=0):month(m .year(y}{}void Print() {cout<<month<<"/"<<year<<end1;}______operator+(const Date d1,const Dated2;private:int month year;};______operaror+(const Dated1,const Date d2)int year, month;year=d1.year+d2.year;month=d1.month+d2.month;year+=(month-1)/12;month=(month-1)%12+l;return Date{month, year}:}void main(){Date d1(3,2004),d2,d3(10);d2=d3+d1;d2.Print();}

有以下程序:includeusingnamespacestd;staticintdays[]={31,28,31,30,31,30,31,31,30 有以下程序: #include <iostream> using namespace std; static int days[]={ 31,28,31,30,31,30,31,31,30,31,30,31 }; class date { private: int month,day,year; public: date( int m,int d,int y ) { month = m; day = d; year = y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+( iht day ) { date dt = * this; day += dt.day; while ( day > days[ dt.month - 1 ] ) { day -= days[ dt.month - 1 ]; if ( ++dt.month == 13 ) { dt.month = 1; dt.year++; } } dt.day = day; return dt; } }; int main() { date dl( 6, 20, 2004 ), d2; d2 = dt + 20; d2.disp(); return 0; } 执行后的输出结果是( )。A.2004-7-10B.2004-6-20C.2004-7-20D.程序编译时出错

有以下程序: 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

有以下程序includeusing namespace std;static int days []={31,28,31,30,31,30,3l,3 有以下程序 #include<iostream> using namespace std; static int days []={31,28,31,30,31,30,3l,31,30,31,30,31}; class date { private: int month,day,year; public: date(int m,int d,int y) { month=m; day=d; year=y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+(int day) { date dt=*this; day+=dt.day; while(day>days[dt.month-1]) { day-=days[dt.month-1]; if(++dt.month==13) { dt.month=1; dt.year++; } } dt.day=day; retrn dt; } }; int main() { date d1(6,20,2004),d2; d2=d1+20; d2.disp(); return 0; } 执行后的输出结果是A.2004-7-10B.2004-6-20C.2004-7-20D.程序编译时出错

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。【C++程序】include < iostream >using namespace std;(1) Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };class Date {public:Date( int year, Month m_ month) {this→year = year;if( (2) ) month: Jan;else month = m_ month;};~Date(){};bool IsLeap Year( ) {return ((year%4= =0 year% 100 ! =0)|| year%400= =0);};int CaculateDays( ) {switch(m_month ) {case (3) ;{if (4) return 29;else return 28;}case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;case Apr: case Jun: case Sop: case Nov: return 30;}}private:int year;Month month;};void main( ) {Date day(2000,Feb);cout < <day. (5) ( );}

在下向程序和横线处填上适当的内容,使程序执行后的输出结果为1/2005。 include using 在下向程序和横线处填上适当的内容,使程序执行后的输出结果为1/2005。include <iostream>using namespace std;class Date{public:Date(int m=1,int y=0):month(m),year(y){}void Print() {cout<<month<<"/"<<year<<end 1; }【 】 operator+(eonst Date d1, const Date d2);private:int month,year;};【 】 operator+(const Date d1, const Date d2){int year,month;year=d1.year+d2.year;month=d1. month+d2.month;year+=(month-1 )/12;month=(month-1 )% 12+1;return Date(month,year);}void main()Date d1 (3,2004),d2,d3(10);d2=d3+d1;d2,Print();}

下列程序的运行结果为()。includemain(){struct date {int year,month,day; }today; pr 下列程序的运行结果为( )。 #include<stdio.h> main() { struct date {int year,month,day; }today; printf("%d\n",sizeof(struct date)); }A.8B.6C.10D.12

有以下程序: 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

以下程序的运行结果是()。includemain(){st,uct date {int year,month,day;}today; pri 以下程序的运行结果是( )。 #include <stdio.h> main() { st,uct date {int year,month,day;}today; printf("%d\n",sizeof(struct date)); }A.6B.8C.10D.12