c++数学计算模拟器

做了一个数学计算模拟器,运行通过,可直接编译。

精致的主页面...

 呵呵......

看代码

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int s=0;int m,n;int a[100];

long long math_z(long long temp)
{
	long long u=1;
	for (int i=1;i<=temp;i++)
	{
		u*=i;
	}
	return u;
}

void init()
{
	system("color F0");
	cout<<"\n\t\t\t ____________________\n";
	cout<<"\t\t\t |                   |\n";
	cout<<"\t\t\t |   排列组合模拟器  |\n";
	cout<<"\t\t\t |  按小写a进入排列  |\n";
	cout<<"\t\t\t |  按小写b进入组合  |\n";
	cout<<"\t\t\t |  按小写d进入除法  |\n";
	cout<<"\t\t\t |  按小写c退出      |\n";
	cout<<"\t\t\t ---------------------\n";
}

double d(double g, double h)//a=g b=h
{
	if(h==0)
	{
		throw "Division by zero condition!Please continue to choose.";
	}
	return (g*1.0/h*1.0);
}

void init_2()
{
	system("mode con cols=80 lines=20");
	//1
	system("color F4");
	cout<<"\n\n";
	cout<<"       ("<<endl;
    cout<<"       )))"<<endl;
    cout<<"      ((((("<<endl;
    cout<<"      )))))))"<<endl;
    cout<<"     (((((((((("<<endl;
    cout<<"   ))))))))))))))"<<endl;
    cout<<"  (((((((((((((((("<<endl;
    cout<<")))))))))()))))))))"<<endl;
    cout<<"(((((((((((())(((((((((("<<endl;
    cout<<" ))))))(((())))))))))"<<endl;
    cout<<"(((((((((())(((((((((("<<endl;
    cout<<")))))))))))))))))())))))"<<endl;
    Sleep(1000);
    system("cls");
    //2
    cout<<"\n\n";
	cout<<"             ("<<endl;
    cout<<"             )))"<<endl;
    cout<<"            ((((("<<endl;
    cout<<"            )))))))"<<endl;
    cout<<"           (((((((((("<<endl;
    cout<<"         ))))))))))))))"<<endl;
    cout<<"        (((((((((((((((("<<endl;
    cout<<"      )))))))))()))))))))"<<endl;
    cout<<"      (((((((((((())(((((((((("<<endl;
    cout<<"       ))))))(((())))))))))"<<endl;
    cout<<"      (((((((((())(((((((((("<<endl;
    cout<<"      )))))))))))))))))())))))"<<endl;
    
    Sleep(1000);
    system("cls");
    //2
    cout<<"\n\n";
	cout<<"                 ("<<endl;
    cout<<"                  )))"<<endl;
    cout<<"                 ((((("<<endl;
    cout<<"                 )))))))"<<endl;
    cout<<"                (((((((((("<<endl;
    cout<<"              ))))))))))))))"<<endl;
    cout<<"             (((((((((((((((("<<endl;
    cout<<"           )))))))))()))))))))"<<endl;
    cout<<"           (((((((((((())(((((((((("<<endl;
    cout<<"            ))))))(((())))))))))"<<endl;
    cout<<"           (((((((((())(((((((((("<<endl;
    cout<<"           )))))))))))))))))())))))"<<endl;
    
    Sleep(1000);
    system("cls");
    //2
    cout<<"\n\n";
	cout<<"                         ("<<endl;
    cout<<"                          )))"<<endl;
    cout<<"                         ((((("<<endl;
    cout<<"                         )))))))"<<endl;
    cout<<"                        (((((((((("<<endl;
    cout<<"                      ))))))))))))))"<<endl;
    cout<<"                     (((((((((((((((("<<endl;
    cout<<"                   )))))))))()))))))))"<<endl;
    cout<<"                   (((((((((((())(((((((((("<<endl;
    cout<<"                    ))))))(((())))))))))"<<endl;
    cout<<"                   (((((((((())(((((((((("<<endl;
    cout<<"                   )))))))))))))))))())))))"<<endl;
    
    Sleep(1000);
    system("cls");
    //2
    cout<<"\n\n";
	cout<<"                                   ("<<endl;
    cout<<"                                    )))"<<endl;
    cout<<"                                   ((((("<<endl;
    cout<<"                                   )))))))"<<endl;
    cout<<"                                  (((((((((("<<endl;
    cout<<"                                ))))))))))))))"<<endl;
    cout<<"                               (((((((((((((((("<<endl;
    cout<<"                             )))))))))()))))))))"<<endl;
    cout<<"                           (((((((((((())(((((((((("<<endl;
    cout<<"                              ))))))(((())))))))))"<<endl;
    cout<<"                            (((((((((())(((((((((("<<endl;
    cout<<"                             )))))))))))))))))())))))"<<endl;
    
    cout<<"\n                              数";
    Sleep(100);
    cout<<"学";
    Sleep(100);
    cout<<"计";
    Sleep(100);
    cout<<"算";
    Sleep(100);
    cout<<"模";
    Sleep(100);
    cout<<"拟";
    Sleep(100);
    cout<<"器";
    Sleep(2000);
    system("cls");
}
 
 
int P(int k)
{
	if(k>m)   //如果 k 要比m还要长则停止递归 
	return s;
	
	for(int i=1;i<=n;i++)
	{
		a[k]=i;
		int flag=0;
		for(int j=1;j<=k-1;j++)  //这里表示 每一位例如第2位 要试探n个数,前面出现的就不要。 
		{
			if(a[k]==a[j])
			{
				flag=1;
				break; 
			}
			
		}
		if(flag==0)             //flag==1 表示前面已经用了那个数,就不能用了。 
		{
			if(k==m)			// 当k已经到了第m位,那就要输出这个全排列了 
			{
				for(int i=1;i<=m;i++)
				{
					printf("%d",a[i]);
				}
				printf("\n");
				s++; 			//s统计排列个数 
			}
			else
			P(k+1);				//k还没到达m位,那就继续寻找下一位。 
		}
	}
}





int main()
{
	init_2();
	Sleep(5000);
	//system("cls");
	init();
	int ch;
	while (true)
	{
		if (kbhit()){
			ch = _getch();
			if (ch == 98)
			{
				cout<<endl<<"组合:请输入C(m,n)(数学中m在上,n在下)中的n和m(先输n再输m),直接出结果,一共有多少种结果";
				long long a,b;
				cin>>a>>b;//n=a m=b
				cout<<"一共有"<<math_z(a)/(math_z(b)*math_z(a-b))<<"种组合方式";
			}	
			if (ch == 97)
			{
				cout<<endl<<"组合:请输入A(m,n)(数学中m在上,n在下)中的n和m(先输n再输m),直接出结果,一共有多少种结果";
				int P(int k);   //k从 1 一直增长到 m ,k表示排列的第k个数 
				cin>>n>>m;
				//P(1);
				cout<<endl<<"一共有"<<s<<"种排列方法";
			}
			if (ch==99)
			{
				cout<<"\n\n";
				system("pause");
				exit(0); 
			}
			if (ch==100)
			{
				double z=0;
				cout<<endl<<"输入两个数:";
				double x;
				double y;
				cin>>x>>y;
				cout<<endl<<"请输入要保留几位小数(最多4位)"<<endl;
				int r;
				cin>>r;
				try{
					z = d(x,y);
					cout<<endl<<x<<" / "<<y<<" ~= "<<fixed<<setprecision(r)<<z<<endl;
				}catch (const char* msg){
					cerr<<msg<<endl;	
				}
			}
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_64036070/article/details/122535714
今日推荐