|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- int a_10(int x)
- {
- if(x=0)
- {
- return 1;
- }
- if(x>0)
- {
- return a_10(x-1)*10;
- }
- if(x<0)
- {
- throw x;
- }
- }
- class Fs
- {
- public:
- int z;
- int m;
- Fs(int a);
- Fs(long double s);
- Fs(int c,int x):z(c),m(x) {}
- };
- Fs::Fs(int a)
- {
- m=rand()%11;
- z=a*m;
- }
- Fs::Fs(long double s)
- {
- int d=-1;
- int con;
- int cons;
- int r[100];
- int ss=int(s);
- while(int(s)!=s&&s<std::numeric_limits<long double>::max()/10&&s<std::numeric_limits<int>::max()/10)
- s*=10;
- for(int c = 0; c <= 100; c++) {
- r[c]=int(s)%10;
- for(int i = 0; i <= 100; i++) {
- if(r[100-i]!=0) {
- con =100-i+1;
- break;
- }
- }
- }
- for(int c = 0; c <= 100; c++) {
- r[c]=ss%10;
- for(int i = 0; i <= 100; i++) {
- if(r[100-i]!=0) {
- cons =100-i+1;
- break;
- }
- }
- }
- m=a_10(con-cons);
- z=s;
- }
复制代码
上边是我编的一个头文件,下面是主文件- #include <iostream>
- #include "Fs.h"
- using namespace std;
- int main() {
- int t;
- int w;
- cout << "请输入一个分子和分母,用逗号隔开"<< endl;
- cin >> t >> w;
- Fs s(t,w);
- cout << "建造分数成功"<< endl;
- cout << "再来一个转换的,整数"<< endl;
- cin >> t;
- cout << "输入进来了"<< endl;
- Fs d(t);
- cout << "建造成功"<< endl;
- cout << "它的分母是"<<d.m<<"而分子是"<<d.z<< endl;
- try
- {
- long double l;
- cout << "再来一个实数的吧"<< endl;
- cin >> l;
- Fs f(l);
- cout << "它的分子是"<<f.z<<"而分母是"<<f.m<< endl;
- }
- catch(int)
- {
- cout << "出错了"<< endl;
- }
- return 0;
- }
复制代码
然后他每一次就是到输入完实数实数进去以后就显示运行结束,是为啥呀? |
|