summaryrefslogtreecommitdiffstats
path: root/C++/TwoDimensionalArray
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/TwoDimensionalArray
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/TwoDimensionalArray')
-rw-r--r--C++/TwoDimensionalArray/TwoDimensionalArray.cpp55
-rw-r--r--C++/TwoDimensionalArray/student_data.txt5
2 files changed, 60 insertions, 0 deletions
diff --git a/C++/TwoDimensionalArray/TwoDimensionalArray.cpp b/C++/TwoDimensionalArray/TwoDimensionalArray.cpp
new file mode 100644
index 0000000..a96c64b
--- /dev/null
+++ b/C++/TwoDimensionalArray/TwoDimensionalArray.cpp
@@ -0,0 +1,55 @@
+// Name: msglm
+// Date:
+// Program Name:
+// Description:
+
+
+#include <iostream>
+#include <string>
+#include <iomanip>
+#include <fstream>
+using namespace std;
+
+// Named constants
+
+int main() {
+
+ //Variable declaration
+ double test[5][3];
+ string name[5];
+ int row;
+ int col;
+ ifstream inFile;
+ // open file
+ inFile.open("student_data.txt");
+
+ //Title and desc.
+ cout << "Two dimentional array example \n\n this program utilizes parallel arrays: one being an one-dimentional \n array to store student names and the other being a two-dimentional \n array to store 3 exam scores per student. the input will be read fron an external file and then be printed on the screen\n\n";
+
+ //Read arrays data from the file and store in both arrays
+ for (row=0; row < 5; row++) {
+ inFile >> name[row];
+ for (col = 0; col < 3; col++) {
+ inFile >> test[row][col];
+ }
+ }
+ cout << setw(10) << left << "Name" << setw(7) << right << "Test 1" << setw(7) << "Test 2" << setw(7) << "Test 3" << endl;
+
+ for (row = 0; row < 5; row++) {
+ cout << setw(10) << left << name[row];
+ for (col = 0; col < 3; col++) {
+
+ cout << setw(7) << right << test[row][col];
+
+ }
+ cout << endl;
+ }
+}
+
+
+/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
diff --git a/C++/TwoDimensionalArray/student_data.txt b/C++/TwoDimensionalArray/student_data.txt
new file mode 100644
index 0000000..82312f9
--- /dev/null
+++ b/C++/TwoDimensionalArray/student_data.txt
@@ -0,0 +1,5 @@
+Amy 89 54 92
+Bob 92 88 65
+Carl 75 87 91
+Darla 98 94 90
+Eve 65 75 85 \ No newline at end of file