Z
zfareed
I managed to sort a 2-dim array of lastnames but I am having trouble
with printing the corresponding first names which are stored in a
different 2-dim array. Here is my code for:
bubbleSort(Lstname,j);
// Printing array
cout << "STUDENT " << setw(8) << "ID " << setw(20)<< "S1 S2
S3 S4"
<< " S5 S6 S7 S8 AVG"<< endl;
cout <<
"--------------------------------------------------------------"
<< "-----------------"<<endl;
k=j;
for(j=0;j<k;j++)
{
cout << Lstname[j] << Fstname [j] << " " << Id[j] << " ";
for(i=0;i<8;i++)
if(scores[j] == 0)
cout << "00.0" << " ";
else
cout << fixed << setprecision(1) << scores[j] << "
";
cout << average[j];
cout << endl;
}
void bubbleSort (char Lstname[][10], int j)
{
int n;
char save[10];
int min;
for(n=0; n < j;n++)
cout << Lstname[n] << endl;
cout << endl;
cout << "Sorted list" << endl;
//Sort
for (int i = 0; i < j-1 ; i++)
{
min = i;
for (int t = i + 1; t < j; t++)
{
if (strcmp (Lstname[t],Lstname[min]) < 0 )
min = t;
}
memcpy ( save, Lstname, 10 );
memcpy ( Lstname, Lstname[min], 10 );
memcpy ( Lstname[min], save, 10 );
}
}
Any ideas?
with printing the corresponding first names which are stored in a
different 2-dim array. Here is my code for:
bubbleSort(Lstname,j);
// Printing array
cout << "STUDENT " << setw(8) << "ID " << setw(20)<< "S1 S2
S3 S4"
<< " S5 S6 S7 S8 AVG"<< endl;
cout <<
"--------------------------------------------------------------"
<< "-----------------"<<endl;
k=j;
for(j=0;j<k;j++)
{
cout << Lstname[j] << Fstname [j] << " " << Id[j] << " ";
for(i=0;i<8;i++)
if(scores[j] == 0)
cout << "00.0" << " ";
else
cout << fixed << setprecision(1) << scores[j] << "
";
cout << average[j];
cout << endl;
}
void bubbleSort (char Lstname[][10], int j)
{
int n;
char save[10];
int min;
for(n=0; n < j;n++)
cout << Lstname[n] << endl;
cout << endl;
cout << "Sorted list" << endl;
//Sort
for (int i = 0; i < j-1 ; i++)
{
min = i;
for (int t = i + 1; t < j; t++)
{
if (strcmp (Lstname[t],Lstname[min]) < 0 )
min = t;
}
memcpy ( save, Lstname, 10 );
memcpy ( Lstname, Lstname[min], 10 );
memcpy ( Lstname[min], save, 10 );
}
}
Any ideas?