IoTcat 5 years ago
parent 33ad0332af
commit 434087ec82
  1. 16
      as1/Fraction.h
  2. 3
      as1/Fraction_test.cpp
  3. BIN
      as1/a.exe

@ -516,7 +516,7 @@ unsigned int Fraction::get_repeat_part(const unsigned long int& t)
if(get_one_decimal(t, j) == get_one_decimal(t, j + i - 1)) count++;
}
//cout << "iii" << i << endl;
if(count == i - 1) return t % (unsigned int)pow(10, i - 1);
}
@ -548,9 +548,13 @@ void Fraction::confirm_repeat_part(const unsigned long int& t, unsigned int& rep
if(len == 3 && ((get_one_decimal(t, i) == get_one_decimal(repeat, 1) && get_one_decimal(t, i+1) == get_one_decimal(repeat, 2) && get_one_decimal(t, i+2) == get_one_decimal(repeat, 3)) || (get_one_decimal(t, i+1) == get_one_decimal(repeat, 1) && get_one_decimal(t, i+2) == get_one_decimal(repeat, 2) && get_one_decimal(t, i) == get_one_decimal(repeat, 3)) || (get_one_decimal(t, i+2) == get_one_decimal(repeat, 1) && get_one_decimal(t, i) == get_one_decimal(repeat, 2) && get_one_decimal(t, i+1) == get_one_decimal(repeat, 3)))) k = true;
if(k){
repeat = t / (unsigned int)pow(10, i -1 - len) - (t / (unsigned int)pow(10, i - 1)) * (unsigned int)pow(10, len);
start = i;
break;
unsigned short t_repeat = t / (unsigned int)pow(10, i -1 - len) - (t / (unsigned int)pow(10, i - 1)) * (unsigned int)pow(10, len);
if(t_repeat == repeat && repeat < 100) start = i + 1;
else if(t_repeat == repeat && repeat < 1000) start = i + 2;
else start = i;
repeat = t_repeat;
return;
}
}
}
@ -582,9 +586,9 @@ void Fraction::repeated_decimal_to_fraction(double d)
for(int i = 0; i < get_long_int_length(repeat); i++){
down += 9 * (unsigned int)pow(10, i);
}
}//cout << "sds" << down << " " << (get_long_int_length(t) - start) << endl;
down *= (unsigned int)pow(10, (get_long_int_length(t) - start));
down *= (get_long_int_length(t) - start > 0)? (unsigned int)pow(10, (get_long_int_length(t) - start)) : 1;
cout << down << endl;

@ -98,13 +98,14 @@ int main()
cout << msg << endl;
}
while(1){
try{
cout << endl << "Please Input a Fraction(-3/5) or a Decimals(e.g. 3.14): ";
cin >> a;
cout << a << endl;
}catch(const char* msg){
cout << endl << msg << endl;
}
}}
return 0;
}

Binary file not shown.
Loading…
Cancel
Save