日期:2018.7.19
星期四
博客期:002
这之前赶着做一个单机游戏的修改器忘了时间,不好意思啊!今天我就把Bignum类的源代码发出来,文件的话,我不知道怎样发,待我好好研究研究这个网站哈!因为内容实在是太大了!我就不排版了啊!
//===================》如下为 main.cpp 文件
1 #include<iostream> 2 using namespace std; 3 #include<Windows.h> 4 #include"Basic.h" 5 #include"Bignum.h" 6 Bignum touch1,touch2; 7 void win0() 8 { 9 system("cls"); 10 Basic::pend(); 11 Basic::make_an_char("Basic Class Practise",'*',1,2,2); 12 Basic::pend(); 13 Basic::pend(' '); 14 Basic::pend('=',28); 15 Basic::pend(); 16 Basic::pend(' '); 17 } 18 void win1() 19 { 20 win0(); 21 Basic::pend(); 22 cout<<" Please choice these:"<<endl<<endl;; 23 cout<<" S:设置第一个大数"<<endl<<endl; 24 cout<<" M:设置第二个大数"<<endl<<endl; 25 cout<<" D:选择运算"<<endl<<endl; 26 cout<<" I:查看说明"<<endl<<endl; 27 cout<<" Q:退出程序"<<endl<<endl; 28 cout<<" "; 29 } 30 //设置第一个大数 31 void S() 32 { 33 char printin[100]; 34 system("cls"); 35 cout<<endl<<endl; 36 Basic::make_an_char("set Bignum",'-',0,2,11); 37 Basic::pend(2); 38 cout<<" --------------------------------------"<<endl<<endl; 39 cout<<" 请输入第一个大数的值:"<<endl<<endl<<" "; 40 cin>>printin; 41 touch1 = Bignum(printin); 42 cout<<endl<<" 数据存储完成"<<endl; 43 Basic::pend(2); 44 cout<<" "; 45 system("PAUSE"); 46 } 47 //设置第二个大数 48 void M() 49 { 50 char printin[100]; 51 system("cls"); 52 cout<<endl<<endl; 53 Basic::make_an_char("set Bignum",'-',0,2,11); 54 Basic::pend(2); 55 cout<<" --------------------------------------"<<endl<<endl; 56 cout<<" 请输入第二个大数的值:"<<endl<<endl<<" "; 57 cin>>printin; 58 touch2 = Bignum(printin); 59 cout<<endl<<" 数据存储完成"<<endl; 60 Basic::pend(2); 61 cout<<" "; 62 system("PAUSE"); 63 } 64 //选择运算 65 void D() 66 { 67 system("cls"); 68 Basic::make_an_char("选择运算",'-',0,2,9); 69 char x='0'; 70 Bignum touch3; 71 cout<<" --------------------------------"<<endl; 72 cout<<" 请输入运算符:"<<endl; 73 while(x!='+'&&x!='-'&&x!='*'&&x!='/'&&x!='%') 74 { 75 cout<<" "; 76 cin>>x; 77 } 78 cout<<endl<<" ********************************"<<endl<<endl; 79 cout<<" "<<touch1<<endl; 80 cout<<" "<<x<<endl; 81 cout<<" "<<touch2<<endl; 82 cout<<" ="<<endl; 83 switch(x) 84 { 85 case '+':touch3=touch1+touch2;break; 86 case '-':touch3=touch1-touch2;break; 87 case '*':Bignum::multiplication(touch1,touch2);break; 88 case '/':touch3=touch1/touch2;break; 89 case '%':touch3=touch1%touch2;break; 90 default:break; 91 } 92 cout<<" "<<touch3<<endl<<endl<<" ********************************"<<endl; 93 cout<<endl; 94 system("PAUSE"); 95 } 96 //查看说明 97 void I() 98 { 99 system("cls"); 100 Basic::pend(2); 101 Basic::make_an_char("Instruction",'*',1,2,2); 102 cout<<endl<<endl; 103 cout<<" Maker: Master"<<endl<<endl; 104 cout<<" Name: Bignum's Program"<<endl<<endl; 105 cout<<" Date: 2018.7.19"<<endl<<endl; 106 cout<<" Version: 1.023"<<endl<<endl; 107 cout<<" "; 108 system("PAUSE"); 109 } 110 //退出程序 111 void Q() 112 { 113 system("cls"); 114 Basic::pend(2); 115 Basic::make_an_char("Welcome to the next time !",'*',1,2,2); 116 cout<<endl<<endl<<" "; 117 } 118 int main() 119 { 120 Bignum tar[20]; 121 char x='c'; 122 while(x!='q'&&x!='Q') 123 { 124 win1(); 125 cin>>x; 126 getchar(); 127 switch(x) 128 { 129 case 's': 130 case 'S':S();break; 131 case 'm': 132 case 'M':M();break; 133 case 'd': 134 case 'D':D();break; 135 case 'i': 136 case 'I':I();break; 137 case 'q': 138 case 'Q':Q();break; 139 default:break; 140 } 141 } 142 return 0; 143 }
//=============================》如下为 Basic.h 文件
1 #include<iostream> 2 using namespace std; 3 #include<string> 4 class Basic 5 { 6 public: 7 //====================<输入输出>=======================// 8 /* 9 /-----------<pend函数> 10 /-# 11 /----(1)默认输出" ",可直接输入int类型变量或常量给形参n,得到输出n次的换行(默认输出一次) 12 /----(2)可指定字符p,输入n次(默认输出一次) 13 /----(3)可连续输出对间隔输出 14 */ 15 static void pend(const int n=1) 16 { 17 for(int i=0;i<n;i++) 18 cout<<endl; 19 } 20 static void pend(const char p,const int n=1) 21 { 22 for(int i=0;i<n;i++) 23 cout<<p; 24 } 25 static void pend(const char p,const char q,const int n=1,const int m=1,const bool s=true) 26 { 27 if(s) 28 { 29 Basic::pend(p,n); 30 Basic::pend(q,m); 31 } 32 else 33 { 34 if(m==n) 35 for(int i=0;i<n;i++) 36 { 37 Basic::pend(p); 38 Basic::pend(q); 39 } 40 } 41 } 42 static void pend(const char o,const char p,const char q,const int l=1,const int m=1,const int n=1) 43 { 44 Basic::pend(o,l); 45 Basic::pend(p,m); 46 Basic::pend(q,n); 47 } 48 /* 49 /-----------<printarray函数> 50 /-# 51 /----(1)用于打印一维数组或二维数组 52 /----(2)可确定初始位置(begin) 53 /----(3)可设定列间距(lie) 54 /----(4)使用时必须设定数组长度 55 /----(5)数据中从du开始读,并结束于 n(即 n可以小于 p的实际长度) 56 /----(6)数据的列从da开始读,并结束于 m(同上) 57 */ 58 template <typename T> 59 static void printarray(T *p,int n=0,const int lie=1,const int begin=1,int du=0) 60 { 61 if(n==0) 62 return; 63 Basic::pend(' ',begin); 64 for(int i=du;i<n;i++) 65 { 66 cout<<p[i]; 67 if(i!=n-1) 68 Basic::pend(' ',lie); 69 } 70 Basic::pend(); 71 } 72 template <typename T> 73 static void printarray(T **q,int n=0,int m=0,const int hang=0,const int lie=1,const int begin=1,int du=0,int da=0) 74 { 75 if(n==0||m==0) 76 return; 77 for(int t=da;t<m;t++) 78 { 79 Basic::pend(' ',begin); 80 for(int i=du;i<n;i++) 81 { 82 cout<<q[t][i]; 83 if(i!=n-1) 84 Basic::pend(' ',lie); 85 } 86 Basic::pend(hang+1); 87 } 88 } 89 //====================<窗口>=======================// 90 /* 91 /-----------<make_an_char函数> 92 /-# 93 /----(1)窗口制定 94 /----(2)可设定长宽 95 /----(3)可确定初始位置 96 */ 97 static void make_an_char(char *q,const char p='*',const int hang=0,const int lie=1,const int begin=1) 98 { 99 //最初行 100 Basic::pend(' ',begin); 101 Basic::pend(p,lie+1); 102 for(int i=0;*(q+i)!='