题目内容

写出下列程序的执行结果是:__________________。#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);}

在下划线处填上缺少的部分。#include#includeusing namespace std;class complex{public:int real;int imag;complex(int r=0,int i=0){real=r;imag=i;}};complex operator+( ________________________,complex& b){int r=a.real+b.real;int i=a.imag+b.imag;return complex(r,i);}void main( ){complex x(1,2),y(3,4),z;z=x+y;cout<

有如下程序:#includeusing namespace std;class Wages{ //"工资"类 double base; //基本工资 double bonus; //奖金 double tax; //税金public: Wages(double CBase,double CBonus,double CTax): base(CBase),bonus(CBonus),tax(CTax){} double getPay()const; //返回应付工资额 Wages operator+(Wages w)const; //重载加法};double Wages::getPay()const{return base+bonus-tax;}Wages Wages::operator+(Wages w)const{ return Wages(base+w.base, bonus+w.bonus,tax+w.tax);}int main(){ Wages w1(2000,500,100),w2(5000,1000,300); cout<<(w1+w2).getPay()<

如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补充完整。#include#include#includeusing namespace std;class PhoneNumber{public: void setNumber(string number){this->number=number;}//重载流插入操作符 friend (ostream &output,const PhoneNumber &num) {output<

答案查题题库