Using C++ and Using One Dimensional Parallel arrays. Create two arrays with 5 el
ID: 3661653 • Letter: U
Question
Using C++ and Using One Dimensional Parallel arrays.
Create two arrays with 5 elements each: one will hold Strings and the second will hold integers.
Write a program to ask the user to enter 5 student names and their ages. Output the data from the parallel arrays.
Sample Run: Your program must run exactly like the example below.
Enter a student name: Joe
Enter a student name: Mark
Enter a student name: Mary
Enter a student name: Michelle
Enter a student name: Aaron
Enter Joe’s Age: 25
Enter Mark’s Age: 24
Enter Mary’s Age: 35
Enter Michelle’s Age: 19
Enter Aaron’s Age: 65
Joe 25
Mark 24
Mary 35
Michelle 19
Aaron 65
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
void getData(int size, int [], char [][6]);
void sortData();
void main(){
int age[5];
char Students [5][6];
int size;
cout << "Enter size for arrays: ";
cin >> size;
getData(size,age,Students);
}
void getData(int size, int age[],char studentName[][6]) {
int index;
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
}
for (index = 0; index <= size -1; index++){
cout << "Enter age for " << studentName[index]
<< ": ";
cin >> age[index];
while (0 > age[index] ){
cout << "enter age for " << studentName[index]
<< ": ";
cin >> age[index];
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.