给定一个类及对象的定义,以下各选项中使用正确的是 。 class Time { private: int hour; int minute; public: int second; void set() {cin>>hour>>minute>>second;} void display() {cout<<hour<<minute<<second<<endl;} }t1, t2;A.t1.hour=10;B.t2.minute=20;C.t1.second=10;D.t1.set;

给定一个类及对象的定义,以下各选项中使用正确的是 。 class Time { private: int hour; int minute; public: int second; void set() {cin>>hour>>minute>>second;} void display() {cout<<hour<<minute<<second<<endl;} }t1, t2;

A.t1.hour=10;

B.t2.minute=20;

C.t1.second=10;

D.t1.set;


参考答案和解析
A

相关考题:

有如下类定义:class AA{int a;public:int getRef() const{return a;} // ①int getvalue() const{return a;} // ②void set(int n) const{a=n;} // ③friend void show(AA aa) const {cout // ④};其中的四个函数定义中正确的是A . ①B . ②C . ③D . ④

下列程序中的重载函数disp( )发生错误,错误原因是【 】。 includeclass Sample {priva 下列程序中的重载函数disp( )发生错误,错误原因是【 】。include<iostream, h>class Sample{private:int m;static int sr;public:Sample(int a) {m=a; st+=a; }static void disp(){cout<<m<<end1; }static void disp(Sample input){cout<<input. m<<end1;}};int Sample: : st=2;void main(){Sample Eirst(2), Second(4)Sample: :disp( );Sample: :disp (Second);}

在下面的类定义中,横线处应填入的内容是 class Fred { public: void print(){cout<<data<<endl;} void setData(double d)(data=d;} static int count; private: double data; }; count=0; //静态数据成员的定义A.intB.static intC.int Fred::D.static int Fred::

有以下程序:includeusing namespace std;class A{private:int a;public:A(int i){a=i 有以下程序: #include<iostream> using namespace std; class A {private: int a; public: A(int i) {a=i;} void disp() {cout<<a<<“,”;}}; class B {private: int b; public: B(int j) {b=j;} void disp() {cout<<b<<“,”;A.10,10,10B.10,12,14C.8,10,12D.8,12,10

下面这个程序的结果是includeclass A{private:int a;public:void seta();int geta( 下面这个程序的结果是 #include<iostream.h> class A { private: int a; public: void seta();int geta();}; void A∷seta() {a=1;} int A∷geta() {return a;} class B { pnvate: int a; publiC: void sera();int geta();}; void B∷seta() {a = 2;} int B∷geta() {return a;} class C:public A,public B { private: int b; public: void display();}; void C∷display() { int b=geta(); cout<<b;} void main() { C c; c.seta(); c.display();}A.1B.2C.随机输出1或2D.程序有错

已知如下类定义: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正确地加入子类中?() A.private void fun( int n ){ //...}B.void fun ( int n ){ //... }C.protected void fun ( int n ) { //... }D.public void fun ( int n ) { //... }

为使下列程序的正确输出结果为: Now is 2004-7-6 12:12:12 那么应该在程序划线处填入的语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } void DateTime(TIME t); private: int year,month, day; }; class TIME { public: TIME(int h=0,int m=0,int s=0) { hour=h; minute=m; second=s; } ______________; //将类 DATE 中成员函数 DateTime 声明为类 TIME 的友元函数 private: int hour,minute, second; }; void DATE: :DateTime(TIME t) { cout<<"Now is "<<year<<'-'<<month<<'-'<<day<< ' '<<t.hour<<":"<<t.minute<<': '<<t.seoond<<'.'<<end1; } int main ( ) { DATE d(2004,7,6); TIME t (12, 12, 12); d. DateTime (t); return 0; }A.friend void DateTime(TIME t);B.friend void DATE::DateTime(TIME 0;C.void DateTime(TIME t);D.friend void DateTime(TIME t);

下列程序的运行结果是【 】。 include class SomeClass { public: SomeClass(int va 下列程序的运行结果是【 】。include <iostream. h>class SomeClass{public:SomeClass(int value) { some_value=value;};void show_data(void) { cout<<data<<"<<~some_value<<endl; };static void set_data(int value) {data=value; }private:static int data;int some_value};int SomeClass::datavoid main(void){SomeClass my_class(1001),your_class(2002);your_class. set_data(4004);my_elass. show_data()}

下面程序的输出结果是【】。 include using namespace std; int x; void funA(int,i 下面程序的输出结果是【 】。include<iostream>using namespace std;int x;void funA(int,int);void funB(int,int);int main(){int first;int second=5;x=6;funA(first,seconD) ;fimB(first,seconD) ;cout<<first<<" "<<second<<" "<<x<<end1;return 0;}void funA(int a,int B){int first;first=a+b;a=2*b;b=first+4;}void funB(int u,int v){int second;second=x;v=second+4;x=u+v;}

有以下程序: include usingnamespacestd; classCFactorial { private:intvalue;intfac 有以下程序:include <iostream>using namespace std;class CFactorial{private:int value;int fact;public:CFactorial ( int val );void CalculateFactorial();void Display();};CFactorial :: CFactorial( int val ){value = val;fact = 1;}void CFactorial :: CalculateFactorial(){int i = value;while ( i > 1 )fact *= i--;}void CFactorial :: Display(){cout<<value<<"!="<<fact<<end1;}int main(){CFactorial A( 5 );A.CalculateFactorial();A.Display();return 0;}程序中,类CPactorial的功能是【 】,该程序运行的结果是【 】。

下面程序的输出结果是______。 include using namespace std; int x; void funA(int,int);void funB(int,int);int main(){int first;int second=5;x=6;funA(first,second);funB(first,second);cout<<first<<””<<second<<””<<x<<endl;return 0;}void funA(int a,int b){int first;first=a+b;a=2*b;b=first+4;}void funB(int u, int v){int second;second=x;v=second+4;x=u+v;}

为了使程序的输出的正确结果为: Now is 2004.7.10 10:10:10. 那么应在下列程序划线处填入的正确语句是( )。 那么应在下列程序划线处填入的正确语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } friend void DateTime(DATE d, TIME t); private: int year, month, day; }; class TIME { public: TIME(iht h=0, int m=0,int s=0) { hour=h; minute=m; second=s; } friend void DateTime(DATE d,TIME t); private: int hour,minute, second; }; ______________________ //函数 DateTime 的首部 { cout<<"Now is"<<d.year<<'.'<<d.month<<'.'<<d.day<< ' '<<t.hour<<":"<<t.minute<<':'<<t.second<<'.'<<end1; } int main ( ) { DATE d(2004,7,10); TIME t(10, 10, 10); DateTime(d,t); return 0; }A.void DateTime(DATE d,TIME t)B.void TIME::DateTime(DATE d,TIME t) constC.friend void DateTime(DATE d,TIME t)D.void DATE::DateTime(DATE d,TIME t)

下面这个程序的结果是 include class A { private: int a; public: void seta( ) ; 下面这个程序的结果是#include<iostream.h>class A{private:int a;public:void seta( ) ;int geta( ) ;};void A: :seta( ){ a=1;}int A: :geta( ){ retum a;}class B{ private:int a;public:void seta( ) ;int geta( ) ;};void B: :seta( ){a=2;}int B: :geta( ){return a;}class C: public A,public B{ private:int b;public:void display( ) ;};void C: :display( ){ int b=geta( ) ;cout < < b;}void main( ){ C c;c. seta( ) ;c. display( ) ;}A.1B.2C.随机输出1或2D.程序有错

以下程序的输出结果是_____。 include class object {private:int val; public:objec 以下程序的输出结果是_____。include<iostream.h>class object{ private:int val;public:object( ) ;object(int i) ;~object( ) ;};object: :object( ){ val=0;cout < < "Default constructor for object" < < endl;}object: :object(int i){ val=i;cout < < "Constructor for object" < < val < < endl;}object: :~object( ){ cout < < "Destructor for object" < < val < < endl;}class container{ private:object one;object two;int data;public:container( ) ;container(int i,int j,int k) ;~container( ) ;};container: :container( ){ data=0;cout < < "Default constructor for container" < < endl;}container: :container(int i,int j,int k) :two(i) ,one(j){ data=k;cout < < "Constructor for container" < < endl;}container: :~container( ){ cout < < "Destructor for container" < < endl;}void main( ){ container anObj(5,6,10) ;}

以下程序段共有错误()处。include using namespaces std;class Sample{private: int n 以下程序段共有错误( )处。 #include <iostream> using namespaces std; class Sample { private: int n; public: Sample(int i) { n=i; } void setvalue (int i) { n=i; } void display() { cout<<”n=”<<n<<endl; } }; int main() { const Sample a(10); a.setvalue(5); a.display(); return 0; }A.1B.2C.3D.4

有以下程序:include using namespace std;class A{private:int a;public:A (int i){a 有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A (int i) { a=i; } void disp() { cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp() { cout<<b<<","; } }; class C : public B,public A { private: int c; public: C(int k) :A(k-2),B(k+2) { c=k; } void disp () { A::disp (); B::disp (); cout<<c<<endl; } }; int main () { C obi (10); obj.disp (); return 0; } 程序执行后的输出结果是A.10,10,10B.10,12,14C.8,10,12D.8,12,10

下列程序的运行结果是______。include class Base { public: void f(int x){cout 下列程序的运行结果是______。include<iostream.h>class Base{public:void f(int x){cout<<“Base:”<<x<<endl;});class Derived:public Base{public:void f(char*str){cout<<“Derived:”<<str<<endl;}};void main(void){Base*pd=ne

下面程序的执行结果为 ‘ #include"iostream" using namespace std; class A { int a; public: void Sera(int x){a=x;} void Display_a(){cout<<a<<endl;} }; class B { int b; public: void Setb(int x){ b=x;} void Dispaly_b() {cout<<b<<endl;} }; class C:public A,private B { private: int c; public: void Setc(int x,int y,int z) { c=z;Sera(x);Serb(y);} void Display_c(){cout<<c<<endl;} }; ① void main() ② { ③ C cc; ④ cc.Seta(1); ⑤ cc.Display_a(); ⑥ cc.Setc(2,2,3); ⑦ cc.Dispaly_b(); ⑧ cc.Display_c(); }A.输出为2 2 3B.有错误在第5行C.输出为1 2 3D.有错误在第7行

若有以下程序:include using namespace std;class A{private:int a;public:A(im i){a 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A(im i) { a=i; } void disp() cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp0 { cout<<b<<","; } }; class C: public B,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp0 { A::disp(); B::disp(); cout<<c<<endl; } }; int main() { C obj(10); obj.disp(); return 0; } 程序执行后的输出结果是( )。A.10,10,10B.10,12,14C.8,10,12D.8,12,10

使用VC6打开考生文件夹下的工程test35_3。此工程包含一个test35_3.cpp,其中定义了时钟类clock,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)定义类clock的私有数据成员hour和minute,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。(2)补充完全类clock的构造函数,私有数据成员hour和minute分别初始化为参数h和m的值,请在注释“//**2**”之后添加适当的语句。(3)完成类clock的成员函数printtime,的定义,该函数以“Now the time is hour:minute”的格式输出数据成员hour和 minute的值,如hour=3、minute=59,则输出为“Now the time is 03:59”,请在注释“//**3**”之后添加适当的语句。(4)完成类clock的成员函数addoneminutetime的定义,该函数可将clock类对象表示的时间加一分钟,如现在hour=3、 minute=59,运行该函数后hour=4、minute=0。请在注释“//**4**”之后添加适当的语句。程序的输出结果如下:Now,the time is 12:59Now,the time is 13:00注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test35_3.cpp清单如下:include<iostream.h>class clock{private:// ** 1 **public:clock(int h, int m){// ** 2 **}int presenthour(){return hour;}int presentminute(){return minute;}void addoneminutetime();void printtime();};void clock::printtime(){if(hour<10) cout<<'0';// ** 3 **if(minute<10) cout<<'0';cout<<minute<<end1;}void clock::addoneminutetime(){// ** 4 **if(minute>59){minute-=60;hour++;}if(hour>23)hour=0;}void main ( ){clock c(12,59);c.printtime();c.addoneminutetime();c.printtime();}

使用VC6打开考生文件夹下的工程test15_3。此工程包含一个test15_3.cpp,其中定义了类Time和Timex,Timex公有继承Time,但定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类Time构造函数的定义,将数据成员hours和minutes分别初始化为参数new_hours和new_minutes的值。请在注释“//**1**”之后添加适当的语句。(2)完成类Timex的构造函数的定义,注意参数的传递。请在注释“//**2**”之后添加适当的语句。(3)请按时间格式“hour:minute”和“hour:minute:second”分别输出对象time1和time2所表示的时间,注意必须使用已经定义的成员函数。请在注释“//**3**”之后添加适当的语句。输出结果如下:20:3010:45:34注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件test15_3.cpp清单如下:include<iostream.h>class Time{public:Time(int new hours,int new_minutes){// ** 1 **}int get_hours();int get_minutes();protected:int hours,minutes;};int Time::get_hours(){return hours;}int Time::get_minutes(){return minutes;}class Timex:public Time{public:Timex(int new hours,int new_minutes,int new_seconds);int get_seconds();protected:int seconds;};// ** 2 **{seconds=new_seconds;}int Timex::get_seconds(){return seconds;}void main(){Time time1(20,30);Timex time2(10,45,34);// ** 3 **}

类time可以输出12小时或24小时制的时间,现需要设计一个缺省构造函数,缺省值为0时0分0秒。该缺省构造函数为______。include<iostream.h>class Time{int h,m,s;public:Time(int hour=0,int min=0,int sec=0){settime(hour,min,sec);}void settime(int hour,int min,int sec){h=hour;m=min;s=sec;}void show24( ){ cout<<(h<10?"0":"")<<h<<":"<<(m<10?"0":"")<<m<<":"<<(s<10?"0":"")<<s<<endl;}void showl2( ){ int temp=(h= =0 || h= =12)? 12:h%12;cout<<(temp<10?"0":"")<<temp<<":"<<(m<10?"0":"")<<m<<":"<<(s<10?"0":"")<<s<<((temp>0h<12)?"AM":"PM")<<endl;}};void main( ){Time t(15,43,21);t.showl2( );t.show24( );}

若有以下程序:includeusing namespace std;class A{private:int a; public:void seta 若有以下程序: #include<iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb() { cout<<b<<",”; } }; class C:pUblic A,private B { private: int c; public: void setc(int x,int y,int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main() { Cc; c.setc(1,2,3); c.showc(); retrun 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

若有以下程序:includeusing namespace std;class A{private:inta;public:voidseta(in 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb (int x) { b=x; } void showb() { cout<<b<<","; } }; class C :public A,private B { private: int c; public: void setc(int x, inc y, int z) { c=z; seta (x); setb (y); } void showc() { showa (); showb (); cout<<c<<end1; } }; int main () { C c; c. setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

若有以下程序:include using namespace std;class A{private:int a;public:A(int i){ 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: A(int i) { a=i; } void disp () { cout<<a<<","; } }; class B { private: int b; public: B(int j) { b=j; } void disp () { cout<<b<<","; } }; class C : public B,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp () { A::disp(); B::disp(); cout<<c<<endl; } }; int main() { C obj(10); obj.disp(); return 0; }A.10,10,10B.10,12,14C.8,10,12D.8,12,10

若有以下程序:include using namespace std;class A{private:int a;public:void seta 若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。A.1,2,3B.1,1,1C.2,2,2D.3,3,3

若有以下程序:inclideusing nameSpace std;class A{pricate: int a;public: A(int i) 若有以下程序: #inclide<iostream> using nameSpace std; class A { pricate: int a; public: A(int i) { a=i } Void disp() { cout<<a<<","; } }; clas B { private: int b; public: B(int j) { b=j; } Void disp() { cout<<b<<","; } }; class C:publicB,public A { private: int c; public: C(int k):A(k-2),B(k+2) { c=k; } void disp() { A::disp(); B::disp(); cout<<c<<endl; } }; int main() { C obj(10); obj.disp(); return 0; } 程序执行后的输出结果是A.10,10,10B.10,12,14C.8,10,12D.8,12,10

若有以下程序:includeusing namespace std;class A{private:int x;public:int z;void 若有以下程序:#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;} 程序运行以后的输出结果是A.产生语法错误B.2,3,4C.2,2,2D.4,3,2