Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Test/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Test/.idea/Test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Test/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Test/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Test/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

359 changes: 359 additions & 0 deletions Test/.idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Test/CMakeLists.txt
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})
4 changes: 4 additions & 0 deletions Test/knownrecipients.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Zach Henry
[email protected]
Passcode_yes
-500
110 changes: 110 additions & 0 deletions Test/main.cpp
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 = "";
Copy link
Member

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.

//input = std::cin , output = std::cout; Can this be done?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put using std::cin; and using std::cout; up here and then just write cin and cout below.

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 == "");
}
Copy link
Member

Choose a reason for hiding this comment

The 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;
}