summaryrefslogtreecommitdiffstats
path: root/C++/Polymorphism/Polymorphism.cpp
blob: d09c2d68a990023618af1a728625026c1c1563e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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 <iostream>
#include <string>
#include <fstream>
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 <https://www.gnu.org/licenses/>.
   */