
Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / Калькулятор / Calc / func1
.cpp#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
//-------Умножение и деление----------------------------------
string func1(string str)
{
char sres[10];
char *tmp1,*tmp2;
int p0,p1,p2,i;
while(str.find("*",0)!=-1||str.find("/",0)!=-1)
{
p0=str.find_first_of("*/",0);
p1=-1;
for(i=0;i<p0;i++)
if((str[i]=='+'||(str[i]=='-'&&i!=0))&&(str[i-1]!='e'))
p1=i;
tmp1=new char[p0-p1-1];
str.copy(tmp1,p0-p1-1,p1+1);
p2=str.find_first_of("+-*/",p0+1);
if(str[p2-1]=='e'||str[p2-1]=='*'||str[p2-1]=='/')
p2=str.find_first_of("+-*/",p2+1);
if(p2==-1) p2=str.length();
tmp2=new char[p2-p0-1];
str.copy(tmp2,p2-p0-1,p0+1);
if(str[p0]=='*') _gcvt(atof(tmp1)*atof(tmp2),15,sres);
if(str[p0]=='/'&&str[p0+1]!='0') _gcvt(atof(tmp1)/atof(tmp2),15,sres);
if(str[p0]=='/'&&str[p0+1]=='0')
{
str="!divizion by zero";
break;
}
str.replace(p1+1,p2-p1-1,sres);
delete [] tmp1;
delete [] tmp2;
}
return str;
}
Соседние файлы в папке Calc