写出下列程序的执行结果是:__________________。#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 << "," <
写出下列程序的执行结果是:__________________。#include using namespace std;class T{ public : T() { a = 0; b = 0; c = 0; } T( int i, int j, int k ) { a = i; b =j; c = k; } void get( int &i, int &j, int &k ) { i = a; j = b; k = c; } T operator* ( T obj );private: int a , b , c;};T T::operator* ( T obj ){ T tempobj; tempobj.a = a * obj.a; tempobj.b = b * obj.b; tempobj.c = c * obj.c; return tempobj;}void main(){ T obj1( 1,2,3 ), obj2( 5,5,5 ), obj3; int a , b , c; obj3 = obj1 * obj2; obj3.get( a, b, c ); cout<<"(obj1*obj2):"<<"a="<
下面程序的运行结果如下: B::display() C::display() 在下划线处填上缺少的部分。源程序如下:#includeusing namespace std;class B{public: _________________ void display( ) {cout << "B::display( ) "<display();}void main(){ B b,*pb; C c; pb=&b; fun(pb); pb=&c; fun(pb);}