From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/ParallelArray/ParallelArray.cpp | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 C++/ParallelArray/ParallelArray.cpp (limited to 'C++/ParallelArray/ParallelArray.cpp') diff --git a/C++/ParallelArray/ParallelArray.cpp b/C++/ParallelArray/ParallelArray.cpp new file mode 100644 index 0000000..b859023 --- /dev/null +++ b/C++/ParallelArray/ParallelArray.cpp @@ -0,0 +1,53 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include +#include +#include +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 . + */ + -- cgit v1.2.3