summaryrefslogtreecommitdiffstats
path: root/C++/ParallelArray/ParallelArray.cpp
blob: b859023225d0a238fc2ae0d347e8afd97e4c29be (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
// Name: msglm
// Date: 
// Program Name:
// Description: 


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

// Named constants
const int ARRAY_SIZE = 5;

int main() {

    //Variable declaration
    string name[ARRAY_SIZE];
    int age[ARRAY_SIZE];

    //Program title and description for the user
    cout << "parallel array example " << endl << endl;
    cout << "This program shows the example of parallel arrays. arrays can\n only hold data of one type. so if you want to store something\n like names and ages you must store then in  different arrays\n\n this program will ask for 5 names and their corresponding\n ages and then output the results in columns " << endl << endl;

    //User input
    for(int i = 0; i < ARRAY_SIZE; i++) {
        cout << "Enter a name: ";
        getline(cin, name[i]);
        cout << "Enter the age: ";
        cin >> age[i];

        cin.ignore(); //ignores newln char after age before begin of name
    }


    //output

    //headlines
    cout << "\033[2J\033[1;1H";
    cout << setw(20) << left << "Name" << setw(4) << right << "Age" << endl;

    //names/ages
    for (int i = 0; i < ARRAY_SIZE; i++) {
        cout << setw(20) << left << name[i] << setw(4) << right << age[i] << 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/>.
 */