summaryrefslogtreecommitdiffstats
path: root/C++/Final Program/Final.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'C++/Final Program/Final.cpp')
-rw-r--r--C++/Final Program/Final.cpp247
1 files changed, 247 insertions, 0 deletions
diff --git a/C++/Final Program/Final.cpp b/C++/Final Program/Final.cpp
new file mode 100644
index 0000000..10894c3
--- /dev/null
+++ b/C++/Final Program/Final.cpp
@@ -0,0 +1,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/>.
+ */