/* teststruct3.cpp CIS 150 David Klick 6/30/05 Using an array of structures. */ #include #include #include using std::cout; using std::cin; using std::setw; using std::setprecision; using std::showpoint; using std::fixed; struct Employee { int id; char fname[15]; char lname[15]; double rate; }; const int ARRAY_SIZE = 5; void display(Employee e); void sort(Employee e[], int len); int main(void) { int i; // declare array of Employees Employee emp[ARRAY_SIZE]; // get Employee info from user for (i=0; i> emp[i].id; cin.ignore(); // get rid of newline after id cout << "First name: "; cin.getline(emp[i].fname, 15, '\n'); cout << " Last name: "; cin.getline(emp[i].lname, 15, '\n'); cout << " Rate: "; cin >> emp[i].rate; cout << '\n'; } // display employee info for (i=0; i e[j].id) { temp = e[i]; e[i] = e[j]; e[j] = temp; } } } } /* Sample input/output: Employee #1 ID#: 27 First name: Sammi Last name: Hargrove Rate: 12.35 Employee #2 ID#: 62 First name: Red Last name: Forman Rate: 13.20 Employee #3 ID#: 13 First name: Eric Last name: Forman Rate: 16.50 Employee #4 ID#: 5 First name: Marcia Last name: Brady Rate: 8.95 Employee #5 ID#: 38 First name: Walter Last name: Savitch Rate: 10.50 27: Sammi Hargrove (12.35) 62: Red Forman (13.20) 13: Eric Forman (16.50) 5: Marcia Brady (8.95) 38: Walter Savitch (10.50) Employee info after sorting by ID#: 5: Marcia Brady (8.95) 13: Eric Forman (16.50) 27: Sammi Hargrove (12.35) 38: Walter Savitch (10.50) 62: Red Forman (13.20) */