-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_cal.cpp
More file actions
43 lines (39 loc) · 1.13 KB
/
math_cal.cpp
File metadata and controls
43 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "math_cal.h"
string CAL_alg(vector<string> &hold_strs, string type, bool& NULL_flag){
//cout<<"meet cal"<<endl;
//if any error occurs, return "NULL"
if(type == "date" || type == "time") return hold_strs[0];
if(type=="char(1)"){
if(CAA_2(hold_strs,NULL_flag)=="NULL")NULL_flag=true;
return CAA_2(hold_strs,NULL_flag);
}
else if(type!="int(11)"&&type!="double"){
NULL_flag=true;
return "NULL";
}
else if(type=="int(11)"){
if(CAA<int>(hold_strs,NULL_flag)=="NULL"){
//cout<<"one NULL"<<endl;
NULL_flag=true;
}
return CAA<int>(hold_strs,NULL_flag);
}
else{
if(CAA<double>(hold_strs,NULL_flag)=="NULL")NULL_flag=true;
return CAA<double>(hold_strs,NULL_flag);
}
}
string CAA_2(vector<string> & hold_strs,bool& NULL_flag){
if(NULL_flag)return "NULL";
int str_turn=1;
int cal_turn=0;
string resu;
for(int pos=0;pos<=hold_strs.size()-1;pos++,str_turn^=1,cal_turn^=1){
if(str_turn){
resu+=hold_strs[pos];
}else{
if(hold_strs[pos]!="+")return "NULL";
}
}
return resu;
}