首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
在下面程序的横线处填上__________,使程序执行后的输出结果为1/2005。 #include using namespace std; class Date { public: Date(int
在下面程序的横线处填上__________,使程序执行后的输出结果为1/2005。 #include using namespace std; class Date { public: Date(int
admin
2012-12-29
38
问题
在下面程序的横线处填上__________,使程序执行后的输出结果为1/2005。
#include
using namespace std;
class Date
{
public:
Date(int m=1,int y=0):month(m),year(y){}
void Print(){cout<
__________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);
}
voidmain()
{
Date d1(3,2004),d2,d3(10);
d2=d3+d1;
d2.Print();
}
选项
答案
friend Date
解析
此题考查的是类与对象以及运算符的重载。题目中“+”重载函数的参数表巾有两个参数,所以是作为友元函数重载,实现的功能是将参数对象中成员变量month、year进行相应对加。题中重载函数的返回值类型是类Dace,所以应填入“friend Date”。
转载请注明原文地址:https://jikaoti.com/ti/shL0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#includemain(){inti,j,x=0;for(i=0;i
在黑盒测试方法中,设计测试用例的主要根据是()。
以下程序的输出结果是()。#include<stdio.h>main(){inta=8,b=6,m=1;switch(a%4){case0:m++;break;case1:m
设函数中有整型变量n,为保证其在未赋值的情况下初值为0,应选择的存储类别是()。
判断char型变量c1是否为小写字母的正确表达式为()。
E-R图中用来表示实体的图形是()。
度为3的一棵树共有30个节点,其中度为3,1的节点个数分别为3,4。则该树中的叶子节点数为()。
下面属于白盒测试方法的是()。
在长度为n的顺序表中查找一个元素,假设需要查找的元素有一半的机会在表中,并且如果元素在表中,则出现在表中每个位置上的可能性是相同的。则在平均情况下需要比较的次数大约为()。
下列算法中均以比较作为基本运算,则平均情况与最坏情况下的时间复杂度相同的是()。
随机试题
根据《重要地理信息数据审核公布管理规定》,重要地理信息数据公布时,应当说明()。
下列哪项不属于项目建议书编制的内容()
海关批准进口货物保税的原则为()。
报关单位申报出料加工货物出境时应向海关提交出料加工登记手册、出口货物报关单、货运单据及其他海关需要的报关单证;属于应征出口税的商品,应向海关提供担保,属于许可证件管理的商品,应向海关提交许可证件。()
下列情况下,企业可将其他资产转换为投资性房地产的有()。
AlexisdeTocqueville,theFrenchpoliticalscientist,historian,philosopherandpolitician,ismostfamousforafour-volumeb
某车间需要用一台车床和一台铣床加工A、B、C、D四个零件。每个零件都需要先用车床加工,再用铣床加工。车床与铣床加工每个零件所需的工时(包括加工前的准备时间以及加工后的处理时间)如表3。若以A、B、C、D零件顺序安排加工,则共需32小时。适当调整零件加工
下图是在一台Windows主机在命令行模式不执行某个命令时用sniffer捕获的数据包。请根据图中信息回答下列问题。该主机上执行的命令是【5】。
下列各组排序法中,最坏情况下比较次数相同的是()。
Theteam______itswinningseasontohardworkanditsnewcoach.
最新回复
(
0
)