diff options
Diffstat (limited to 'C++/TwoDimensionalArray/TwoDimensionalArray.cpp')
-rw-r--r-- | C++/TwoDimensionalArray/TwoDimensionalArray.cpp | 55 |
1 files changed, 55 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/>. + */ + |