题目内容

●试题八
阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
设计一个日期类Date包括年、月、日等私有数据成员。要求实现日期的基本运算,如某日期加上天数、某日期减去天数、两日期相差的天数等。
在Date类中设计如下重载运算符函数:
Date operator+(int days):返回某日期加上天数得到的日期。
Date operator-(int days):返回某日期减去天数得到的日期。
int operator-(Date&b):返回两日期相差的天数。
【程序】
#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)∥-运算符重载函数
{
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;∥不是闰年
else
return0:
}
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];
else
days+=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(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 dl=now+1000,d2=now-1000;
cout<<"now+1000:";d1.disp();
cout<<"now-1000:":d2.disp();
}

查看答案
更多问题

●试题四
阅读下列程序说明和C程序,将应填入(n)处的字句写在答卷纸的对应栏内。
【程序说明】
该程序定义了两个子函数strsort和strmerge。它们分别实现了将一个字符串按字母顺序排序和将两个字符串合并排序,并删去相同字符。在主函数里,先输入两个字符串s1和s2,然后调用strsort函数对它们分别排序,然后调用strmerge函数将s1和s2合并,将合并后的字符串赋给字符串s3,最后输出字符串s3。
【程序】
#include<stdio.h>
void strmerge(char*a,char*b,char*c)//将字符串a,b合并到字符串c中
{
char t,*w;
w=c;
while((1) )
{
//找到字符串a,b当前字符中较小的字符
if(*a<*b)
{
t=*a;
(2) ;
}
else if(*a>*b)
{
t=*b;
(3) ;
}
else//字符串a,b当前字符相等
{
t=*a;
a++;
b++;
}
if((4) )//开始,可直接赋值
*w=t;
else if(t!=*w)
//如果a,b中较小的当前字符与c中当前字符不相等,才赋值 (5) ;
}
if(*a!=\′\0′)//如果字符串a还没有结束,则将a的剩余部分赋给c
while(*a!=′\0′)
if(*a!=*w)
{
*(w)=*a;
a++;
}
else
(6) ;
if(*6!=′\0′)//如果字符串b还没有结束,则将b的剩余部分赋给c
while(*b!=′\0′)
if(*b!=*w)
{
*(w)=*b;
b++;
}
else
b++;
(7) ;
}
void strsort(char*s)//将字符串S中的字符排序
{
int i,j,n;
char t,*w;
W=S;
for(n=0;*w!=′\0′;n++)//得到字符串长度n
w++;
for(i=0;i<n-1;i++)//对字符串s进行排序,按字母先后顺序
for(j=i+1;j<n;j++)
if((8) )
{
t=s[i];s[i]=s[j]; (9) ;
}
}
void main()
{
char s1[100],s2[100],s3[100];printf("\nPlease,input the first string:");
scanf("%s",s1);
printf("\nPlease input the second string:");
scanf("%s",s2);
strsort(s1);//将字符串s1排序
strsort(s2);//将字符串s2排序
printf("%s\n",s1);
printf("%s\n",s2);
s3[0]=′\0′;//字符串s3的第一个字符先置′\0′结束标志
(10) //将s1和s2合并,按照字母顺序排列,
//且要删去相同字符,存入s3中
printf("%s",s3);
}

●试题三
阅读下列说明和HTML文本,分析其中嵌入的JavaScript脚本,将应填入(n)处的语句写在答题纸的对应栏内。
【说明1】在文本框中实现时钟显示功能,格式如下:“-年-月-日小时:分:秒星期几”
【HTML文本】
<html>
<!省略部分为HTML文本框>
<script. Language="JavaScript">
<!
vartimer=null;//定义全域变量,timer表示当前定时器是否在运行,time-rr表
//示当前正在运行的定时器Id
var timerr=false;
function stopClock(){ //停止时钟函数,如果定时器正在运行,就停止该定时器
if((1) )
ClearTimeout(timer);
timerr=false;
document.clock.face.value="";
}
function showTime(){
var now=new Date();//定义各个与时间有关的变量(年、月、日等),并且赋
//值于当前时间的值
var year=now.getYear();
var month= (2) ;
var date=new.getDate();
vat hours=nowgetHours();
var mins=now.getMinutes();
var secs=now.getSeconds();
var days=now.getDay();
functionday(){//定义星期显示函数
this.length=day.arguments.length;
for((3) )
this[i+1]=day.arguments[i];
}
var d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六",);
//定义新对象
Var timeval="";//定义时钟显示的当前时间字符串
timeval+=year"年";//产生当前时间的显示字符串
timeval+=month+"月";
fimeval+=date+"日";
timeval+=hours;
timeval+=((mins<10)?":0":":")+rains;
timeval+=()secs<10)?":0":":")+secs;
timeval+= (4) ;
document.clock.face.value=timeval;//将“时钟”的显值改写为当前时间
timer=setTimeout("showTime()",1000);//设置定时器且设置定时器正在运行
(5) ;
function startClick() ∥定义开始定时定时器的显示
stopClock();
showTime();
function windowOpener(indexnum){//在装载主页时调用开始时钟显示的程序
vat loadpos="date.html"+"#"+indexnum;
controlWindow=window.open(loadpos,"date","toolbar=no,location=no,diretories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=400");
}
//>
</script>
<!省略部分为HTML文本框>
</html>

●试题二
如今无线技术发展迅速,请回答下面关于无线通信方面。
[问题1]请列举IEEE 802.11b的两种工作模式。
[问题2]提高WLAN的安全性有哪些措施。
[问题3]列举蓝牙产品采用的主要技术内容。

●试题四
请补充函数fun(),该函数的功能是将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Are you come from Sichuan?",则输入"are you come from sichuan?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char *fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
{
if((tt[i]>=′A′)&&((1) ))
(2) ;
}
return ((3) ) ;
}
main()
{
char tt[81];
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is: \n%s",
fun(tt));
}

答案查题题库