Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Plasm ( 16 years ago )
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
char first_bm[100],second_bm[100],res_bm[10000],oprt='\\0', int_part1[10000], frac_part1[10000], int_part2[10000], frac_part2[10000],res_int[10000],res_frac[10000];
int end_of,buf,buf_m,int1_real,int2_real,frac1_real=0,frac2_real=0,str_r,zpt_pointer=0,zpt_counter1=0,zpt_counter2=0,res_int_real,res_frac_real;
bool getting_data()
{
puts("Hey, user! Get me 2 biiig numbers and operation:");
puts("Now, get first number:");
gets(first_bm);
puts("Now, get second number:");
gets(second_bm);
puts("And operation:");
scanf("%c",&oprt;);
puts("Now, wait, please. Processing...");
return true;
}
void outputing_data()
{
puts(res_bm);
puts("Thanks for using -)");
}
void dism_to_int_and_frac_parts() //Процедура разделяет исходные строки на две - целую часть и дробную часть
{
//Первое число
{
for(int i=0;first_bm[i]!='\0';i++)
{
if ((first_bm[i]==',') || (first_bm[i]=='.'))
{
zpt_counter1++;
zpt_pointer=i;
}
}
if (zpt_counter1>2)
{
puts("You are stupid! Too many comma`s");
puts("Result will be wrong!");
}
if (zpt_counter1==1)
{
for(int i=0;i<zpt_pointer;i++)
{
int_part1[i]=first_bm[i];
}
for(int i=zpt_pointer+1;first_bm[i]!='\0';i++)
{
frac_part1[i]=first_bm[i];
}
for(int i=zpt_pointer;i<10000;i++)
{
frac_part1[i-zpt_pointer-1]=frac_part1[i];
frac_part1[i]=0;
}
}
if (zpt_counter1==0)
{
for(int i=0;first_bm[i]!='\0';i++)
{
int_part1[i]=first_bm[i];
}
}
}
//Второе число
{
for(int i=0;second_bm[i]!='\0';i++)
{
if ((second_bm[i]==',') || (second_bm[i]=='.'))
{
zpt_counter2++;
zpt_pointer=i;
}
}
if (zpt_counter2>2)
{
puts("You are stupid! Too many comma`s");
puts("Result will be wrong!");
}
if (zpt_counter2==1)
{
for(int i=0;i<zpt_pointer;i++)
{
int_part2[i]=second_bm[i];
}
for(int i=zpt_pointer+1;second_bm[i]!='\0';i++)
{
frac_part2[i]=second_bm[i];
}
for(int i=zpt_pointer;i<10000;i++)
{
frac_part2[i-zpt_pointer-1]=frac_part2[i];
frac_part2[i]=0;
}
}
if (zpt_counter2==0)
{
for(int i=0;second_bm[i]!='\0';i++)
{
int_part2[i]=second_bm[i];
}
}
}
str_r=strlen(frac_part1)-strlen(frac_part2);
if (str_r > 0)
{
for(int i=strlen(frac_part1)+1;i<strlen(frac_part2)+1;i++)
{
frac_part1[i]='0';
}
}
if (str_r < 0)
{
for(int i=strlen(frac_part2)+1;i<strlen(frac_part1)+1;i++)
{
frac_part2[i]='0';
}
}
}
void addition()
{
bool incr_int=false;
dism_to_int_and_frac_parts();
//Дробная часть
{
//Найдем последний символ
for(int i=100;i!=0;i--)
{
if ((frac_part1[i]!=0) && (frac_part1[i]!='0') && (frac_part1[i]!='\0'))
{
end_of=i;
break;
}
}
//Считаем
for(int i=9999;end_of>-1;i--,end_of--)
{
buf=(frac_part1[end_of]-'0')+(frac_part2[end_of]-'0')+buf_m;
if (buf<10)
{
res_frac[i]=buf+'0';
buf_m=0;
}
if (buf>9)
{
res_frac[i]=(buf-10)+'0';
buf_m=1;
if (end_of==0)
{
incr_int=true;
}
}
}
//Выравниваем
{
for(int i=0; i<10000;i++)
{
if ((res_frac[i]!=0) && (res_frac[i]!='0') && (res_frac[i]!='\0') && (res_frac[i]>0))
{
end_of=i;
break;
}
}
for(int i=end_of-1; i<10000;i++)
{
res_frac[i-end_of]=res_frac[i];
res_frac[i]=0;
}
}
}
//Целая часть
{
if (incr_int)
{
buf_m=1;
}
//Найдем последний символ
for(int i=100;i!=0;i--)
{
if ((int_part1[i]!=0) && (int_part1[i]!='0') && (int_part1[i]!='\0'))
{
end_of=i;
break;
}
}
//Считаем
for(int i=9999;end_of>-1;i--,end_of--)
{
buf=(int_part1[end_of]-'0')+(int_part2[end_of]-'0')+buf_m;
if (buf<10)
{
res_int[i]=buf+'0';
buf_m=0;
}
if (buf>9)
{
res_int[i]=(buf-10)+'0';
buf_m=1;
if (end_of==0)
{
res_int[i-1]=res_int[i-1]+1+'0';
}
}
if (incr_int)
{
res_int[9999]=(res_int[9999]-'0'+1)+'0';
}
}
//Выравниваем
{
for(int i=0; i<10000;i++)
{
if ((res_int[i]!=0) && (res_int[i]!='0'))
{
end_of=i;
break;
}
}
for(int i=end_of; i<10000;i++)
{
res_int[i-end_of]=res_int[i];
res_int[i]=0;
}
}
}
if (strlen(res_frac)==0)
{
res_frac[0]='0';
}
strcpy(res_bm,res_int);
strcat(res_bm,",");
strcat(res_bm,res_frac);
outputing_data();
}
void substraction()
{
}
void multiplication()
{
}
void division()
{
}
void processing()
{
//Обнуляем всё, куда будем записывать
memset(res_bm,0,strlen(res_bm));
memset(int_part1,0,strlen(int_part1));
memset(int_part2,0,strlen(int_part2));
memset(frac_part1,0,strlen(frac_part1));
memset(frac_part2,0,strlen(frac_part2));
memset(res_int,0,strlen(res_int));
memset(res_frac,0,strlen(res_frac));
//Считаем разницу в длине строк
str_r=strlen(first_bm)-strlen(second_bm);
//В этом блоке выравниваю строки по длине(то есть если на вводе было 1234 и 123 то будет 1234 и 0123)
{
if (str_r > 0)
{
for(int i=strlen(second_bm);i>-1;i--)
{
second_bm[i+abs(str_r)]=second_bm[i];
second_bm[i]='0';
}
}
if (str_r < 0)
{
for(int i=strlen(first_bm);i>-1;i--)
{
first_bm[i+abs(str_r)]=first_bm[i];
first_bm[i]='0';
}
}
}
//В зависимости от введенного знака операции вызываем нужную функцию для обработки данных
{
switch (oprt)
{
case '+':
{
addition();
break;
}
case '-':
{
substraction();
break;
}
case '*':
{
multiplication();
break;
}
case '/':
{
division();
break;
}
default:
{
puts("Not operation! Restart the program");
}
}
}
}
void main()
{
if (getting_data())
{
processing();
getch();
}
}
Revise this Paste