c++题库编程题 下载本文

共享知识 分享快乐

Point(float a=0,float b=0,float c=0):x(a),y(b),z(c){} Point operator ++(); Point operator --(); Point operator ++(int); Point operator --(int); void show() { cout<<\ <<\ } };

Point Point::operator ++() { return Point(++x,++y,++z); }

Point Point::operator --() { return Point(--x,--y,--z); }

Point Point::operator ++(int) { Point temp; temp.x=x++; temp.y=y++; temp.z=z++; return temp; }

Point Point::operator --(int) { Point temp; temp.x=x--; temp.y=y--; temp.z=z--; return temp; }

void main() { Point a(1,1,1),b(2,2,2),c,d; cout<<\ a.show(); cout<<\ b.show(); cout<

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

cout<<\ cout<<\ c.show(); cout<

#include using namespace std; class Complex { float real,image; public: Complex(float a,float b):real(a),image(b){} Complex(){} friend bool operator ==(Complex &x,Complex &y) {return (x.real==y.real&&x.image==y.image);} };

void main() { Complex Cp1(1,2),Cp2(3,4),Cp3(1,2); cout<<(Cp1==Cp2)<

书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚

共享知识 分享快乐

#include using namespace std; class Complex { float real,image; public: Complex(float x,float y):real(x),image(y){} Complex(){} Complex operator +(Complex &a) {return Complex(real+a.real,image+a.image);} Complex operator -(Complex &b) {return Complex(real-b.real,image-b.image);} friend ostream & operator <<(ostream &output,Complex &c) { output<<'('<

void main() { Complex Cp1(1,-2),Cp2(2,5),Cp3,Cp4; Cp3=Cp1+Cp2; Cp4=Cp1-Cp2; cout<| 举报本页文档 All rights reserved Powered by 南京廖华答案网 
资料来自互联网, 有任何疑问,请联系客服:779662525☒qq.com 苏ICP备200033号-4