diff options
author | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
commit | 9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch) | |
tree | eb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/Final Program | |
download | school-code-master.tar.gz school-code-master.tar.bz2 school-code-master.zip |
Diffstat (limited to 'C++/Final Program')
-rw-r--r-- | C++/Final Program/Final.cpp | 247 | ||||
-rw-r--r-- | C++/Final Program/INSTRUCTIONS | 50 | ||||
-rw-r--r-- | C++/Final Program/person.h | 15 |
3 files changed, 312 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/>. + */ diff --git a/C++/Final Program/INSTRUCTIONS b/C++/Final Program/INSTRUCTIONS new file mode 100644 index 0000000..277f82a --- /dev/null +++ b/C++/Final Program/INSTRUCTIONS @@ -0,0 +1,50 @@ + Final Program +Due on Tuesday, November 29th before midnight (no late assignments accepted since this is the last day of class) +200 Points +Write a program that does the following: + + Create a parent class called Person and it will have the variables to store first name, last name and their favorite movie + Move the Person class into a header file (you may keep the code together until finished, then move it to a header file to make this easier) + Create a child class that inherits from the Person class called Movie. It will store the variables movie name, box office gross, and year made + Get data via the keyboard or an input file for each of the above variables. Please store at least 3 sets of data to make the program interesting + As you read in the movie name, check it for <HTML> tags and remove any found + Create a simple menu that will ask a user if they want to: + Sort on the movie name + Sort on the box office gross + Sort on the year the movie was made + Display the highest grossing movie's info + Display the lowest grossing movie's info + The menu should loop until the user is finished making choices + If the person's favorite movie matches the a movie entered, output a special message to the screen + Output to the screen each time the user makes a selection + +Assignment Notes: + + You are free to use arrays or vectors. Or, you can mix/match. It is up to you. + It will be easier if you have all of your functions in a class. This is not required though. + You can get the information via the keyboard or from an input file. Up to you. + Your variables should be in a class - Private or Protected sections. + I will be closely watching for cheating (copying from friends, online help, etc.) + +General Notes: + + Be sure to use comments in your program: Name, Program Description, Date and anywhere else in the program you deem necessary. + Much of this code came from the midterm, so you can watch the midterm key videos to see how to write a lot of this code + I will provide limited help in the classroom and/or email. Being a final exam, I cannot help a lot. I recommend you watch the recorded lectures on Blackboard since everything I ask you to do in this exam has examples in those lectures + +Grading Rubric: + + If you do not include comments at the top of the program (name, program description, date), you will lose 30 points + If you do not use functions, then your program will not be OOP and you will get a 0/200 + If your program is not OOP, then you will get a 0/200 + If your program does not use inheritance, you will lose 75 points + If your program does not sort or sort properly, you will lose up to 60 points + If your program does not output a special message when a movie name matches the user's favorite movie, you will lose 20 points + If your program uses global variables, you will lose 10 points for each used + If your program does not compile (run), then I will give a grade of 0/200. But will give you the change to repair for points back (some points are better than none) + If your program is not formatted nicely (code all over the place, ugly), you will lose up to 50 points depending on the extent + If your program stops working when I run it, you will lose points. The exact amount depends on the severity of the error + If your program still has your friend's name on it, I will send you a message asking you to try harder while giving you a 0/200 + If your program looks like a a professional programmer wrote it, I will write to you to ask if you want a job. Well, maybe not. But, I will ask about the code + This is just a list of typical issues I run into when grading to give you some idea of where your points go. Points can be taken off for other reasons. + diff --git a/C++/Final Program/person.h b/C++/Final Program/person.h new file mode 100644 index 0000000..2ec6b47 --- /dev/null +++ b/C++/Final Program/person.h @@ -0,0 +1,15 @@ +#include <string> +using namespace std; +class Person { + private: + string fname; + string lname; + string favmov; + public: + void set_fname(string x) { fname = x; } + void set_lname(string x) { lname = x; } + void set_favmov(string x) { favmov = x; } + string get_fname() { return fname; } + string get_lname() { return lname; } + string get_favmov() { return favmov; } +}; |