summaryrefslogtreecommitdiffstats
path: root/C++/Final Program/Final.cpp
blob: 10894c3f395ea44467caa4bc6b2e0db159181bed (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Name: msglm
// Date: Nov 29th 2022
// Program Name: Final Program
// Description: The last hurrah!


//This is it, the last time I will be touching C++ while not being paid!
//But seriously, this class has been great, especially for an online class. I'm glad you were receptive to my comments and I appreciate the feedback given. The topics, while filled with gross C++isms, is useful in the industry and im glad I got to practice and refine my skills in them (even if I disliked the content). 
//For hobby projects, I'll absolutely be avoiding C++! However, this class has opened up some rabbit holes on topics to go down (such as FORTH programming and functional programming) and has let me develop my side-effect avoidant style of coding. These will surely be useful for my own hobby projects.
//Anyway, This, and the other assignment you put out, will likely be the last you ever see from me, unless you can offer me a job or something (im graduating with my associates this semseter, so i'll consider it if you can offer!). For now at least, Goodbye and have a nice life! 

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include "person.h"
using namespace std;

//Classes

class Movie : public Person {
    private:
        string movieName;
        string boxOffice;
        int year;
        bool special;
    public:
        void set_movieName(string x) { movieName = x; }
        void set_boxOffice(string x) { boxOffice = x; }
        void set_year(int x) { year = x; }
        string get_movieName() { return movieName; }
        string get_boxOffice() { return boxOffice; }
        int get_year() { return year; }

        bool chosenIsFav() {
            if (movieName == get_favmov()) {
                return true;
            }
            return false;
        }
};

string sanitize(string userInput) {
    bool insideATag = false;
    bool metTheTagTerminator = false;
    int beginBracketPos;
    int endBracketPos;
    int tagLength;

    for (int charPos=0; charPos<=userInput.length();charPos++) {
        if (insideATag && metTheTagTerminator) {

            tagLength = (endBracketPos-beginBracketPos)+1;
            userInput.erase(beginBracketPos, tagLength);
            charPos = 0;
            insideATag = false;
            metTheTagTerminator = false;
        }
        if (userInput[charPos] == '<') {
            insideATag = true;
            beginBracketPos = charPos;
        }

        if (userInput[charPos] == '>' && insideATag) {
            metTheTagTerminator = true;
            endBracketPos = charPos;
        }


    }
    return userInput;
}


Movie getInput() {
    Movie movie;
    string temp;

    cout << "===Enter your information===\n";
    cout << "Please enter your first name: ";
    cin >> temp;
    movie.set_fname(sanitize(temp));

    cout << "Please enter your last name: ";
    cin >> temp;
    cin.ignore();
    movie.set_lname(sanitize(temp));

    cout << "Please enter your favorite movie: ";
    getline(cin, temp);
    movie.set_favmov(sanitize(temp));

    cout << "Please enter the movie's name: ";
    getline(cin, temp);
    movie.set_movieName(sanitize(temp));

    cout << "Please enter the movie's box office: ";
    cin >> temp;
    movie.set_boxOffice(sanitize(temp));

    cout << "Please enter the movie's year of release: ";
    cin >> temp;
    movie.set_year(stoi(sanitize(temp)));
    return movie;
}


vector<Movie> sort(vector<Movie> movieList, int menuOption) {
    Movie temp;
    switch(menuOption) {
        case 1:
            for (int pos = 0; pos < movieList.size() - 1; pos++) {
                for (int comparePos = 0; comparePos < ((movieList.size() - 1) - pos); comparePos++) {
                    if(movieList[comparePos].get_movieName() > movieList[comparePos + 1].get_movieName()) {
                        temp = movieList[comparePos];
                        movieList[comparePos] = movieList[comparePos + 1];
                        movieList[comparePos + 1] = temp;
                    }
                }
            }
            break;
        case 2:
            for (int pos = 0; pos < movieList.size() - 1; pos++) {
                for (int comparePos = 0; comparePos < ((movieList.size() - 1) - pos); comparePos++) {
                    if(movieList[comparePos].get_year() > movieList[comparePos + 2].get_year()) {
                        temp = movieList[comparePos];
                        movieList[comparePos] = movieList[comparePos + 1];
                        movieList[comparePos + 1] = temp;
                    }
                }
            }
            break;
        case 3:
            for (int pos = 0; pos < movieList.size() - 1; pos++) {
                for (int comparePos = 0; comparePos < ((movieList.size() - 1) - pos); comparePos++) {
                    if(stof(movieList[comparePos].get_boxOffice()) > stof(movieList[comparePos + 1].get_boxOffice())) {
                        temp = movieList[comparePos];
                        movieList[comparePos] = movieList[comparePos + 1];
                        movieList[comparePos + 1] = temp;
                    }
                }
            }
            break;
        case 4:
            //Display the highest grossing movie's info
            for (int pos = 0; pos < movieList.size() - 1; pos++) {
                for (int comparePos = 0; comparePos < ((movieList.size() - 1) - pos); comparePos++) {
                    if(stof(movieList[comparePos].get_boxOffice()) > stof(movieList[comparePos + 1].get_boxOffice())) {
                        temp = movieList[comparePos];
                        movieList[comparePos] = movieList[comparePos + 1];
                        movieList[comparePos + 1] = temp;
                    }
                }
            }
            movieList.erase(movieList.begin(),movieList.end()-1);
            break;
        case 5:
            //Display the lowest grossing movie's info
            for (int pos = 0; pos < movieList.size() - 1; pos++) {
                for (int comparePos = 0; comparePos < ((movieList.size() - 1) - pos); comparePos++) {
                    if(stof(movieList[comparePos].get_boxOffice()) > stof(movieList[comparePos + 1].get_boxOffice())) {
                        temp = movieList[comparePos];
                        movieList[comparePos] = movieList[comparePos + 1];
                        movieList[comparePos + 1] = temp;
                    }
                }
            }
            movieList.erase(movieList.begin()+1,movieList.end());
            break;
    }
    return movieList;
}

void output(vector<Movie> movieDataContainer) {

    cout << left << setw(25) << "First Name" ;
    cout << left << setw(25) << "Last Name" ;
    cout << left << setw(25) << "Favorite Movie" ;
    cout << left << setw(25) << "Movie Name" ;
    cout << left << setw(25) << "Box Office" ;
    cout << left << setw(25) << "Year Released" ;

    for (Movie movie : movieDataContainer) {
        cout << endl;
        cout << left << setw(25) << movie.get_fname();
        cout << left << setw(25) << movie.get_lname();
        cout << left << setw(25) << movie.get_favmov();
        cout << left << setw(25) << movie.get_movieName();
        cout << left << setw(25) << movie.get_boxOffice();
        cout << left << setw(25) << movie.get_year();
        if (movie.chosenIsFav()) {
            cout << left << setw(15) << "<--- This individual's chosen movie is also their favorite!";
        }
    }
    cout << endl;
}


int menuOption() {
    int choice;
    cout << "1. Sort by Movie Name\n";
    cout << "2. Sort by Year Released\n";
    cout << "3. Sort by Box office gross\n";
    cout << "4. Display the highest grossing movie's info\n";
    cout << "5. Display the lowest grossing movie's info\n";
    cout << "Enter Selection: ";
    cin >> choice;
    return choice;
}




int main() {
    char finished;
    vector<Movie> movieVector;
    movieVector.push_back(getInput());
    movieVector.push_back(getInput());
    movieVector.push_back(getInput());


    //This is wrote in an uneligant way because I eliminated state when state would have been useful!
    //Since everything is just data being passed around, there's no actual state that would tell if a user is finished or not
    //To my knowledge, the concept of a functional Monad (https://en.wikipedia.org/wiki/Monad_(functional_programming) ) would
    //have solved this problem, but I'm writing in C++ and not LISP, also I don't know LISP!
    //
    //Maybe I should learn LISP or Haskell.
    //Wow, am I really going to be one of those functional programming nerds?
    //I really should have gotten a math degere instead of an IT one
    //however, the recession is looming and I need a job sooner rather than later!
    while(true) {
        output(sort(movieVector, menuOption()));
        cout << "Are you finished working with your data (Y/n)?: ";
        cin >> finished;
        if (finished == 'y' || finished == 'Y') {
            cout << "Acknowledged. Terminating now.\n";
            exit(0);
        }
    }
}
/*
   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/>.
   */