-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvartable.cpp
More file actions
39 lines (31 loc) · 1010 Bytes
/
vartable.cpp
File metadata and controls
39 lines (31 loc) · 1010 Bytes
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
#include "vartable.h"
#include <iostream>
using namespace std;
int VarTable::getIndex(string name){
for (int i=0; i < vartab.size(); i++)
if (name == vartab[i].name)
return i;
vartab.push_back({name,0}); // new entry in table
return vartab.size()-1;
}
float VarTable::getValue(int index){
return vartab[index].value;
}
int VarTable::setVar(string name, float value){
for (int i=0; i<vartab.size(); i++)
if (name == vartab[i].name) {
vartab[i].value = value;
return i;
}
vartab.push_back({name,value}); // new entry in table
return vartab.size()-1;
}
int VarTable::setVar(int index, float value){
vartab[index].value = value;
return index;
}
void VarTable::printVarTable(){
cout << "\nvar: "; for (const auto& element : vartab) cout << element.name << "\t" ;
cout << "\nvar: "; for (const auto& element : vartab) cout << element.value<< "\t";
cout << endl;
}