-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hanks Homework, #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.3) | ||
project(Test) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
|
||
set(SOURCE_FILES main.cpp) | ||
add_executable(Test ${SOURCE_FILES}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Zach Henry | ||
[email protected] | ||
Passcode_yes | ||
-500 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
std::string name = "",email = "",passcode = "",time_zone = "",file_path = ""; | ||
//input = std::cin , output = std::cout; Can this be done? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can put |
||
void users_name() | ||
{ | ||
do { | ||
std::cout<< "Enter your Name:\n"; | ||
getline (std::cin, name); | ||
} while (name == ""); | ||
} | ||
void email_address(){do { | ||
std::cout<< "Enter your Email:\n"; | ||
getline (std::cin, email); | ||
} while (email == ""); | ||
} | ||
void password(){do { | ||
std::cout<< "Enter a unique Passcode:\n"; | ||
getline (std::cin, passcode); | ||
} while (passcode == "");} | ||
void timezone() | ||
{ | ||
do { | ||
std::cout<< "Enter your Time Zone:\n"; | ||
getline (std::cin, time_zone); | ||
} while (time_zone == ""); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a new line of white space between your functions |
||
void create(){ | ||
users_name(); | ||
email_address(); | ||
password(); | ||
timezone(); | ||
|
||
std::cout << "Enter path to Known Recipients file:\n"; | ||
getline (std::cin, file_path); | ||
if (file_path == "") { | ||
file_path = "knownrecipients.txt"; | ||
} | ||
|
||
std::ofstream init_outputf; | ||
init_outputf.open(file_path); | ||
|
||
init_outputf << name << '\n'; | ||
init_outputf << email << '\n'; | ||
init_outputf << passcode << '\n'; | ||
init_outputf << time_zone << '\n'; | ||
|
||
init_outputf.close(); | ||
} | ||
|
||
void reconfigure(){ | ||
std::string edit_file_path, edit_name = "",edit_email = "",edit_passcode = "",edit_timezone = ""; | ||
std::cout << "Enter path to Known Recipients file:\n"; | ||
std::cin >> edit_file_path; | ||
|
||
std::ifstream edit_file_input; | ||
bool file_found = true; | ||
|
||
|
||
edit_file_input.open(edit_file_path); | ||
|
||
if (edit_file_input) { | ||
|
||
edit_file_input >> edit_name; | ||
std::cout << "The Name we have is " << edit_name<<'\n'; | ||
|
||
edit_file_input >> edit_email; | ||
edit_file_input >> edit_passcode; | ||
edit_file_input >> edit_timezone; | ||
edit_file_input.close(); | ||
}else{ | ||
file_found = false; | ||
std::cout << "We are having a little problem\n"; | ||
} | ||
|
||
if (file_found) { | ||
std::ofstream edit_output_file; | ||
edit_output_file.open(edit_file_path); | ||
|
||
do { | ||
std::cout << "Enter the new Name: \n"; | ||
getline(std::cin, edit_name); | ||
}while (edit_name == ""); | ||
|
||
edit_output_file << edit_name << '\n'; | ||
edit_output_file << edit_email << '\n'; | ||
edit_output_file << edit_passcode << '\n'; | ||
edit_output_file << edit_timezone << '\n'; | ||
|
||
edit_output_file.close(); | ||
}else{ | ||
std::cout << "Find correct file path before editing.\n"; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
std::cout << "Please enter 'create' to initialize config file or 'reconfigure' to edit the file:\n"; | ||
if (static_cast<std::string>(argv[1]) == "create") | ||
{ | ||
std::cout << "Prepping the creation of the Config File.\n"; | ||
create(); | ||
} | ||
else if (static_cast<std::string>(argv[1]) == "reconfigure") | ||
{ | ||
std::cout << "Starting the Reconfiguration process.\n"; | ||
reconfigure(); | ||
} | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dangerous global variables that are not const could lead to data side-effects an difficult debugging. These should be within you main function or const.