1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
using namespace std;
#include <iostream>
#include <iomanip>
int main()
{
int records = 4;
char temp[16] = { 0 };
char temp2[16] = { 0 };
char last_name[4][16] = { 0 };
char first_name[4][16] = { 0 };
cout << "\nEnter Last Name 0: ";
cin.sync();
cin.getline(last_name[0], 16);
cin.sync();
cout << endl;
cout << "\nEnter First Name 0: ";
cin.sync();
cin.getline(first_name[0], 16);
cin.sync();
cout << endl;
cout << "\nEnter Last Name 1: ";
cin.sync();
cin.getline(last_name[1], 16);
cin.sync();
cout << endl;
cout << "\nEnter First Name 1: ";
cin.sync();
cin.getline(first_name[1], 16);
cin.sync();
cout << endl;
cout << "\nEnter Last Name 3: ";
cin.sync();
cin.getline(last_name[2], 16);
cin.sync();
cout << endl;
cout << "\nEnter First Name 3: ";
cin.sync();
cin.getline(first_name[2], 16);
cin.sync();
cout << endl;
cout << "\nEnter Last Name 4: ";
cin.sync();
cin.getline(last_name[3], 16);
cin.sync();
cout << endl;
cout << "\nEnter First Name 4: ";
cin.sync();
cin.getline(first_name[3], 16);
cin.sync();
cout << endl;
for (int i = 0; i < records - 1; i++)
{
if (strcmp(last_name[i], last_name[i + 1]) > 0)
{
strcpy_s(temp, last_name[i]);
strcpy_s(last_name[i], last_name[i + 1]);
strcpy_s(last_name[i + 1], temp);
strcpy_s(temp2, first_name[i]);
strcpy_s(first_name[i], first_name[i + 1]);
strcpy_s(first_name[i + 1], temp2);
}
else if (strcmp(last_name[i], last_name[i + 1]) == 0)
{
if (strcmp(first_name[i], first_name[i + 1]) > 0)
{
strcpy_s(temp2, first_name[i]);
strcpy_s(first_name[i], first_name[i + 1]);
strcpy_s(first_name[i + 1], temp2);
}
}
}
cout << last_name[0] << ' ' << first_name[0] << ' ' << "\n"
<< last_name[1] << ' ' << first_name[1] << ' ' << "\n"
<< last_name[2] << ' ' << first_name[2] << ' ' << "\n"
<< last_name[3] << ' ' << first_name[3] << ' ' << "\n";
system("pause");
return 0;
}
|