-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cpp
More file actions
149 lines (116 loc) · 4.12 KB
/
IO.cpp
File metadata and controls
149 lines (116 loc) · 4.12 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "IO.h"
void IO::clearScreen() {
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOut == INVALID_HANDLE_VALUE) return;
// Get the number of cells in the current buffer
if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
// Fill the entire buffer with spaces
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
// Fill the entire buffer with the current colors and attributes
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
// Move the cursor home
SetConsoleCursorPosition(hStdOut, homeCoords);
}
void IO::newLineSpace() {
std::cout << "-------------------------------------------------" << std::endl;
}
std::string IO::stringInitial(std::string strToWriteTo) {
// ProceedStr will hold the user's string response, and proceed will control the while-loop
std::string proceedStr;
bool proceed = false;
// Refer to: IO 1A + 1B
if (strToWriteTo == "name") {
IO::newLineSpace();
std::cout << "Please give a name for your event: " << std::endl;
IO::newLineSpace();
std::getline(std::cin, strToWriteTo);
// Let the user keep editing the name until they are satisfied with it
while (!proceed) {
IO::newLineSpace();
std::cout << "Is this name correct \"" << strToWriteTo << "\" ? (Y/N) : " << std::endl;
IO::newLineSpace();
std::getline(std::cin, proceedStr);
// Convert proceedStr to lowercase for checking purposes
std::transform(proceedStr.begin(), proceedStr.end(), proceedStr.begin(), ::tolower);
if (proceedStr == "y" || proceedStr == "yes")
proceed = true;
else if (proceedStr == "n" || proceedStr == "no") {
IO::newLineSpace();
std::cout << "Please give a name for your event: " << std::endl;
IO::newLineSpace();
std::getline(std::cin, strToWriteTo);
}
else {
IO::newLineSpace();
std::cout << "Unexpected input" << std::endl;
}
}
}
// This section will execute if the user is adding a description to their event
// More or less, this code is the same as the code for name
if (strToWriteTo == "description") {
IO::newLineSpace();
std::cout << "Please give a description for your event: " << std::endl;
IO::newLineSpace();
std::getline(std::cin, strToWriteTo);
while (!proceed) {
IO::newLineSpace();
std::cout << "Is this description correct?" << std::endl << std::endl;
std::cout << "\"" << strToWriteTo << "\" (Y/N) : " << std::endl;
IO::newLineSpace();
std::getline(std::cin, proceedStr);
std::transform(proceedStr.begin(), proceedStr.end(), proceedStr.begin(), ::tolower);
if (proceedStr == "y" || proceedStr == "yes")
proceed = true;
else if (proceedStr == "n" || proceedStr == "no") {
IO::newLineSpace();
std::cout << "Please give a description for your event: " << std::endl;
IO::newLineSpace();
std::getline(std::cin, strToWriteTo);
}
else {
IO::newLineSpace();
std::cout << "Unexpected input" << std::endl;
}
}
}
// Return whichever variable the user edited, so the correlating variable can be set in the Event object
return strToWriteTo;
}
int IO::formattedDate() {
// These variables may end up being used to set the day, month, and year values for the Event object
int day, month, year, formattedDate = 0;
IO::newLineSpace();
std::cout << "Please enter the month of your event: ";
std::cin >> month;
IO::newLineSpace();
std::cout << "Please enter the day of your event: ";
std::cin >> day;
IO::newLineSpace();
std::cout << "Please enter the year of your event: ";
std::cin >> year;
// Year will be in the form xxxx0000; Month in the form yy00; Day will just be zz
formattedDate += (year * pow(10, 4));
formattedDate += (month * pow(10, 2));
formattedDate += day;
// Return an integer in the format of xxxxyyzz
return formattedDate;
}