i have a program that i need to do for an assignment and i am stuck on it.
Here is an exchange sort algorithm written in pseudo code:
Exchange Sort of Array X[]
For I = 0 to (number of array elements - 2), increment by 1
For J = (I + 1) to (number of array elements - 1), increment by 1
If X[I] is greater than X[J] then
temp = X[I]
X[I] = X[J]
X[J] = temp
Next J
Next I
Write a program to define a simple structure for the following information:
last name
sales (float)
Now declare an array of the structure, reserving space for at least 10 elements.
The program should request data from the keyboard to populate (put data in) the
array. You may use "quit" as a last name code value to indicate that data input is
finished. The array should now be sorted so that the element with the highest sales
figure is first and the element with the lowest sales figure is last (adapt the
exchange above). Output the sorted array to the screen.
To compare the entered last name to "quit" do the following:
#include <string.h>
in your program:
if( strcmp( record field, "quit" ) == 0 ) break;
where record field is the name of your last name string
(example: entry[i].lastname
the code that i have is:
#include <iostream>
using namespace std;
int e;
struct record
{
char lastName[15];
float sales;
}
entry[100];
I think the only headers i can use are #include <iostream> and #include <string.h>
I took what you put and tried to make it in the way that they want it. is there anyway to get this to work. I am getting an error of (invalid converstion from 'record' to 'int')
#include <iostream>
using namespace std;
struct record
{
static const int Name_size = 15;
char lastName[Name_size];
double sales;
};
void MakeEntry (int e, record entry[] )
{
cout << "enter last name: ";
cin >> entry[e].lastName;
cout << "enter sales: ";
cin >> entry[e].sales;
}
void ListEntries (int t, const record entry[])
{
int r;
for (r = 0; r <= t; r++)
{
cout << entry[r].lastName << endl;
cout << entry[r].sales << endl;
}
}
void SortEntries ( record entry[], int I )
{
for( int i = 0 ; i < I ; ++i )
{
for( int j = i+1 ; j < I ; ++j )
{
if( entry[i].sales > entry[j].sales )
{
Thank you all so so much. Switching those did make the program work. I was looking at the program and finally got to switching them and it came back with no error.