首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day,分别表示年、月、 日,类型为i
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day,分别表示年、月、 日,类型为i
admin
2017-11-27
17
问题
使用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。
(1)定义私有成员变量year、month、day,分别表示年、月、 日,类型为int。请在注释//********1********后添加适当的语句。
(2)完成构造函数,分别给year、month、day赋值,请在注释//********2********后添加适当的语句。
(3)完成重载符号“+=”的定义,请在注释//********3********后添加适当的语句。
(4)完成print()打印函数,如2008年8月8日到屏幕和文件modi3.txt格式相同,请在注释∥********4********后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
#include
#include
#include
#include
using namespace std;
void WriteFile(int c)
{
ofstream out1;
out1.open("modi3.txt",ios_base::app);
out1<
out1.Close();
}
void WriteFile(char* str)
{
Ofstream out1;
out1.open("modi3.txt",ios_base::app);
out1<
out1.close();
}
void ClearFile()
{
ofstream out1;
out1.open("modi3.txt");
out1.Close();
}
Class Date
{
public:
Date(int y,int m,int d)
{
//********2********
}
void print()const;
//********3********
{
month+=m;
int i=month/12;
int j=month%12;
if(j=0)
{
year+=(i-1);
month=12;
}
elase
{
year+=i;
month=j;
}
return *this;
}
private:
//********1********
};
void Date::print()const
{
//********4********
WriteFile(year);
WriteFile("年");
WriteFile(month);
WriteFile("月");
WriteFile(day);
WriteFile("日");
}
int main()
{
ClearFile();
Date Oly day(2008,8,8);
Oly_day+=3;
Oly_day.print();
return 0;
}
选项
答案
(1)添加语句:int year,month,day; (2)添加语句:year=y;month=m;day=d; (3)添加语句:Date&operator+=(int m) (4)添加语句:cout<
解析
(1)题目1要求“定义私有成员变量year、month、day”。在C++程序的private区域中添加变量year、month、day的定义,即在第1个标识下添加“int year,month,day;”。
(2)题目2要求“完成构造函数,分别给year、month、day赋值”。在程序中“Date(int y,int m,int d)”的构造函数中添加给year、month、day赋值的语句,即在第2个标识下添加“year=y;month=m;day=d;”。
(3)题目3要求“完成重载符号“+=”的定义”。在C++中,运算符重载的定义方法是定义一个重载运算符的函数,格式为函数operator+重载运算符号+,所以这里补全“Date&operator+=(int m)”。
(4)题目4要求“完成函数print()打印函数”。在C++中的print()函数中补全其打印功能,即在第四个标识下添加“cout<
转载请注明原文地址:https://kaotiyun.com/show/tDAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面对静态数据成员的描述中,正确的是()。
有如下程序:#include<iostream>#include<iosream>usingnamespacestd;classBASE{charc;public;BASE(charn):c(n){
有以下程序:#include<iostream.h>voidmain(){intx=5,y=2;cout<<!(y==x/2)<<",";cout<<y!=x%3)<<",";
下列语句中,输出与众不同的是
以下程序不用第三个变量实现将两个数进行对调的操作,划线处应为main(){inta,b;scanf("%d%d",&a,&B).;cin>>a>>b;cout<<"a="<<a
设有如下关系表:则下列操作中正确的是
在链表的运算过程中,能够使空表与非空表的运算统一的结构是______。
软件工程的框架可概括为:目标、过程和【 】。
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
下列关于关系运算的叙述中正确的是()。
随机试题
5岁,女,反复呼吸道感染1个月。1周前体检时白细胞7×109/L,中性粒细胞0.6,淋巴细胞0.4,血红蛋白100g/L,IgA0.1g/L,LgG12g/L,IgM0.1g/L。可考虑为
患者男,9岁。因“发现双颈部包块1个月余”入院。患儿近1个月来双颈部包块,进行性增大,以左侧为甚,无发热、咳嗽、胸闷、腹痛、乏力、消瘦、盗汗等症状。入院查胸片,肝脾B超均未见异常,颈部淋巴结活检病理报告:霍奇金病(淋巴细胞为主型),骨髓活检示幼稚淋巴细胞占
女性,54岁,反复尿频尿急4个月,3天来症状加重伴腰痛,尿检示白细胞5~20/HP,红细胞10~25/HP,蛋白0.3克/升,夜尿增多,晨尿比重为1.010,pH值6.7;最可能的诊断是女性,23岁,突发尿急,尿痛伴肉眼血尿1天,寒战高热,恶心,体温3
关于糖异生生理意义的错误叙述是
建设项目负责人的权力通常涉及()等方面。
A、 B、 C、 D、 A题干图形组成相似,但不完全相同,从第一组后两个图形可知考查的是小图形的移动,解题的关键是将每组第一个图形看成两个相互重叠的小图形。第一组图形中是两个重叠的方框分别向两边移动后得到第二
欧盟现有26个成员国,人口6亿,GDP超过16万亿美元,是全球最大的经济体。()
【2009年山西省第109题】甲班有42名学生,乙班有48名学生,在某次数学考试中按百分制评卷,评卷结果两个班的数学总成绩相同,平均成绩都是整数,且都高于80分。请问甲班的平均分与乙班相差多少分?
Inordertogetnamesofschoolboys(SEX=’M’)whoseage=22,fromarelationS(SNO,SNAME,SEX,AGE),whichofthefollowingexpression
Howdidthenameof"computervirus"comeintobeing?
最新回复
(
0
)