-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColumnDouble.cpp
76 lines (69 loc) · 2.32 KB
/
ColumnDouble.cpp
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
70
71
72
73
74
75
76
//
// Created by Christo on 3/14/2019.
//
#include "ColumnDouble.h"
/**
* \brief Constructor used to create a ColumnDouble from an existant table.
* @param columnName name of the Column.
* @param tableName name of the Table that owns the column.
*/
ColumnDouble::ColumnDouble(std::string columnName, std::string tableName) : Column(columnName, tableName) {
dataType = DOUBLE;
columnFile.open(columnFilePath, std::ios::out | std::ios::app);
if(columnFile){
columnFile<<enumStringMap.at(dataType)+"_type"<<std::endl;
}
columnFile.close();
}
/**
* \brief Constructor used to create a new ColumnDouble.
* @param columnName is the name of the Column.
* @param tableName is the name of the table that owns the column.
* @param description the description of the new Column.
*/
ColumnDouble::ColumnDouble(std::string columnName, std::string tableName, std::string description) : Column(columnName, tableName, description) {
dataType = DOUBLE;
columnFile.open(columnFilePath, std::ios::out | std::ios::app);
if(columnFile){
columnFile<<enumStringMap.at(dataType)+"_type"<<std::endl;
}
columnFile.close();
}
/**
* \brief Constructor used to open an existant column stored in the files of the program.
* @param columnFilePath is the path to the file.
*/
ColumnDouble::ColumnDouble(std::string columnFilePath) : Column(columnFilePath) {
this->columnFilePath=columnFilePath;
}
/**
* \brief method used to insert a new entry into the file
* @param data is the element to be inserted into the file.
*/
void ColumnDouble::addData(std::string data) {
columnFile.open(columnFilePath, std::ios::out | std::ios::app);
if(columnFile){
columnFile<<std::stod(data)<<std::endl;
}
columnFile.close();
}
/**
* \brief used to calculate the sum of all the doubles stored in the file
* @return the sum of all the doubles in the column
*/
std::string ColumnDouble::calSum() {
columnFile.open(columnFilePath, std::ios::in);
int counter = 0;
double toRet=0;
std::string data;
if(columnFile){
while(columnFile>>data){
counter++;
if(counter>=3){
toRet+=std::stod(data);
}
}
}
columnFile.close();
return std::to_string(toRet);
}