半年学习以来写的最长的程序,但是还有错误
2009-06-24 21:49
344 查看
#include <iostream>
using namespace std ;
class Complex
{
public:
Complex()
{
real=0 ;
imag=0 ;
}
Complex(int r , double im) : real(r) , imag(im) {}
friend Complex operator + (const Complex & , const Complex &) ;
friend Complex operator - (const Complex & , const Complex &) ;
friend Complex operator * (const Complex & , const Complex &) ;
friend Complex operator / (const Complex & , const Complex &) ;
void display ()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl ;
}
private:
int real ;
double imag ;
}
Complex operator + (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real + c2.real ;
c.imag = c1.imag + c2.imag ;
return c ;
}
Complex operator - (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real - c2.real ;
c.imag = c1.imag - c2.imag ;
return c ;
}
Complex operator * (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real*c2.real) - (c1.imag*c2.imag) ;
c.imag = (c1.imag*c2.real) + (c1.real*c2.imag) ;
return c ;
}
Complex operator / (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real * c2.real + c1.imag * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
c.imag = (c1.imag * c2.real - c1.real * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
return c ;
}
int main ()
{
Complex a(3 , 4) , b(5 , 10) , c ;
c = a + b ;
cout<<"a + b = "
c.display() ;
c = a - b ;
cout<<"a - b = "
c.display() ;
c = a * b ;
cout<<"a * b = "
c.display() ;
c = a / b ;
cout<<"a / b = "
c.display() ;
return 0 ;
}
--------------------Configuration: myfirst - Win32 Debug--------------------
Compiling...
myfirst.cpp
D:\myfirst\myfirst.cpp(12) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
myfirst.obj - 1 error(s), 0 warning(s)
using namespace std ;
class Complex
{
public:
Complex()
{
real=0 ;
imag=0 ;
}
Complex(int r , double im) : real(r) , imag(im) {}
friend Complex operator + (const Complex & , const Complex &) ;
friend Complex operator - (const Complex & , const Complex &) ;
friend Complex operator * (const Complex & , const Complex &) ;
friend Complex operator / (const Complex & , const Complex &) ;
void display ()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl ;
}
private:
int real ;
double imag ;
}
Complex operator + (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real + c2.real ;
c.imag = c1.imag + c2.imag ;
return c ;
}
Complex operator - (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = c1.real - c2.real ;
c.imag = c1.imag - c2.imag ;
return c ;
}
Complex operator * (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real*c2.real) - (c1.imag*c2.imag) ;
c.imag = (c1.imag*c2.real) + (c1.real*c2.imag) ;
return c ;
}
Complex operator / (const Complex &c1 , const Complex &c2)
{
Complex c ;
c.real = (c1.real * c2.real + c1.imag * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
c.imag = (c1.imag * c2.real - c1.real * c2.imag) / (c2.real * c2.real + c2.imag * c2.imag) ;
return c ;
}
int main ()
{
Complex a(3 , 4) , b(5 , 10) , c ;
c = a + b ;
cout<<"a + b = "
c.display() ;
c = a - b ;
cout<<"a - b = "
c.display() ;
c = a * b ;
cout<<"a * b = "
c.display() ;
c = a / b ;
cout<<"a / b = "
c.display() ;
return 0 ;
}
--------------------Configuration: myfirst - Win32 Debug--------------------
Compiling...
myfirst.cpp
D:\myfirst\myfirst.cpp(12) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
myfirst.obj - 1 error(s), 0 warning(s)
相关文章推荐
- 18.02.11,web学习第五十七天,还有半年,努力吧青年 bos第三天 easyUI messager,menubutton菜单,validatebox,web-INF内页面访问
- exe中用new一块内存,但是在dll程序中delete引发的错误
- DLL中用malloc分配了一块内存,但是在exe程序中释放引发的错误可能原因
- 【Java学习】命令行下编译java程序,出现错误:编码GBK的不可映射字符
- win7系统iis部署好,但是程序运行后页面报错“HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效。“
- 已成功与服务器建立连接 但是在登录过程中发生错误。 provider 共享内存提供程序 error 0 管道的另一端上无任何进程。
- DLL中用malloc分配了一块内存,但是在exe程序中释放引发的错误:其原因可能是堆被损坏,这也说明 **.exe 中或它所加载的任何 DLL 中有 bug
- C++ Primer 学习笔记_89_用于大型程序的工具 -错误处理[续2]
- Android程序自动退但是没有提示任何错误
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
- 已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程。)
- 【微信小程序】图片可以加载成功,但是控制台报渲染层网络层错误
- [原创]java WEB学习笔记71:Struts2 学习之路-- struts2常见的内建验证程序及注意点,短路验证,非字段验证,错误消息的重用
- DLL中用malloc分配了一块内存,但是在exe程序中释放引发的错误:其原因可能是堆被损坏,这也说明 **.exe 中或它所加载的任何 DLL 中有 bug。
- 已成功与服务器建立连接 但是在登录过程中发生错误。 provider 共享内存提供程序 error 0 管道的另一端上无任何进程。
- ArcGIS API for Flex制作程序发布后出现错误:"访问 URL 时遇到安全性错误" 解决办法尝试(学习笔记)
- 18.01.20,web学习第四十二天,还有半年,努力吧青年 struts2第四天 拦截器和
- RunLoop学习笔记,从CF层面了解由于CFRunLoopMode机制iOS程序ScrollView的滑动为何如此平滑的原因。还有介绍AFNetworking如何单独发起一个global threa
- 一个非常非常非常基础的程序,写的不好,但是一般的文件读写操作及字符处理函数都涉及到了..新手学习用的
- SQL2008R2 已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程。)