/* teststruct1.cpp CIS 150 David Klick 7/3/08 This program demonstrates the basics of using structures. */ #include #include #include using std::cin; using std::cout; using std::setw; using std::setprecision; using std::showpoint; using std::fixed; struct Employee { int id; char fname[15]; char lname[15]; double rate; }; void display(Employee e); void cont(); int main() { // declare and initialize first Employee Employee e1 = {36, "Shirley", "Jackson", 27.35}; // declare next two Employees Employee e2, e3; // set fields of second Employee e2.id = 49; strcpy(e2.fname, "Horace"); strcpy(e2.lname, "Greeley"); e2.rate = 17.25; // copy employee data from one location to another e3 = e1; // display employee information display(e1); display(e2); display(e3); cont(); return 0; } /* void display(Employee e); Arguments: Employee e: an Employee structure Returns: nothing Displays the employee's information on stdout. */ void display(Employee e) { cout << fixed << showpoint << setprecision(2) << setw(3) << e.id << ": " << e.fname << ' ' << e.lname << " (" << e.rate << ")\n"; } /* void cont(); Arguments: none Returns: nothing Clears input buffer and pauses waiting for user to press Enter. */ void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }