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

📄 longinteger.cpp

📁 实现了任意长度整数的加减乘除以及成n次方运算
💻 CPP
字号:



#include<stdio.h>
#include<iostream>
#include <string> 
using namespace std;



#include"DIVIDE.h"
//#include"MULTIPY.cpp"

int main()
{
	string str;
	string strA,strB,strC,strD,pownum;
	struct head *headA = new struct head;
	struct head *headB = new struct head; 
	struct head *headC = new struct head;
	struct head *headD = new struct head;
	struct head *headE = new struct head;
	struct head *headF = new struct head;
	struct head *headG = new struct head;
	struct head *headH = new struct head;
	struct head *headI = new struct head;
	struct head *headJ = new struct head;
	struct head *headK = new struct head;
	struct head *headL = new struct head;
	struct head *headM = new struct head;
	struct head *headN = new struct head;
	struct head *headO = new struct head;
	struct head *headP = new struct head;
	struct head *headQ = new struct head;
	struct head *headR = new struct head;
	struct head *headS = new struct head;
	struct head *headT = new struct head;
	struct head *headU = new struct head;
	struct head *headV = new struct head;
	struct head *headW = new struct head;
	struct head *headX = new struct head;
	struct head *headY = new struct head;
	struct head *headZ = new struct head;

	cout<<"Please Input the following fuctions to choose operation, all captal letters. thank you !"<<endl;
	cout<<"ADD"<<endl;
	cout<<"SUBTRACT"<<endl;
	cout<<"MULTIPLY"<<endl;
	cout<<"DIVIDE"<<endl;
	cout<<"POW"<<endl;
	cout<<"PREDEFINED"<<endl;
	cout<<"EXIT"<<endl;
	while(true)
	{
		cin>>str;
		if(str == "ADD")
		{
			cout<<"Please input adder1"<<endl;
			cout<<"A=";
			cin>>strA;
			CreatandStore(headA, strA);
			cout<<"Please input adder2"<<endl;
			cout<<"B=";
			cin>>strB;
			CreatandStore(headB, strB);

			headC = Add(headA, headB);
			cout<<"Result:"<<strA<<"+"<<strB<<"=";
			OutPutData(headC);
			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
		}
		else if(str == "SUBTRACT")
		{
			cout<<"Please input minuend"<<endl;
			cout<<"A=";
			cin>>strA;
			CreatandStore(headA, strA);
			cout<<"Please input subtrahend"<<endl;
			cout<<"B=";
			cin>>strB;
			CreatandStore(headB, strB);

			headC = Subtract(headA, headB);
			cout<<"Result:"<<strA<<"-"<<strB<<"=";
			OutPutData(headC);
			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
			
		}
		else if(str == "MULTIPLY")
		{
			cout<<"Please input multiplicand "<<endl;
			cout<<"A=";
			cin>>strA;
			CreatandStore(headA, strA);
			cout<<"Please input multiplier"<<endl;
			cout<<"B=";
			cin>>strB;
			CreatandStore(headB, strB);

			headC = Multiply(headA, headB);
			cout<<"Result:"<<strA<<"*"<<strB<<"=";
			OutPutData(headC);
			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
					   
		}
		else if(str == "DIVIDE")
		{
			cout<<"Please input dividend"<<endl;
			cout<<"A=";
			cin>>strA;
			CreatandStore(headA, strA);
			cout<<"Please input divisor "<<endl;
			cout<<"B=";
			cin>>strB;
			CreatandStore(headB, strB);

			headC = Divide(headA, headB);
			cout<<"Result:"<<strA<<"/"<<strB<<"=";
			OutPutData(headC);
			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
			  
				    
		}
		else if(str == "POW")
		{
			long powtimes;
			cout<<"Please input cardinal number"<<endl;
			cout<<"A=";
			cin>>strA;
			CreatandStore(headA, strA);
			cout<<"Please input times (less than 8 digits and positive)"<<endl;
			cout<<"B=";
			cin>>strB;
			const char *x = strB.c_str();
			powtimes = strtol(x, NULL, 10);
			
			headC = Pow(headA, powtimes);
			cout<<"Result:"<<strA<<"^"<<strB<<"=";
			OutPutData(headC);
			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
			

		}
		else if(str == "PREDEFINED")
		{
			cout<<"A=22222222"<<endl;
			cout<<"B=55555555"<<endl;
			cout<<"C=24681357"<<endl;
			cout<<"D=18027036"<<endl;

			strA = "22222222";
			strB = "55555555";
			strC = "24681357";
			strD = "18027036";
			CreatandStore(headA, strA);
			CreatandStore(headB, strB);
			CreatandStore(headC, strC);
			CreatandStore(headD, strD);
			
			headE = Multiply(headA, headD);
			cout<<"E=A*D=";
			OutPutData(headE);

			headF = Pow(headA, 2);
			cout<<"F=A^2=";
			OutPutData(headF);

			headG = Pow(headD, 2);
			cout<<"G=D^2=";
			OutPutData(headG);

			headH = Multiply(headB, headC);
			cout<<"H=B*C=";
			OutPutData(headH);

			headI = Add(headA, headD);
			cout<<"I=A+D=";
			OutPutData(headI);

			headJ = Pow(headI, 2);
			cout<<"J=I^2=";
			OutPutData(headJ);

			headK = Subtract(headJ, headF);
			cout<<"K=J-F= ";
			OutPutData(headK);

			headL = Subtract(headK, headG);
			cout<<"L=K-G=";
			OutPutData(headL);

			headM = Divide(headL, headE);
			cout<<"M=L/E=";
			OutPutData(headM);

			headN = Pow(headE, 5);
			cout<<"N=E^5=";
			OutPutData(headN);

			headO = Pow(headH, 3);
			cout<<"O=H^3=";
			OutPutData(headO);

			headP = Subtract(headN, headO);
			cout<<"P=N-O=";
			OutPutData(headP);

			headQ = Pow(headN, 2);
			cout<<"Q=N^2=";
			OutPutData(headQ);

			headR = Pow(headO, 2);
			cout<<"R=O^2=";
			OutPutData(headR);

			headS = Subtract(headQ, headR);
			cout<<"S=Q-R=";
			OutPutData(headS);

			headT = Divide(headS, headP);
			cout<<"T=S/P=";
			OutPutData(headT);

			headU = Subtract(headT, headO);
			cout<<"U=T-O=";
			OutPutData(headU);

			headV = Subtract(headU, headN);
			cout<<"V=U-N=";
			OutPutData(headV);

			headW = Pow(headC, 2);
			cout<<"W=C^2=";
			OutPutData(headW);

			headX = Pow(headB, 2);
			cout<<"X=B^2=";
			OutPutData(headX);

			headY = Subtract(headW, headX);
			cout<<"Y=W-X=";
			OutPutData(headY);

			headZ = Add(headC, headB);
			cout<<"Z=C+B=";
			OutPutData(headZ);

			headH = Divide(headY, headZ);
			cout<<"H=Y/Z=";
			OutPutData(headH);

			headF = Pow(headN, 5);
			cout<<"F=N^5=";
			OutPutData(headF);

			headG = Pow(headE, 25);
			cout<<"G=E^25=";
			OutPutData(headG);

			headI = Divide(headF, headN);
			cout<<"I=F/N=";
			OutPutData(headI);

			headJ = Divide(headG, headI);
			cout<<"J=G/I=";
			OutPutData(headJ);

			headM = Pow(headN, 10);
			cout<<"M=N^10=";
			OutPutData(headM);

			headP = Pow(headG, 2);
			cout<<"P=G^2=";
			OutPutData(headP);

			headQ = Subtract(headP, headM);
			cout<<"Q=P-M=";
			OutPutData(headQ);

			headR = Subtract(headJ, headM);
			cout<<"R=J-M=";
			OutPutData(headR);



			cout<<""<<endl;
			cout<<"You can choose operation again, now."<<endl;
		}
		else if(str == "EXIT")
		{
			break;
		}
		else
		{
			cout<<"Sorry for a wrong input, please input following the instruction above."<<endl;
		}
	}


/*
	cout<<"C=";
	cin>>strC;
	CreatandStore(headC, strC);
	cout<<"D=";
	cin>>strD;
	CreatandStore(headD, strD);

	headE = Subtract(headA,headB);
	headF = Add(headA,headB);
	OutPutData(headE);
	OutPutData(headF);

	Multiply(headA, headB, headE);
	OutPutData(headE);

	long num;
	cout<<"Please input the num of pow"<<endl;
	cin>>pownum;
	const char *a = pownum.c_str();
	num= strtol(a, NULL, 10);
	headE = Pow(headA,num);
	OutPutData(headE);




	headE = Divide(headA, headB);
	cout<<"headE=";
	OutPutData(headE);
	cout<<"finish"<<endl;


	headE = Subtract(headA,headB);
	OutPutData(headE);

	headE = SubOneZero(headA);
	OutPutData(headE);




	int oo=1;
	headE = PlusZeros(headA, oo);
	OutPutData(headE);
*/
}

⌨️ 快捷键说明

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