没有合适的资源?快使用搜索试试~ 我知道了~
大数加、减、乘、除、取余运算
5星 · 超过95%的资源 需积分: 50 21 下载量 115 浏览量
2013-03-31
18:51:15
上传
评论
收藏 6KB TXT 举报
温馨提示
试读
9页
整数的加、减、乘、除、取余操作中,对于减操作,只要看作是将减数改变了符号的加操作即可;乘和整数操作结果的符号只是对两个操作数做异或操作;取余操作的符号取决于被取余数值得符号。
资源推荐
资源详情
资源评论
#include<iostream>
using namespace std;
const int BYTENUM=200;
string add(string a,string b);
string sub(string a,string b);
string mul(string a,string b);
string div(string a,string b);
string mod(string a,string b);
#ifndef HEADER_ATOI
#define HEADER_ATOI
class Deal
{
public:
string add(const string& a,const string& b);
string sub(const string& a,const string& b);
string mul(const string& a,const string& b);
string div(const string& a,const string& b);
string mod(const string& a,const string& b);
};
#endif
//BigInt.cpp
//========
#include"BigInt.h"
#include<iostream>
using namespace std;
using namespace std;
const int BYTENUM=200;
string add(string a,string b);
string sub(string a,string b);
string mul(string a,string b);
string div(string a,string b);
string mod(string a,string b);
#ifndef HEADER_ATOI
#define HEADER_ATOI
class Deal
{
public:
string add(const string& a,const string& b);
string sub(const string& a,const string& b);
string mul(const string& a,const string& b);
string div(const string& a,const string& b);
string mod(const string& a,const string& b);
};
#endif
//BigInt.cpp
//========
#include"BigInt.h"
#include<iostream>
using namespace std;
int main()
{
int n=1;
char ch;
for(string a,b;cin>>ch&&ch!='@';n++)
{
cin>>a>>b;
string aa(a[0]=='-'?a.substr(1):a);
string bb(b[0]=='-'?b.substr(1):b);
if(aa[0]=='0'&&aa.length()>1)
{
cout<<n<<" "<<"Illegal Number"<<endl;
continue;
}
if(bb[0]=='0'&&bb.length()>1)
{
cout<<n<<" "<<"Illegal Number"<<endl;
continue;
}
Deal d;
switch(ch)
{
case'-':cout<<n<<" "<<d.sub(a,b)<<endl;break;
case'+':cout<<n<<" "<<d.add(a,b)<<endl;break;
case'*':cout<<n<<" "<<d.mul(a,b)<<endl;break;
case'/':
if(b=="0")
cout<<n<<" "<<"Divide By Zero.\n";
else
cout<<n<<" "<<d.div(a,b)<<endl;
{
int n=1;
char ch;
for(string a,b;cin>>ch&&ch!='@';n++)
{
cin>>a>>b;
string aa(a[0]=='-'?a.substr(1):a);
string bb(b[0]=='-'?b.substr(1):b);
if(aa[0]=='0'&&aa.length()>1)
{
cout<<n<<" "<<"Illegal Number"<<endl;
continue;
}
if(bb[0]=='0'&&bb.length()>1)
{
cout<<n<<" "<<"Illegal Number"<<endl;
continue;
}
Deal d;
switch(ch)
{
case'-':cout<<n<<" "<<d.sub(a,b)<<endl;break;
case'+':cout<<n<<" "<<d.add(a,b)<<endl;break;
case'*':cout<<n<<" "<<d.mul(a,b)<<endl;break;
case'/':
if(b=="0")
cout<<n<<" "<<"Divide By Zero.\n";
else
cout<<n<<" "<<d.div(a,b)<<endl;
剩余8页未读,继续阅读
资源评论
- liboloy2013-06-19很好,很实用,就是位数少了点。
- fIuent2015-11-20感谢楼主分享,值得借鉴!!!
u010109535
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功