summaryrefslogtreecommitdiffstats
path: root/C++/TwoDimensionalArray/TwoDimensionalArray.cpp
blob: a96c64b1a5e8819c2f545be1fc63e2d6d4c431e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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/>.
 */