题目内容

写出下列程序的执行结果是:__________________。#include using namespace std;class Bclass{ public: Bclass( int i, int j ) { x = i; y = j; } virtual int fun() { return 0 ; }protected: int x, y ;};class Iclass:public Bclass{ public : Iclass(int i, int j, int k):Bclass(i, j) { z = k; } int fun() { return ( x + y + z ) / 3; }private : int z ;};void main(){ Iclass obj( 2, 4, 10 ); Bclass p1 = obj; cout << p1.fun() <<","; Bclass &p2 = obj ; cout << p2.fun() <<","; cout << p2.Bclass :: fun() <<","; Bclass *p3 = &obj; cout << p3 -> fun() << endl;}

查看答案
更多问题

写出下列程序的执行结果是:__________________。#include using namespace std;const double n = 1.852; // 定义海里与千米和米的转换系数(1海里=1.852千米)class nauticalmile_kilometer{ public: nauticalmile_kilometer( int km,double m ) { kilometer = km; meter = m; } void print() { cout<<"kilometer="<

写出下列程序的执行结果是:__________________。#include #includeclass s{ public: s(){ *str= '\0'; } s( char *pstr ) { strcpy( str,pstr ); } char *gets() { return str; } friend s operator+( s obj1,s obj2 );private: char str[100]; };s operator+( s obj1,s obj2 ){ s tempobj; strcat( tempobj.str,obj1.str ); strcat( tempobj.str,obj2.str ); return tempobj; }void main(){ s obj1( "Visual" ),obj2( "C#" ),obj3; obj3 = obj1 + obj2; cout << obj3.gets() << endl;}

写出下列程序的执行结果是:__________________。#include #includeusing namespace std;class s{ public: s(){ *str = '\0'; } s( char *pstr ) { strcpy( str,pstr ); } char *gets() { return str; } s operator+( s obj );private: char str[10]; };s s::operator+( s obj ){ strcat( str,obj.str );return str; //或return *this } void main(){ s obj1( "Visual"),obj2("C++"),obj3; obj3 = obj1 + obj2; cout << obj3.gets() << endl;}

写出下列程序的执行结果是:__________________。#include class Vector{ public: Vector(){ } Vector(int i,int j) { x = i ; y = j ; } friend Vector operator+ ( Vector v1, Vector v2 ) { Vector tempVector ; tempVector.x = v1.x + v2.x ; tempVector.y = v1.y + v2.y ; return tempVector ; } void display() { cout << "(" << x << "," <

答案查题题库