首页/ 题库 / [单选题]有以下程序: Class Date {p的答案

有以下程序: Class Date {public: Date(int y,int m,int d); {year=y; month=m; day=d;} Date(int y=2000) {year=y; month=10; day=1;) Date(Date &D) {year=d.year; month=d.month; day=d.day;} void print() {cout<<year<<“.”<<mo

单选题
2022-01-02 04:00
A、2
B、3
C、4
D、5
查看答案

正确答案
B

试题解析
解析: 本题拷贝构造函数一共被调用了3次:第一次是在执行语句Date date3(date1);时,用已经建立的对象date1对正在建立的对象date3进行初始化;第二次是在调用fun函数时,由于是传住调用,因此实参对象date3要对形参对象d进行初始化,第三次是在执行fun函数中的返回语句returntemp;时,系统用返回初始化一个匿名对象时使用了拷贝构造函数。

标签:
感兴趣题目
有以下程序: #include <iostream> using namespace std; static int days[]={ 31,28,31,30,31,30,31,31,30,31,30,31 }; class date { private: int month,day,year; public: date( int m,int d,int y ) { month = m; day = d; year = y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+( iht day ) { date dt = * this; day += dt.day; while ( day > days[ dt.month - 1 ] ) { day -= days[ dt.month - 1 ]; if ( ++dt.month == 13 ) { dt.month = 1; dt.year++; } } dt.day = day; return dt; } }; int main() { date dl( 6, 20, 2004 ), d2; d2 = dt + 20; d2.disp(); return 0; } 执行后的输出结果是( )。
有以下程序: Class Date { public: Date(int y,int m,mt d); { year=y; month=m; day=d; } Date(int y=2000) { year=y; month=10; day=1; } Date(Date &D) { year=d.year; month=d.month; day=d.day; } Void prin
能将程序补充完整的选项是 class Person { private int a; public int change(int m){return m; } } public class Teacher extends Person { public int b; public static void main(String arg[]) { Person p=new Person(); Teacher t=new Teacher(); int i; ______ } }
能将程序补充完整的选项是 class Person { private int a; public int change(int m){return m;} } public class Teacher extends Person { public int b; public static void main(String arg[]) { Person p=new Person(); Teacher t=new Teacher(); int i; _____ } }
有如下程序: #include <iostream> using namespace std; class shapes { protected: int x, y; public: void setvalue(int d, int w=O) { x=d; y=w; } virtual void disp()=O; }; class square : public shapes { public: void disp () { cout<<x*y<<end1; } }; int main ( ) { shapes *ptr; square s1; ptr=&s1; ptr->setvalue (10, 5) ;ptr->disp(); return 0; } 执行上面的程序将输出( )。
若有以下定义和语句 union date { int i; char c; fioat f;} x; int y; 则以下语句正确的是______。
有以下程序: #include<iostream> using namespace std; #definePl 3.14 Class Point {private: int x,y; public: Point(int a,intB) {X=a; y:b;} int getx() <return x;} int gety() {return y;}}; class Circle:public Point {pri
运行下面的程序时,会产生( )。 public class Test{ public static void main(String args[ ] ) { int x =0; int y = 2/x; int z[ ] = {1,2,4,6}; int p=z[4]; } }
下列程序段中,正确的是______。 ①class MvClass { int var = 100; static int getVar() { return var; } } ②public class MyClass { final int date; void MyClass (int d) { date = d; } } ③public class MyMain { public static void main(String args[]) { System.out.println(Myclass1.date); } } class MyClass1 { int data = 10; } ④class IamAbstract { final int f; double d; abstrct void method(); }
若有以下程序:#include<iostream>using namespace std;class A {private: int x;public: int z; void setx(int i) { x=i; } int getx () { return x; }}:class B : public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a) ; z=b; m=c; } void display{) { cout<<getx ()<<", "<<z<<", "<<m<<end1; }};int main(){ B obj; obj. setvalue(2,3,4); obj.display(); return 0;} 程序运行以后的输出结果是
若有以下程序:#include <iostream>using namespace std;class A{private: int x;public: int z; void setx(int i) { x=i; } int getx() { return x; }};class B: public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a); z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; }};int main(){ B obj; obj.setvalue(2,3,4); obj.display(); return 0;程序运行以后的输出结果是( )
若有以下程序: #include 〈iostream〉 using namespace std; class A { private: int x; public: int z; void setx(int i) { x=i; } int getx () { return x; } }; class B : public A { private: int m; public: int p; void setvalue(int a,int b, int C) { setx (A) ; z=b; m=c; } void display() { cout〈〈getx()〈〈","〈〈z〈〈","〈〈m〈〈end1; } }; int main ( ) { B obj; obj.setvalue(2,3,4); obj.display(); return 0; } 程序运行以后的输出结果是( )。
相关题目
以下程序的运行结果为( )#include main(){struct date{int year,month,day;}today; printf(%d ,sizeof(struct date));}
有如下类说明: class TestClass{ int x; public: TestClass(int n){x=n;} }; class TestClass1:public TestClass{ int y; public: TestClass1(int a,int b); }; 在构造函数TestClass1的下列定义中,正确的是( )。
有如下类声明: class XA { int x; public: XA(int n){x=n;} }; class XB:public XA { int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:public XA{ int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是( )。
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:publicXA{ int y; public: XB(int a,int b); ); 在构造函数XB的下列定义中,正确的是( )。
有如下类声明: class XA{ int x; public: XA(int n){x=n;} }; class XB:public XA{ int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是( )。
若有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int B) { x=a; y=b; } int getx() { return x; } int gety() { reurn y; } }; class Circle: public Point { private: int r; public: Circle(int a,int b.int C) :Point(a,B) r=c; int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle cl(5,7,10); cout<<c 1 .area()<<end1; return 0; } 程序执行后的输出结果是
若有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a, int b,int c) :Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<c1.area()<<end1; return 0; } 程序执行后的输出结果是( )。
有以下程序: Class Date {public: Date(int y,int m,int d); {year=y; month=m; day=d;} Date(int y=2000) {year=y; month=10; day=1;) Date(Date &D) {year=d.year; month=d.month; day=d.day;} void print() {cout<<year<<“.”<<mo
设有以下定义: typedef union {long i;int k[5];char c,}DATE, struct date {int cat;DATE cow;double dog;}too; DATE max; 则下列语句的执行结果是( ) printf("%d",stzeof(struct date)+sizeof(max));
设有以下说明和定义: typedef union {long i int k[5];char c;}DATE; struct date {int cat;DATE cow;double dog;}too; DATE max; 则下列语句的执行结果是 ( ) printf("%d",sizeof(struet date)+sizeof(max));
有以下程序: class Date { public: Date(int y, int m, int d); year = y; month = m; day = d; Date(int y = 2000) year = y; month = 10; day = 1; Date(Date &d) { year = d.year; month = d.month; day = a.day; } void print() cout<<year<<"."<<month<<"."<<day<<end1; } private: int year, month,day; }; Date fun(Date d) Date temp; temp = d; return temp; } int main() { Date date 1 (2000,1,1),date2(0,0,0); Date date3(date 1); date2 = fun(date3); return 0; } 程序执行时,Date 类的拷贝构造函数被调用的次数是
若有以下程序: #include <iostream> using namespace std; class point { private: int x, y; public: point ( ) { x=0; y=0; } void setpoint(int x1,int y1) { x=x1; y=y1;
有如下类定义: class Test { private int x; public int y; public void setX (int m) {x=m;} public int getX( ) {return x;} }现用Test t=new Text();生成一个对象t,则如下语句中,错误的是( )。
下面程序输出的结果是( )。 #include<iostream> using namespace std; class A{ int X; public: A(int x):x(++x){} ~A(){cout<<x;} }; class B:public A{ int y; public: B(int y):A(y),y(y){} ~B(){cout<<y;}; }; void main(){ B b(3); }
有以下程序 #include <iostream> using namespace std; static int days []={31,28.31,30,31,30,31,31,30,31,30,31}; class date { private: int month, day, year: public: date (int m, int d, int y { month = m; day = d; year = y; } date{} {} void disp {) { cout <<year<<" - "<<month<< "- "<<day<<end1; } date operator+(int day) { date dt = *this: day += dt.day; while { day > days[ dt.month - 1 ] ) { day -= tays[ dt.month - 1 ]; if ( ++dt.month == 13 { dt.month = 1; dt.yeare++; } } dr. day = day; return dt; } }; int main() { date d1( 6, 20, 2004 ), d2; d2.= d1 + 20; d2.disp (); return 0; } 执行后的输出结果是
有以下程序 #include<iostream> using namespace std; static int days []={31,28,31,30,31,30,3l,31,30,31,30,31}; class date { private: int month,day,year; public: date(int m,int d,int y) { month=m; day=d; year=y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+(int day) { date dt=*this; day+=dt.day; while(day>days[dt.month-1]) { day-=days[dt.month-1]; if(++dt.month==13) { dt.month=1; dt.year++; } } dt.day=day; retrn dt; } }; int main() { date d1(6,20,2004),d2; d2=d1+20; d2.disp(); return 0; } 执行后的输出结果是
有以下程序 #include <iostream> using namespace std; static int days[]= { 31,28,31,30,31,30,31,31,30,31,30,31 }; class date { private: int month, day, year; public: date( int m, int d, int y ) { month = m; day = d; year = y; } date() {} void disp() { cout<<year<<"-"<<month<<"-"<<day<<end1; } date operator+( int day ) { date dt = *this; day+= dt.day; while ( day > days[dt.month - 1 ] ) { day -= days[ dt.month - 1 ]; if ( ++dt.month == 13 ) { dt.month = 1; dt.year++; } } dt.day = day; return dt; }; int main() { date d1( 6, 20, 2004 ), d2; d2: d1 + 20; d2.disp(); return 0; } 执行后的输出结果是
有以下程序: class Date { public: Date(int y,int m,int d); { year = y; month = m; day = d; } Date(int y = 2000) { year = y; month = 10; day = 1; } Date(Date &d) { year = d.year; month = d.month; day = d.day; } void print() { cout<<year<<"."<<month<<"."<<day<<endl; } private: int year,month,day; }; Date fun(Date d) { Date temp; temp = d; resurn temp; } int main () { Date date1 (2000,1,1),date2 (0,0,0); Date date3 (date1); date2 = fun(date3); return 0; } 程序执行时,Date类的拷贝构造函数被调用的次数是
以下程序的运行结果是( )。 #include <stdio.h> main() { st,uct date {int year,month,day;}today; printf("%d ",sizeof(struct date)); }
广告位招租WX:84302438

免费的网站请分享给朋友吧