summaryrefslogtreecommitdiffstats
path: root/C++/Vectors
diff options
context:
space:
mode:
Diffstat (limited to 'C++/Vectors')
-rw-r--r--C++/Vectors/Vectors.cpp139
-rw-r--r--C++/Vectors/input.txt50
-rw-r--r--C++/Vectors/instructions.txt39
3 files changed, 228 insertions, 0 deletions
diff --git a/C++/Vectors/Vectors.cpp b/C++/Vectors/Vectors.cpp
new file mode 100644
index 0000000..67adaae
--- /dev/null
+++ b/C++/Vectors/Vectors.cpp
@@ -0,0 +1,139 @@
+// Name: msglm
+// Date: Sep 8th, 2022
+// Program Name: Vectirs
+// Description: Read in a file, output the data to the screen and the student who has the highest credit hours and highest GPA.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+#include <array>
+#include <iomanip>
+using namespace std;
+
+//initalizes the file
+void initalize(string location, ifstream & fileVar) {
+ fileVar.open(location);
+
+ if (!fileVar) {
+ cout << "ERROR! " << location << " failed to open!";
+ exit(1);
+ }
+}
+
+//Takes in the initalized file and turns it into a vector of arrays of strings
+vector<array<string, 10>> serializeIntoVecArr(ifstream & fileVar) {
+ vector<array<string, 10>> studentDataContainer;
+ studentDataContainer.push_back(array<string, 10>());
+ int student = 0;
+ int data = 0;
+
+ while(getline(fileVar, studentDataContainer[student][data]) && fileVar.peek() != EOF) {
+ data = data + 1;
+ if (data == 10) {
+ data = 0;
+ student = student + 1;
+ //This initializes the next set of arrays
+ studentDataContainer.push_back(array<string, 10>());
+ }
+ }
+ return studentDataContainer;
+}
+
+
+//Prints out all the data in a tabular format
+void allData(vector<array<string, 10>> studentDataContainer) {
+
+ //this code repetition is gross
+ //Perhaps I could have made this cleaner
+ cout << left << setw(25) << "First Name" << " ";
+ cout << left << setw(25) << "Last Name" << " ";
+ cout << left << setw(25) << "T-Number" << " ";
+ cout << left << setw(25) << "Major" << " ";
+ cout << left << setw(25) << "Advisor" << " ";
+ cout << left << setw(25) << "GPA" << " ";
+ cout << left << setw(25) << "Credit Hours" << " ";
+ cout << left << setw(25) << "Years until Graduation" << " ";
+ cout << left << setw(25) << "Hardest Class" << " ";
+ cout << left << setw(25) << "Easiest Class" << " ";
+
+ //C++ 11 range based loops
+ //I wish I knew about these earlier
+ for (array<string, 10> student : studentDataContainer) {
+ cout << endl;
+ for (string data : student) {
+ cout << left << setw(25) << data << " ";
+ }
+ }
+
+}
+
+
+
+void highestCreditHours(vector<array<string, 10>> studentDataContainer) {
+ cout << "\n\nStudent with highest credit hours:\n";
+ int highestStudent = 0;
+ int highest = 0;
+
+ //gets the largest using only one pass through
+ for(int studentPos = 0; studentPos < studentDataContainer.size(); studentPos++) {
+ for (string data : studentDataContainer[studentPos]) {
+ if (data[6] > highest) {
+ highest = data[6];
+ highestStudent = studentPos;
+ }
+ }
+ }
+
+ //Outputs all the data of the largest
+ for (int dataPos = 0; dataPos < 10; dataPos++) {
+ cout << left << setw(25) << studentDataContainer[highestStudent][dataPos] << " ";
+ }
+}
+
+//clone of highestCreditHours
+void highestGPA(vector<array<string, 10>> studentDataContainer) {
+ cout << "\n\nStudent with highest GPA \n";
+ int highestStudent = 0;
+ int highest = 0;
+
+ for(int studentPos = 0; studentPos < studentDataContainer.size(); studentPos++) {
+ for (string data : studentDataContainer[studentPos]) {
+ if (data[7] > highest) {
+ highest = data[7];
+ highestStudent = studentPos;
+ }
+ }
+ }
+
+ for (int dataPos = 0; dataPos < 10; dataPos++) {
+ cout << left << setw(25) << studentDataContainer[highestStudent][dataPos] << " ";
+ }
+
+}
+
+int main() {
+ //Variable declaration
+ ifstream data;
+
+
+ //"Read in an unknown number of records from an input file and store that data into vector variables for the below"
+ //
+ //The data will be going into a vector, but that vector will hold arrays at a fixed size since each student's data will be fixed
+ //This makes accessing the data infinitely easier
+ initalize("input.txt", data);
+ vector<array<string, 10>> serializedVectorArray = serializeIntoVecArr(data);
+
+ allData(serializedVectorArray);
+ highestCreditHours(serializedVectorArray);
+ highestGPA(serializedVectorArray);
+
+}
+
+/*
+ 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++/Vectors/input.txt b/C++/Vectors/input.txt
new file mode 100644
index 0000000..a7ff2f7
--- /dev/null
+++ b/C++/Vectors/input.txt
@@ -0,0 +1,50 @@
+James
+May
+T-20425
+Information Technology
+Jeff Kenney
+4.0
+36
+2
+Ethics
+Programming
+Jennifer
+May
+T-22343
+Information Technology
+Jeff Kenney
+3.0
+26
+3
+Repiar
+Programming
+Anonymous
+Anonymous
+T-11111
+Information Technology
+Megan Lastname
+3.98
+30
+2
+Critical Thinking
+Orientation
+Epic
+Fail
+T-2042587
+Information Technology
+Jef Kenney
+2.0
+50
+2
+beingalive
+fail
+r
+rMay
+T-22143120425
+Information Technology
+Jeff Kenney
+2.76
+20
+3
+r
+r
diff --git a/C++/Vectors/instructions.txt b/C++/Vectors/instructions.txt
new file mode 100644
index 0000000..a40c663
--- /dev/null
+++ b/C++/Vectors/instructions.txt
@@ -0,0 +1,39 @@
+ Write a program that does the following:
+
+ Read in an unknown number of records from an input file and store that data into vector variables for the below:
+ First Name
+ Last Name
+ T-Number
+ Major
+ Advisor Name
+ GPA
+ Credit Hours
+ Year expected to graduate
+ Hardest class taken so far
+ Easiet class taken so far
+
+ Use functions for each of the below:
+ Function to check to see if input file was found
+ Function to read in data from input file
+ Function to output all data to screen and output file
+ Function to output the student's information that has the highest number of credit hours
+ Function to output the student's information that has the highest GPA
+
+General Notes:
+Be sure to use comments in your program: Name, Program Description, Date and anywhere else in the program you deem necessary. You do not need to sort the data to get the highest credit hours or GPA. There are much easier ways of doing this.
+If you are stuck, I will help you!
+Grading Rubric:
+
+ If you do not include comments at the top of the program (name, program description, date), you will lose 15 points
+ If you do not use functions, you will use 10 points per missing function (50 points)
+ If your program does not compile (run), then I will give a grade of 0/100. But will give you the change to repair for points back (some points are better than none)
+ If your program is late (within 48 hours of the due date), you will lose 25 points
+ If your program uses global variables, you will lose 5 points for each used
+ If your program is late beyond the 48 hour due date, I will typically still accept it, but you will lose far more points. Depends on when you turn it in
+ If you submit your program in a Word document, you will lose 20 points and will need to resubmit your program for grading. Please only submit .cpp files
+ If your program is not formatted nicely (code all over the place, ugly), you will lose up to 25 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/100
+ If your program looks like 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.
+