Skip to content

Commit ecd3f02

Browse files
committedDec 5, 2018
UX improvements
1 parent dc7ad64 commit ecd3f02

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed
 

‎UI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ std::string UI::getChoice(std::vector<std::string> *vector, int perLine) {
3535
count++;
3636
}
3737

38-
std::cout << std::endl;
38+
std::cout << "Enter your choice: ";
3939
unsigned long choice = getIntFromUser(1, vector->size());
4040
return vector->at(choice-1);
4141
}
@@ -64,9 +64,9 @@ unsigned long UI::getIntFromUser(unsigned long low, unsigned long high) {
6464
while (true) {
6565
unsigned long userInt = getIntFromUser();
6666
if (userInt < low) {
67-
std::cout << "You must enter a integer greater than or equal to " << low << std::endl;
67+
std::cout << "You must enter a integer greater than or equal to " << low << ". Please Try again: ";
6868
} else if (userInt > high) {
69-
std::cout << "You must enter a integer less than or equal to " << high << std::endl;
69+
std::cout << "You must enter a integer less than or equal to " << high << ". Please Try again:";
7070
} else {
7171
return userInt;
7272
}

‎audio.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void Audio::create_wav(vector<double> *sound_data, const std::string &fileName)
7878
if (sf_write_double(sf, sound_data->data(), sound_data->size()) != sound_data->size()) {
7979
fprintf(stderr, "%s\n", sf_error_number(sf_error(sf)));
8080
} else {
81-
std::cout << "Wrote EAS Alert to";
81+
std::cout << "Wrote EAS Alert to " << fileName << ".";
8282
}
8383
sf_write_sync(sf);
8484
sf_close(sf);

‎main.cpp

+40-36
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121

2222
#define TRUE 1
2323

24-
using namespace std;
25-
26-
void getAreas(vector<string> *locations);
24+
void getAreas(std::vector<std::string> *locations);
2725
int getDate();
2826
int getStartHour();
2927
int getStartMinute();
3028
std::string getParticipant();
3129
Alert::WATs getWat();
32-
string getOrigin();
33-
string getEvent();
34-
string getLength();
30+
std::string getOrigin();
31+
std::string getEvent();
32+
std::string getLength();
3533

3634
int main() {
3735
auto *a = new Alert();
@@ -55,43 +53,48 @@ int main() {
5553
a->participant = getParticipant();
5654
a->wat = getWat();
5755

58-
a->create_alert("eas_alert_1.wav");
56+
std::cout << "Enter file name, should end with .wav: ";
57+
std::string filename;
58+
std::cin >> filename;
59+
60+
a->create_alert(filename);
5961
delete a;
6062
exit(EXIT_SUCCESS);
6163

6264
}
6365

64-
string getLength() {
65-
vector<string> lengths = {"0015", "0030", "0045", "0100", "0115", "0130", "0145", "0200", "0215", "2030"};
66-
string length = UI::getChoice(&lengths);
66+
std::string getLength() {
67+
std::vector<std::string> lengths = {"0015", "0030", "0045", "0100", "0115", "0130", "0145", "0200", "0215", "2030"};
68+
std::string length = UI::getChoice(&lengths);
6769
return length;
6870
}
6971

70-
string getEvent() {
71-
vector<string> nationalEvents = {"EAN", "NIC", "NPT", "RMT", "RWT"};
72+
std::string getEvent() {
73+
std::vector<std::string> nationalEvents = {"EAN", "NIC", "NPT", "RMT", "RWT"};
7274

73-
vector<string> stateEvents = { "ADR", "AVW", "AVA", "BZW", "BLU", "CAE", "CDW", "CEM", "CFW", "CFA", "DSW", "EQW", "EVI",
74-
"EWW", "FRW", "FFW", "FFA", "FFS", "FLW", "FLA", "FLS", "HMW", "HWW", "HWA", "HUW", "HUA",
75-
"HLS", "LEW", "LAE", "NMN", "TOE", "NUW", "DMO", "RHW", "SVR", "SVA", "SVS", "SPW", "SMW",
76-
"SPS", "SSA", "SSW", "TOR", "TOA", "TRW", "TRA", "TSW", "TSA", "VOW", "WSW", "WSA"};
77-
vector<string> events;
75+
std::vector<std::string> stateEvents = { "ADR", "AVW", "AVA", "BZW", "BLU", "CAE", "CDW", "CEM", "CFW", "CFA", "DSW", "EQW", "EVI",
76+
"EWW", "FRW", "FFW", "FFA", "FFS", "FLW", "FLA", "FLS", "HMW", "HWW", "HWA", "HUW", "HUA",
77+
"HLS", "LEW", "LAE", "NMN", "TOE", "NUW", "DMO", "RHW", "SVR", "SVA", "SVS", "SPW", "SMW",
78+
"SPS", "SSA", "SSW", "TOR", "TOA", "TRW", "TRA", "TSW", "TSA", "VOW", "WSW", "WSA"
79+
};
80+
std::vector<std::string> events;
7881
events.insert(events.end(), nationalEvents.begin(), nationalEvents.end());
7982
events.insert(events.end(), stateEvents.begin(), stateEvents.end());
80-
string event = UI::getChoice(&events, 6);
83+
std::string event = UI::getChoice(&events, 6);
8184
return event;
8285
}
8386

84-
string getOrigin() {
85-
vector<string> originators = {"EAS", "CIV", "WXR", "PEP"};
87+
std::string getOrigin() {
88+
std::vector<std::string> originators = {"EAS", "CIV", "WXR", "PEP"};
8689

87-
string origin = UI::getChoice(&originators);
90+
std::string origin = UI::getChoice(&originators);
8891
return origin;
8992
}
9093

9194
Alert::WATs getWat() {
92-
cout << "Select the Attention Tone";
93-
vector<string> wats = { "NRW", "Normal" };
94-
string choice = UI::getChoice(&wats);
95+
std::cout << "Select the Attention Tone" << std::endl;
96+
std::vector<std::string> wats = { "NRW", "Normal" };
97+
std::string choice = UI::getChoice(&wats);
9598
if (choice == wats[0]) {
9699
return Alert::NRW_WAT;
97100
} else {
@@ -101,40 +104,41 @@ Alert::WATs getWat() {
101104
}
102105

103106
std::string getParticipant() {
104-
cout << "Participant: ";
107+
std::cout << "Participant: ";
105108
std::string part;
106109
while (TRUE) {
107-
cin >> part;
110+
std::cin >> part;
108111
if (part.length() != 8) {
109-
cout << "Participant must 8 characters long";
112+
std::cout << "Participant must 8 characters long";
110113
}
111114
return part;
112115
}
113116
}
114117

115118
int getDate() {
116-
cout << "Enter Start Date: ";
117-
return UI::getIntFromUser(0, 366);
119+
std::cout << "Enter Start Date: ";
120+
return UI::getIntFromUser(0, 366);
118121
}
119122

120123
int getStartHour() {
121-
cout << "Enter Start Hour: ";
124+
std::cout << "Enter Start Hour: ";
122125
return UI::getIntFromUser(0, 23);
123126
}
124127

125128

126129
int getStartMinute() {
127-
cout << "Enter the Start Minute: ";
130+
std::cout << "Enter the Start Minute: ";
128131
return UI::getIntFromUser(0, 59);
129132
}
130133

131-
void getAreas(vector<string> *locations) {
134+
void getAreas(std::vector<std::string> *locations) {
135+
std::cout << "Type \"DONE\" when done entering locations" << std::endl;
132136
for (int i = 0; i < 31; i++) {
133-
string location;
134-
cout << "Enter location: ";
135-
cin >> location;
137+
std::string location;
138+
std::cout << "Enter location: ";
139+
std::cin >> location;
136140
if (location == "DONE") {
137-
cout << "Done Entering locations." << endl;
141+
std:: cout << "Done Entering locations." << std::endl;
138142
break;
139143
} else {
140144
locations->push_back(Utils::zero_pad_int(location, 6));

0 commit comments

Comments
 (0)