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: Using header files(.h files) //Website: EasyProgramming.net //header.h #include <iostream> #include <string> using namespace std; void prompt(string name[3], int grade[3]); void init(int index[3]); void sort(string name[3], int index[3]); void output(string name[3], int grade[3], int index[3]);
//Name: Nazmus //Program: Using header files(.h files) //Website: EasyProgramming.net //main.cpp #include "header.h" int main() { string name[3]; int grade[3]; int index[3]; prompt(name, grade); init(index); sort(name, index); output(name, grade, index); } void prompt(string name[3], int grade[3]) { for(int i=0;i<=2;i++) { cout << "Please enter name: "; cin >> name[i]; cout << "Please enter grade: "; cin >> grade[i]; } } void init(int index[3]) { for(int i=0;i<=2;i++) { index[i]=i; } } void sort(string name[3], int index[3]) { int i, j; for(i=0;i<=1;i++) { for(j=i+1;j<=2;j++) { int temp; if(name[index[i]] > name[index[j]]) { temp = index[i]; index[i] = index[j]; index[j] = temp; } } } } void output(string name[3], int grade[3], int index[3]) { int i; cout << endl; for(i=0;i<=2;i++) { cout << name[index[i]] << " " << grade[index[i]] << endl; } cin.ignore(); cin.get(); //system("pause"); }