From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/Polymorphism/Polymorphism.cpp | 155 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 C++/Polymorphism/Polymorphism.cpp (limited to 'C++/Polymorphism/Polymorphism.cpp') diff --git a/C++/Polymorphism/Polymorphism.cpp b/C++/Polymorphism/Polymorphism.cpp new file mode 100644 index 0000000..d09c2d6 --- /dev/null +++ b/C++/Polymorphism/Polymorphism.cpp @@ -0,0 +1,155 @@ +// Name: msglm +// Date: Nov-14th-2022 +// Program Name: parse CSV +// Description: parses a character-seperated value sequence. Not very robust. + +//This program is a bit less barebones and cool than I wanted, that's because, while working on the original project, I noticed my GPU fan had gone out +//and that I have been risking overheating my computer. I promptly ceased using my computer and repaired the device. This was about 50% of the way through +//completing the program. By the time I had the thing fixed, I was working on borrowed time and opted to scrap the original project for something more simple. +// +//The project in question was a small, tile-based territorial control game where AI would battle it out for control over the whole board. I had a good portion of it done, but +//still a lot more to get done. Once I got my GPU back in, I saw how much was necessary, and ditched the whole project because of time constraints. +// +//Lesson learned: never do cool things when under a deadline. + +#include +#include +#include +using namespace std; + +class parseCSV { + public: + string input; + char delim; + string processed; + + void setdelim(char x) { + delim = x; + } + + void setdelim(string x) { + delim = x[0]; + } + + void takeInput() { + cout << "Please enter the data that you would like to be parsed\n"; + cin >> input; + } + + void takeInput(string toParse) { + input = toParse; + } + + void takeInput(ifstream & file) { + + file.open("input.txt"); + if (!file) { + cout << "ERROR! input.txt does not exist!"; + exit(1); + } + getline(file, input); + file.close(); + } + + void process() { + for(int charPos = 0; charPos < input.length(); charPos++) { + if (input.at(charPos) == delim) { + processed.push_back('\n'); + } else { + processed.push_back(input[charPos]); + } + } + + } + + void output() { + cout << processed; + } + + void output(string location) { + ofstream output; + output.open(location); + output << processed; + output.close(); + } + +}; + + +int main() { + + parseCSV parse; + int choice; + + //Taking in the data to be parsed + cout << "Would you like too...\n"; + cout << "1. Read input from a file\n"; + cout << "2. Input data manually\n"; + cout << "Enter Selection: "; + cin >> choice; + + switch (choice) { + case 1: + { + ifstream file; + parse.takeInput(file); + break; + } + case 2: + { + parse.takeInput(); + break; + } + default: + cout << "You did not give a valid input. Exiting."; + exit(1); + break; + } + + //Setting the deliminator + char temp; + cout << "Please selecte a deliminator for your file: "; + cin >> temp; + parse.setdelim(temp); + + //process the input + parse.process(); + + //Outputting + cout << "Would you like too...\n"; + cout << "1. Have the output put in a file\n"; + cout << "2. Have the output put on the screen\n"; + cout << "Enter Selection: "; + cin >> choice; + + switch (choice) { + case 1: + { + string temploc; + cout << "Where would you like to write the file?\n"; + cin >> temploc; + parse.output(temploc); + break; + } + case 2: + { + parse.output(); + break; + } + default: + { + cout << "You did not give a valid input. Exiting."; + exit(1); + break; + } + } + + +} +/* + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 ONLY as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + */ -- cgit v1.2.3