From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/TwoDimensionalArray/TwoDimensionalArray.cpp | 55 +++++++++++++++++++++++++ C++/TwoDimensionalArray/student_data.txt | 5 +++ 2 files changed, 60 insertions(+) create mode 100644 C++/TwoDimensionalArray/TwoDimensionalArray.cpp create mode 100644 C++/TwoDimensionalArray/student_data.txt (limited to 'C++/TwoDimensionalArray') 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 +#include +#include +#include +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 . + */ + 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 -- cgit v1.2.3