Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.
//Name: Nazmus //Program: Index Sort with Functions //Website: EasyProgramming.net #include <iostream> #include <string> using namespace std; void prompt(string name[7], int grade[7]); void init(int index[7]); void sort(string name[7], int index[7]); void output(string name[7], int grade[7], int index[7]); int main() { string name[7]; int grade[7]; int index[7]; prompt(name, grade); init(index); sort(name, index); output(name, grade, index); } void prompt(string name[7], int grade[7]) { for(int i=0;i<=6;i++) { cout << "Please enter name: "; cin >> name[i]; cout << "Please enter grade: "; cin >> grade[i]; } } void init(int index[7]) { for(int i=0;i<=6;i++) { index[i]=i; } } void sort(string name[7], int index[7]) { int i, j; for(i=0;i<=5;i++) { for(j=i+1;j<=6;j++) { int temp; if(name[index[i]] > name[index[j]]) { temp = index[i]; index[i] = index[j]; index[j] = temp; } } } } void output(string name[7], int grade[7], int index[7]) { int i; cout << endl; for(i=0;i<=6;i++) { cout << name[index[i]] << " " << grade[index[i]] << endl; } cin.ignore(); cin.get(); //system("pause"); }