Assume that empName and empID are two parallel arrays of siz
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
string empName[] = {\"John\",\"Thomas\",\"George\",\"Mary\",\"Sarah\"}; //initialize empName array
int empId[] = {4,1,5,3,2}; //initialize empId array
int numEmp = 5, temp;
string str;
for(int i=0; i<numEmp; i++){ //outer loop which iterates numEmp times
for(int j=i; j<numEmp; j++){ //inner loop for comparision
if(empId[i]>empId[j]){ //check for bigger empId, if not in ascending order, just swap the two Ids positions also
temp = empId[i];
empId[i] = empId[j];
empId[j] = temp;
swap(empName[i],empName[j]); //swap corresponding empName also
}
}
}
cout << \"empId :\"<< flush; //print empId array
for(int i=0; i<numEmp; i++){
cout << empId[i] << \" \" << flush;
}
cout << \"\ empName :\"<< flush; //print empName array
for(int i=0; i<numEmp; i++){
cout << empName[i] << \" \" << flush;
}
cout << endl;
}
-----------------------------------------------------------------------------------
OUTPUT:

