-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupportMethods.cpp
More file actions
126 lines (104 loc) · 2.69 KB
/
SupportMethods.cpp
File metadata and controls
126 lines (104 loc) · 2.69 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "SupportMethods.h"
char SupportMethods :: getCharacter()
{
string providedCharacter = "";
char character = {0};
while (true)
{
getline(cin, providedCharacter);
if (providedCharacter.length() == 1)
{
character = providedCharacter[0];
break;
}
cout << "This is not one character. Please enter again." << endl;
}
return character;
}
string SupportMethods :: changeFirstLetterToCapitalAndOtherToLowercase(string text)
{
if (!text.empty())
{
transform(text.begin(), text.end(), text.begin(), ::tolower);
text[0] = toupper(text[0]);
}
return text;
}
string SupportMethods :: getNumber(string text, int characterPosition)
{
string number = "";
while(isdigit(text[characterPosition]) == true)
{
number += text[characterPosition];
characterPosition ++;
}
return number;
}
float SupportMethods :: loadFloat()
{
string providedData = "";
float number;
while (true)
{
cin.clear();
getline(cin, providedData);
providedData = changeCommaToDot(providedData);
stringstream myStream(providedData);
if (myStream >> number)
break;
cout << "This is not the amount. Please add again. " << endl;
}
return number;
}
int SupportMethods :: convertStringToInt(string number)
{
int numberInt;
istringstream iss(number);
iss >> numberInt;
return numberInt;
}
string SupportMethods :: convertIntToString(int number)
{
ostringstream ss;
ss << number;
string str = ss.str();
return str;
}
string SupportMethods :: loadLine()
{
string input = "";
getline(cin, input);
return input;
}
string SupportMethods :: removeDashFromDate(string date) {
string stringDatewithoutDash;
for (unsigned int i = 0 ; i <= date.length(); i++) {
if (date[i] != '-') {
stringDatewithoutDash += date[i];
}
}
return stringDatewithoutDash;
}
string SupportMethods :: addDashToDate(string date) {
string stringDateWithDash;
stringDateWithDash = date.insert (4,1,'-');
stringDateWithDash = stringDateWithDash.insert (7,1,'-');
cout << "Today date is: " << stringDateWithDash << endl;
return stringDateWithDash;
}
string SupportMethods :: convertFloatToString( float amount )
{
std::stringstream FloatToStr;
std::string str;
FloatToStr << amount;
FloatToStr >> str;
FloatToStr.clear();
return str;
}
string SupportMethods :: changeCommaToDot(string input) {
size_t foundComma = input.find(",");
if(foundComma != string::npos) {
input.replace(foundComma, 1, ".");
}
return input;
}