首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
在下面程序的横线处填上______,使程序执行后的输出结果为1/2005。 #include<iostream.h> using namespace std; class Date { Public: Date(int
在下面程序的横线处填上______,使程序执行后的输出结果为1/2005。 #include<iostream.h> using namespace std; class Date { Public: Date(int
admin
2012-01-20
11
问题
在下面程序的横线处填上______,使程序执行后的输出结果为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 Date&d1,const Date&d2);
private:
int month, year;
};
Date 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();
}
选项
答案
friend Date
解析
此题考查的是类与对象以及运算符的重载。题目中“+”重载函数的参数表中有两个参数,所以是作为友元函数重载,实现的功能是将参数对象中成员变量month、year进行相应对加。题中重载幽数的返回值类型是类Date,所以应填入“friend Date”。
转载请注明原文地址:https://kaotiyun.com/show/kPVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的输出结果是()。#include<stdio.h>main(){inta[3][3]={0,1,2,0,1,2,0,1,2},i,j,s=1;for(i=0;i<3;i++)for(j
有以下程序,其中%u表示按无符号整数输出()。main(){unsignedintx=0xFFFF;/*x的初值为十六进制数*/printf("%u\n",x);}程序运行后的输出结果是()。
可在C程序中用作用户标识符的一组标识符是()。
请编写函数fun,其功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为WWWWSSSSHHHH则字符串中的内容应是:
设数据集合为D={1,2,3,4,5}。下列数据结构B=(D,R)中为非线性结构的是()。
有如下嵌套的if语句:if(a<b)if(a<c)k=a;dsek=c;elseif(b<c)k=b;elsek=c;以下选项中与上述if语句等价的语句是()。
设Y为整型变量,A=1,A的地址为EF01;B=2,B的地址为EF02;执行语句B=&A;Y=&b;后Y的值()。
C语言规定,函数返回值的类型是()。
下列关系表达式中,结果为“假”的是()。
关于C语言的符号常量,下列叙述正确的是()。
随机试题
教育理念
改革开放前我国行政职能的主要特征是
A.30天(15~45天)B.40天(10~70天)C.50天(15~150天)D.70天(30~180天)E.100天乙型肝炎的潜伏期一般为
关于管理体系合规性评价,下列说法正确的有()。
直接融资方式下的信用工具是()。
强制性思维的主要特点是()。
下列关于“人的全面发展”的说法错误的是()。
大约有百分之几的服务业公司地处郊区?哪一种产业在城区和郊区的分布大致相等?
关于静态路由,下列说法中错误的是()。
请根据下面的题目写一篇论说文,字数不少于500字。生活中我们可以自由的选择还是受到社会各种规则的制约呢?
最新回复
(
0
)