手机版

程序设计基础实验报告(6)

时间:2025-07-14   来源:未知    
字号:

case 2:outfile<<"to:";break; case 3:outfile<<"subject:";break; case 4:outfile<<"body:";break; default:cout<<"error!\n";exit(0); } state=0; infile.get(); while(infile.peek()!='<') { infile.get(ch); outfile.put(ch); } outfile<<endl; } } } cout<<"Convert correctly!"<<endl; }

测试数据(输入、输出)

第3_2题

算法描述:

设计一个复数类型,输入实部和虚部生成一个复数,可进行两个复数求和、两个复数求差、两个复数求积运算。 源程序: No3_2.cpp

#include<iostream.h> class complex {

public: complex(){set(0.0,0.0);} complex(double real, double imag){set(real,imag);} void set(double r, double i){real=r;imag=i;} friend complex operator +(const complex &c1,const complex &c2); friend complex operator -(const complex &c1,const complex &c2); friend complex operator *(const complex &c1,const complex &c2); void print(); private: double real, imag; };

void complex::print() { if(imag<0) cout<<real<<imag<<"i"<<endl; else cout<<real<<"+"<<imag<<"i"<<endl; }

complex operator +(const complex &c1,const complex &c2) { return complex(c1.real+c2.real,c1.imag+c2.imag); }

complex operator -(const complex &c1,const complex &c2) { return complex(c1.real-c2.real,c1.imag-c2.imag); }

complex operator *(const complex &c1,const complex &c2) { return complex(c1.real*c2.real-c1.imag*c2.imag, c1.real*c2.imag+c1.imag*c2.real); }

void main() { complex a,b,c; double r,i; cout<<"Complex a:\n";

程序设计基础实验报告(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)