⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 巨型整数类
💻 CPP
字号:

#include"head.h"

int main(){

	HugeInt n0("-12300982156758676"),n1(123214414L),n,n5;
	cout<<"执行HugeInt n0(\"-12300982156758676\");后n0的当前值为:"<<n0<<endl;
	cout<<"执行HugeInt n1(123214414L);后n1的当前值为:"<<n1<<endl;
    cout<<"n0+0L="<<n0+0L<<endl;
	cout<<"n0*0L="<<n0*0L<<endl;
	cout<<"n0-0L="<<n0-0L<<endl;
	if(n0!=n1) cout<<n0<<"!="<<n1<<endl;
	if(n0>n1) cout<<n0<<">"<<n1<<endl;
	if(n0==n1) cout<<n0<<"="<<n1<<endl;
	if(n0<n1) cout<<n0<<"<"<<n1<<endl;
	if(n0<=n1) cout<<n0<<"<="<<n1<<endl;
	if(n0>=n1) cout<<n0<<">="<<n1<<endl;

	cout<<"执行n0+n1得:"<<n0+n1<<endl;
	cout<<"执行n0-n1得:"<<n0-n1<<endl;
	cout<<"执行n0*n1得:"<<n0*n1<<endl;
	 n0+=n1;
	cout<<"执行n0+=n1后结果为:"<<n0<<endl;
	n0-=n1;
	cout<<"执行n0-=n1后结果为:"<<n0<<endl;
	n0*=n1;
	cout<<"执行n0*=n1后结果为:"<<n0<<endl;
	n0=-n0;
    cout<<"执行n0=-n0后结果为:"<<n0<<endl;
	n1=-n1;
	cout<<"执行n1=-n1后结果为:"<<n1<<endl;
	
	n1=-n0;
	cout<<"执行n1=-n0得:"<<n1<<endl;

	cout<<"\n\n按任意键...继续";
	getch();
	cout<<endl<<endl;

	HugeInt n3("-123456789009876543245678990");
	cout<<"执行HugeInt n3(\"-123456789009876543245678990\");\n后的n3为:";
	cout<<n3<<endl;
	HugeInt n2(n3);
	cout<<"执行HugeInt n2(n3)后n2为:"<<n2<<endl;

	HugeInt n4(-1213244613L);
	cout<<"执行HugeInt n4(-1213244613L)后的n4为:"<<n4<<endl;

	n=n2+1123456789L;
	cout<<"执行"<<n2<<"+1123456789L后的结果为:\n"<<n<<endl;

	n=n2-(-1234567123L);
	cout<<"执行"<<n2<<"-(-1234567123L)后的结果为:\n"<<n<<endl;

	n=n2*1234567890L;
	cout<<"执行n2*1234567890L后的结果为:\n"<<n<<endl;

	n5=n4+"-123456789009876543245678990";
	cout<<"执行"<<n4<<"+\"-123456789009876543245678990\";后n5为:"<<n5<<endl;

	n5=n4-("-1234567523641246513132100000000");
	cout<<"执行"<<n4<<"-(\"-1234567523641246513132100000000\");后n5为:"<<n5<<endl;

	n5=n4*"100012312310000000000000";
	cout<<"执行"<<n4<<"*\"100012312310000000000000\";后n5为:"<<n5<<endl;

	cout<<endl<<endl;
	cout<<"按任意键...继续";
	getch();
    cout<<endl<<endl;

	cout<<"n4的当前值为:"<<n4<<endl;
	cout<<"执行++n4后;n4的值为:"<<++n4<<endl;

	cout<<"执行n4++后n4的值为:"<<n4++<<endl;
	cout<<"n4的当前值为:"<<n4<<endl;
	cout<<"执行--n4后n4的值为:"<<--n4<<endl;
	cout<<"执行n4--后n4的值为:"<<n4--<<endl;
	cout<<"n4的当前值为:"<<n4<<endl;
//----------巨型与长整型比较----------------------//
	if(n4<0L) cout<<n4<<"<0L"<<endl;
	if(n4>-1934567890L) cout<<n4<<">-1934567890L"<<endl;
	if(n4==-1213244613L) cout<<n4<<"=-1213244613L"<<endl;
	if(n4>=-1213244613L) cout<<n4<<">=-1213244613L"<<endl;
    if(n4<=-1213244613L) cout<<n4<<"<=-1213244613L"<<endl;
	if(n4!=0L) cout<<n4<<"!=0L"<<endl;

//-----------巨型与字符串比较------------------//
	if(n4<"0") cout<<n4<<"<\"0\""<<endl;
	if(n4>"-1934567890") cout<<n4<<">\"-1934567890\""<<endl;
	if(n4=="-1213244613") cout<<n4<<"=\"-1213244613\""<<endl;
	if(n4>="-1213244613") cout<<n4<<">=\"-1213244613\""<<endl;
    if(n4<="-1213244613") cout<<n4<<"<=\"-1213244613\""<<endl;
	if(n4!="0") cout<<n4<<"!=\"0\""<<endl;

//---------字符串与长整型比较-----------------//
	if("0"<n4) cout<<n4<<"<\"0\""<<endl;
	if("-1934567890">n4) cout<<"\"-1934567890\">"<<n4<<endl;
	if("-1213244613"==n4) cout<<"\"-1213244613\"="<<n4<<endl;
	if("-1213244613">=n4) cout<<"\"-1213244613\">="<<n4<<endl;
    if("-1213244613"<=n4) cout<<"\"-1213244613\"<="<<n4<<endl;
	if("0"!=n4) cout<<"\"0\"!="<<n4<<endl;

//----------长整型与巨型整数比较-------------//
	if(-12340L<n4) cout<<"-12340L<"<<n4<<endl;
	if(12345L>n4) cout<<"12345L>"<<n4<<endl;
	if(0L==n4) cout<<"0L="<<n4<<endl;
	if(-1932456780L>=n4) cout<<"-1932456780L>="<<n4<<endl;
	if(-1932456780L<=n4) cout<<"-1932456780L<="<<n4<<endl;
	if(0L!=n4) cout<<"0L!="<<n4<<endl;

	cout<<endl<<endl;
	cout<<"按任意键...继续";
	getch();
	cout<<endl<<endl;


	cout<<"n4的当前值为:"<<n4<<endl;
	n5="1223424675485486000"+n4;
	cout<<"\"1223424675485486000\"+n4="<<n5<<endl;
	n5="-123123000000000412410"-n4;
	cout<<"\"-123123000000000412410\"-n4="<<n5<<endl;
	n5="-12342310000000000"*n4;
	cout<<"\"-12342310000000000\"*n4="<<n5<<endl;

	n5=-1234500000L+HugeInt(134246965L);
	cout<<"-1234500000L+HugeInt(134246965L)="<<n5<<endl;
	n5=-1234512000L-HugeInt("-1000255412354");
	cout<<"-1234512000L-HugeInt(\"-1000255412354\")="<<n5<<endl;
	n5=-1761243150L*HugeInt(0L);
	cout<<"-1761243150L*HugeInt(0L)="<<n5<<endl;

//----------------------除法运算-------------------------------//
	HugeInt a(-222232323L),b(0L);
	try{
		n5=a/b;
	cout<<"执行HugeInt(-222232323L)/HugeInt(\"0\")="<<HugeInt(-222232323L)/HugeInt("0")<<endl;
	}
	catch(Divbyzero){
		cout<<"执行HugeInt(-222232323L)/HugeInt(\"0\")  除数为0.错误!"<<endl;
	}

	try{
		n5=a/"0";
		cout<<"执行"<<a<<"/\"0\"="<<n5<<endl;
	}
	catch(Divbyzero){
		cout<<"执行"<<a<<"/\"0\"  除数为0.错误!"<<endl;
	}

	try{
		n5=a/"-12340";
		cout<<"执行"<<a<<"/\"-12340\"="<<n5<<endl;
	}
	catch(Divbyzero){
		cout<<"执行"<<a<<"/\"0\"  除数为0.错误!"<<endl;
	}

	try{
		n5=a/0L;
		cout<<"执行"<<a<<"/0L="<<n5<<endl;
	}
	catch(Divbyzero){
		cout<<"执行"<<a<<"/0L  除数为0.错误!"<<endl;
	}

	HugeInt a1(0L);
	try{
		cout<<"\na的当前值为:"<<a<<"   a1的当前值为:"<<a1<<endl;
		a/=a1;
		cout<<"执行a/=a1后的值为"<<a<<endl;
	}
	catch(Divbyzero){
		cout<<"执行a/=a1   除数为0.错误!"<<endl;
	}

	cout<<endl<<endl;
	cout<<"按任意键...继续";
	getch();
	cout<<endl<<endl;

//-----------------取余运算---------------------------//
	HugeInt n6(121244124L);
	
	try{
		cout<<"n6的当前值为:"<<n6<<endl;
		cout<<n6<<"/\"0\"="<<n6%"0"<<endl;
	}
	catch(Modbyzero){
		cout<<n6<<"%\"0\"     模取0.错误"<<endl;
	}

	try{
		cout<<n6<<"%0L"<<n6%0L<<endl;
	}
	catch(Modbyzero){
		cout<<n6<<"%0L    模取0.错误!"<<endl;
	}

	HugeInt n7(123456L),n8(0L);
	try{
		cout<<"\"32131312\"%"<<n7<<"="<<"32131312"%n7<<endl;
	}
	catch(Modbyzero){
	cout<<"\"32131312\"%"<<n7<<"     模取0.错误!"<<endl;
	}

	try{
		cout<<"-123456L%"<<n7<<"="<<-123456%n7<<endl;
	}
	catch(Modbyzero){
		cout<<"-123456%"<<n7<<"      模取0.错误!"<<endl;
	}

	try{
		cout<<"n7的当前值为:"<<n7<<"        n8的当前值为:"<<n8<<endl;
		n7%=n8;
		cout<<"执行n7%=n8后n7的值为:"<<n7<<endl;
	}
	catch(Modbyzero){
		cout<<"执行n7%=n8     模取0.错误!"<<endl;
	}
		

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -