Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C++ structure type problem
C++ structure type problem
Then your program has changed the database data, so the following is a short small program I wrote, which fully meets the requirements of the topic. The data in the database will not change, only a plastic array set will be used; Just sort the index numbers stored in the array.

//The following program can run efficiently and correctly!

# include & ltiostream & gt

Use namespace std

# Define N 5

Structural employee

{

char name[20];

Floating wages;

};

Int sort (int flag[], struct employee em[])

//Input: the flag array stores the index numbers of data elements before sorting;

//Output: Using selective sorting, the index numbers corresponding to the sorted data elements from the largest to the smallest are stored in the flag array.

{

int i,j,mark,temp

for(I = 0; I<n-1; i++)

{

mark = I;

for(j = I+ 1; j & ltn; j++)

if(em[flag[j]]。 Salary & gtem[flag[mark]]. Salary)

mark = j;

If (me! = Mark)

{

temp = flag[I];

flag[I]= flag[mark];

flag[mark]= temp;

}

}

Returns 0;

}

int main()

{

Structure employee em[N]={

{"Jimmy", 1250.04}, {"Tim", 1280.07},

{"Rose", 1390.08}, {"tommoy ",1490.35},

{"Jon", 1320.54}

};

int flag[N]={0, 1,2,3,4},I;

sort(flag,em);

cout & lt& lt”OUT:\ n”;

for(I = 0; I & ltn;; i++)

cout & lt& lt" The " & lt& ltI+ 1 & lt; & lt" th " & lt& ltem[flag[i]]。 Name & lt< ""< & ltem [flag [i]]. Salary & lt& ltendl

cout & lt& lt“OK”;

CIN & gt; & gt me;

Returns 0;

}

I hope kutpbpb's answer can help you!