summaryrefslogtreecommitdiffstats
path: root/C++/ParallelArray
diff options
context:
space:
mode:
Diffstat (limited to 'C++/ParallelArray')
-rw-r--r--C++/ParallelArray/ParallelArray.cpp53
1 files changed, 53 insertions, 0 deletions
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 <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/>.
+ */
+