diff --git a/config_generator/.idea/.name b/config_generator/.idea/.name new file mode 100644 index 0000000..0001471 --- /dev/null +++ b/config_generator/.idea/.name @@ -0,0 +1 @@ +config_generator \ No newline at end of file diff --git a/config_generator/.idea/config_generator.iml b/config_generator/.idea/config_generator.iml new file mode 100644 index 0000000..0ae9d87 --- /dev/null +++ b/config_generator/.idea/config_generator.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config_generator/.idea/encodings.xml b/config_generator/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/config_generator/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/config_generator/.idea/misc.xml b/config_generator/.idea/misc.xml new file mode 100644 index 0000000..3eb495b --- /dev/null +++ b/config_generator/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config_generator/.idea/modules.xml b/config_generator/.idea/modules.xml new file mode 100644 index 0000000..db7df03 --- /dev/null +++ b/config_generator/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/config_generator/.idea/workspace.xml b/config_generator/.idea/workspace.xml new file mode 100644 index 0000000..40b85c4 --- /dev/null +++ b/config_generator/.idea/workspace.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1457568783508 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config_generator/CMakeLists.txt b/config_generator/CMakeLists.txt new file mode 100644 index 0000000..e3ed0ec --- /dev/null +++ b/config_generator/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.3) +project(config_generator) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +set(SOURCE_FILES main.cpp structures_header.h) +add_executable(config_generator ${SOURCE_FILES}) \ No newline at end of file diff --git a/config_generator/main.cpp b/config_generator/main.cpp new file mode 100644 index 0000000..eb6eb5d --- /dev/null +++ b/config_generator/main.cpp @@ -0,0 +1,140 @@ +#include "structures_header.h" +// Project should read the Config into the struct then Output the Struct to the file +int main() { + string selection = ""; + cout << "What would you like to do? Create , Edit , or Read :"; + cin >> selection; + if (selection == "Create") + { + writeConfig("C:\\Users\\Hanko\\Documents\\C++ Files\\Assignment3\\config.txt" , create_config()); + }else if (selection == "Edit") + { + writeConfig("C:\\Users\\Hanko\\Documents\\C++ Files\\Assignment3\\config.txt" , + edit_config("C:\\Users\\Hanko\\Documents\\C++ Files\\Assignment3\\config.txt", selection)); + }else if (selection == "Read") + { + writeConfig("C:\\Users\\Hanko\\Documents\\C++ Files\\Assignment3\\config.txt" , + read_config("C:\\Users\\Hanko\\Documents\\C++ Files\\Assignment3\\config1.txt")); + } + + return 0; +} +int size_finder(string path) +{ + int count = 0; + string line; + fstream myFile(path); + while(getline(myFile,line)) + { + count++; + } + return count; +} +configStruct read_config(string config_file_path) { + configStruct info; + int const SIZE = size_finder(config_file_path) + 1; + fstream file(config_file_path); + if (file.is_open()) { + string myArray[SIZE]; + cout <<"Config Read\n"; + for (int i = 0; i < SIZE; ++i) { + file >> myArray[i]; + } + info.first_name = myArray[0]; + info.last_name = myArray[1]; + info.email = myArray[2]; + info.password = myArray[3]; + info.timezone = myArray[4]; + +return info; + } +} + +configStruct create_config() { + configStruct create; + + cout <<"Create Config\n"; + cout << "Enter your first name , Last name email , password , and timezone ; Hit Enter after each input :"; + for (int i = 0; i < 5; ++i) { + if (i == 0) + { + cout <<"Enter yor first name : \n"; + std::cin >>create.first_name; + }else if (i == 1) + { + cout <<"Enter your Last name : \n"; + std::cin >> create.last_name; + }else if (i == 2) + { + cout <<"Enter your Email : \n"; + std::cin >> create.email; + }else if (i == 3) + { + cout <<"Enter your Passcode : \n"; + std::cin >> create.password; + }else + { + cout <<"Enter your timezone : \n"; + std::cin >>create.timezone; + } + + } + return create; + +} +configStruct edit_config(string f , string choice) { + configStruct edit; + fstream file(f); + string selection = ""; + cout <<"edit Config\n"; + if(file.is_open()){ + if(choice == "Edit") + { + cout <<"What would you like to Edit: \n"; + std::cin >>selection; + while (selection != "Done") { + if (selection == "First Name") + { + cout <<"Enter your first name : \n"; + std::cin >>edit.first_name; + }else if (selection == "Last Name") + { + cout <<"Enter your Last name : \n"; + std::cin >> edit.last_name; + }else if (selection == "Email") + { + cout <<"Enter your Email : \n"; + std::cin >> edit.email; + }else if (selection == "Passcode") + { + cout <<"Enter your Passcode : \n"; + std::cin >> edit.password; + }else if (selection == "Timezone") + { + cout <<"Enter your timezone : \n"; + std::cin >>edit.timezone; + } + + } + } + } + return edit; + +} + +bool writeConfig(string path , configStruct data) +{ + fstream file(path); + if(!file) + { + cout <<"File Didn't Work\n"; + return false; + }else{ + cout <<"Struct Output to file\n"; + file << data.first_name << '\n' << data.last_name << '\n' << data.email << '\n' << data.password << '\n' << data.timezone; + file.close(); + return true; + + } +} + diff --git a/config_generator/structures_header.h b/config_generator/structures_header.h new file mode 100644 index 0000000..0d63b62 --- /dev/null +++ b/config_generator/structures_header.h @@ -0,0 +1,19 @@ +#include + +using std::string; using std::cout; + +struct configStruct +{ + string first_name ,last_name, email , password , timezone; + +}; +bool writeConfig(string path , configStruct data); +int size_finder(string path); +using std::cout; +using std::cin; +using std::string; +using std::fstream; +#include +configStruct read_config(string config_file_path) ; +configStruct create_config(); +configStruct edit_config(string file , string choice); \ No newline at end of file