欢迎来到天天文库
浏览记录
ID:40526019
大小:76.00 KB
页数:9页
时间:2019-08-04
《C++第六次作业》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++第六次作业4.13#include#include#include#include#includetypedefstructelem{charc;structelem*next;}elem;elem*p,*t;classList{private:elem*head;public:List(){head=newelem;assert(head!=NULL);head->next=NULL;};voidinsertlist(char&c){p=newelem
2、;assert(p!=NULL);p->c=c;t=head->next;head->next=p;p->next=t;};voidprintlist(){p=head;cout<<"Thelist:"<next!=NULL){cout<next->c<<'';p=p->next;}cout<next;returnp->c;}};voidmain(){Li
3、stl;charc;intk;cout<<"请初始化链表(5个元素):"<>c;l.insertlist(c);}system("cls");cout<<"所建链表为:"<>k;printf("list[%d]为:",k);cout<classComplex{public:Complex(double=0.0,dou
4、ble=0.0);~Complex(){};friendostream&operator<<(ostream&output,constComplex&C2){output<>(istream&input,Complex&C2){input>>C2.real>>C2.imaginary;returninput;}Complexoperator*(constComplex&)const;booloperator==(constC
5、omplex&)const;booloperator!=(constComplex&)const;private:doublereal;doubleimaginary;};//#endif//COMPLEX1.CPP//定义类Complex的成员函数#include//#include"complex.h"//构造函数Complex::Complex(doubler,doublei){real=r;imaginary=i;}//重载的乘运算符ComplexComplex::operator*(constComplex&C2)const{C
6、omplexresult;result.real=real*C2.real-imaginary*C2.imaginary;result.imaginary=real*C2.imaginary+imaginary*C2.real;returnresult;}//重载==运算符boolComplex::operator==(constComplex&C2)const{if(real==C2.real&&imaginary==C2.imaginary)returntrue;returnfalse;}//重载!=运算符boolComplex::operator!=(co
7、nstComplex&C2)const{if(real==C2.real&&imaginary==C2.imaginary)returnfalse;returntrue;}//测试程序//#include//#include"complex1.h"voidmain(){ComplexC0,C1(3,4),C2(2,4),C3(3,4);cout<<"请输入C0:"<>C0;cout<<"C0="<8、ndl;C0=C1*C2
8、ndl;C0=C1*C2
此文档下载收益归作者所有