题目内容

[说明] 设计一个日期类Date,包括年、月、日等私有数据成员。要求实现日期的基本运算,如某日期加上天数、某日期减去天数、两日期相差的天数等。 在Date类中设计如下重载运算符函数。 Date operator+(int days):返回某日期加上天数得到的日期。 Date operator-(int days):返回某日期减去天数得到的日期。 int operator-(Date &b):返回两日期相差的天数。 [C++程序] #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)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) //-运算符重载函数 statis 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; //不是闰年 else return 0; int Date::dton (Date &d) //求从公元0年0月0日到d日期的天数 int y,m,days=0; for (y=1;y<=d.year;y++) if( (5) )days+=366; //闰年时加366天 else days+=365; //非闰年时加365天 for (m=0;m<d.mont.h-1;m++) if (leap (d.year) days+=day_tab [1] [m]; else days+=day__tab [0][m]; days+=d.day; return days; Date Date::ntod (int n) //将从公元0年0月0日的天数转换成日期 int y=1,m=1,d,rest=n,1p; while (1) if (leap (y)) if (rest<-366)break; else rest-=366; else //非闰年 if (rest=365)break; else rest-=365; y++; y--; 1p=leap (y); while (1) if (1p) //闰年 if (rest>day_tab [1][m-1])rest-=day_tab [1] [m-1]; else break; else //非闰年 if(rest>day_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 d1=now+1000,d2=now-1000; cout<<"now+1000:"; d1. disp(); cout<<"now-1000:"; d2. disp();

查看答案
更多问题

[说明] 函数void convert(char *a,int n)是用递归方法将一个正整数n按逆序存放到一个字符数组a中,例如n=123,在a中的存放为’3’、’2’、’1’。 [函数2.1] void convert(char *a,int n) int i; if((i=n/10)! =0) convert( (1) ,i); *a= (2) ; [函数2.2说明] 函数int index(char *s,char *t)检查字符串s中是否包含字符串t,若包含,则返回t在s中的开始位置(下标值),否则返回-1。 [函数2.2] int index(char *s, char *t) int i,j=0;k=0; for(i=0; s[i]!=’\0’;i++) for ( (3) ;(t[k]!=’\0’)&&(s[j]!=’\0’) &&( (4) );j++,k++); if( (5) ) return (i); return (-1);

可用于治疗胃溃疡的化合物()

A. 18-β-H甘草酸
B. 胆酸
C. 齐墩果酸
D. 去氧胆酸
E. 蟾毒灵-3-硫酸酯

Directions: Read the following passages and determine whether the sentences are "Right" or "Wrong". If there is not enough information to answer " Right" or "Wrong", choose "Doesn’t say".Passage One When you buy a house, it is likely that you will be able to borrow a large part of the cost from a building society, when the solicitors close the deal. It is usual, however, to put down a deposit of 10% of the cost several weeks earlier when the price is agreed. Banks will often help with bridging loans for this purpose, against the solicitor’ s undertaking to repay them on completion of the deal. In the same way banks will often make bridging loans to investors, against the security of their investments, when money is required to pay for the purchase of shares before it is available from the sale of other shares. Banks are not usually keen on making long-term loans in either case, because they prefer not to tie up their resources. They lend money which they have borrowed from depositors, mostly repayable on demand or at short notice, and one of the classic ways for a bank to get into trouble is by borrowing "short" and lending "long". You should deposit a certain amount of money with a bank before you buy a house.

A. Right
B. Wrong
C. Doesn’t say

五倍子中的鞣质属于()

A. 没食子酸鞣质
B. 逆没食子酸
C. 缩合鞣质
D. 可水解鞣质
E. 以上都是

答案查题题库