📄 subject_64874.htm
字号:
<p>
序号:64874 发表者:Cxt_ann 发表日期:2003-12-13 20:23:50
<br>主题:大家帮忙看一下啊!!
<br>内容:哪里不对??<BR>/* 题目:<BR> * 定义一个大整数类型,<BR> * 重载四个符号 + - * /,<BR> * 分别进行两个大整数的加减乘除运算,<BR> * 输入输出要用友元函数来定义 <BR> */<BR><BR>//bigint.h<BR><BR>#ifndef BIGINT_H_<BR>#define BIGINT_H_<BR><BR>#include <iostream.h><BR>//using namespace std;<BR><BR>class Int<BR>{<BR>private:<BR> long num;<BR> <BR>public:<BR> Int ();<BR> Int operator+ ( const Int & t ) const;<BR> Int operator- ( const Int & t ) const;<BR> Int operator* ( const Int & t ) const;<BR> Int operator/ ( const Int & t ) const;<BR> <BR> friend istream & operator>> ( istream & is, const Int & t )<BR> {<BR> is >> t.num;<BR> return is;<BR> }<BR><BR> friend ostream & operator<< ( ostream & os, const Int & t )<BR> {<BR> os << t.num;<BR> return os;<BR> }<BR>};<BR><BR>#endif<BR><BR>//bigint.cpp<BR><BR>#include "bigint.h"<BR>#include <iostream.h><BR><BR>Int :: Int ()<BR>{<BR> num = 0;<BR>}<BR><BR>Int Int :: operator+ ( const Int & t ) const <BR>{<BR> Int temp;<BR> temp.num = num + t.num;<BR> return temp;<BR>}<BR><BR>Int Int :: operator- ( const Int & t ) const<BR>{<BR> Int temp;<BR> temp.num = num - t.num;<BR> return temp;<BR>}<BR><BR>Int Int :: operator* ( const Int & t ) const<BR>{<BR> Int temp;<BR> temp.num = num * t.num;<BR> return temp;<BR>}<BR><BR>Int Int :: operator/ ( const Int & t ) const<BR>{<BR> Int temp;<BR> temp.num = num / t.num;<BR> return temp;<BR>}<BR><BR>//usebigint.cpp<BR><BR>#include <iostream.h><BR>//using namespace std;<BR>#include "bigint.h"<BR><BR>int main()<BR>{<BR> Int A;<BR> Int B;<BR> Int temp;<BR><BR> cout << "Please input number1: ";<BR> cin >> A;<BR> cout << "Please input number2: ";<BR> cin >> B;<BR><BR> temp = A + B;<BR> cout << "Number1 + Number2 = " << temp << endl;<BR><BR> temp = A - B;<BR> cout << "Number1 - Number2 = " << temp << endl;<BR><BR> temp = A * B;<BR> cout << "Number1 * Number2 = " << temp << endl;<BR><BR> temp = A / B;<BR> cout << "Number1 / Number2 = " << temp << endl;<BR> cout << "Done!\n";<BR> <BR> return 0;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:红苹果 回复日期:2003-12-14 00:13:10
<br>内容:主要是两个友元函数有错:<BR>1. 友元函数应该是在类中说明、类外定义。<BR>2. operator>> ( ostream & os, const Int & t )的第二个参数不能是const的,它要用来接受数据。<BR>修改后的代码看附件:<BR><BR>2003-12-14 13:07:49
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -