-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmeticExpression.cpp
More file actions
69 lines (63 loc) · 1.92 KB
/
Copy patharithmeticExpression.cpp
File metadata and controls
69 lines (63 loc) · 1.92 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#include "interpret.h"
using namespace std;
void readArithmetic(string line,int lineNum)
{
string operand1,operand2,op,storeVar;
int i=0;
while(line[i]!='='){
storeVar+=line[i];
i++;
}
i++;
while(line[i]!='+' and line[i]!='-' and line[i]!='*' and line[i]!='/' and line[i]!='%'){
operand1+=line[i];
i++;
}
op=line[i];
i++;
while(line[i]!=';'){
operand2+=line[i];
i++;
}
if(op=="+"){
readAddition(storeVar,operand1,operand2,lineNum);
}
else if(op=="-"){
readSubtraction(storeVar,operand1,operand2,lineNum);
}
else if(op=="*"){
readMultiplication(storeVar,operand1,operand2,lineNum);
}
else if(op=="/"){
readDivision(storeVar,operand1,operand2,lineNum);
}
else if(op=="%"){
readRemainder(storeVar,operand1,operand2,lineNum);
}
}
void readAddition(string storeVar,string op1,string op2,int lineNum)
{
cout << "In line " << lineNum+1 << " >> "
<< op1<<" and "<<op2<<" are added and assigned to "<<storeVar<<endl;
}
void readSubtraction(string storeVar,string op1,string op2,int lineNum)
{
cout << "In line " << lineNum+1 << " >> "
<< op1<<" and "<<op2<<" are subtracted and assigned to "<<storeVar<<endl;
}
void readMultiplication(string storeVar,string op1,string op2,int lineNum)
{
cout << "In line " << lineNum+1 << " >> "
<< op1<<" and "<<op2<<" are multipied and assigned to "<<storeVar<<endl;
}
void readDivision(string storeVar,string op1,string op2,int lineNum)
{
cout << "In line " << lineNum+1 << " >> "
<< op1<<" is divided by "<<op2<<" and assigned to "<<storeVar<<endl;
}
void readRemainder(string storeVar,string op1,string op2,int lineNum)
{
cout << "In line " << lineNum+1 << " >> "
<< op1<<" is divided by "<<op2<<" and Remainder is assigned to "<<storeVar<<endl;
}