/* * SelfTest * Chapter 13 * By John Stile */ 1. Write the definition for a structure-type named employee consisting of: a 40-byte character array named name an integer named number a floating point number named salary ANSWER: struct employee { char name[40], int number, float salary }; 2. Write statement that sets the elements number and salary of oldemployee to 57 and 23.75 respectively. ANSWER: employee oldemployee; // declare variable type employee named oldemployee employee.number=57; // initialize the number element employee.salary=23.75; // initilaize the salary element 3. Define an array of structures called allemployees that is in the format of employee as described above. Let the array include 101 structures. ANSWER: employee allemployees[101]; 4. Given the statement for setting the salary of the 10th structure in the array of structures allemployees to 30.10. ANSWER: allemployees[9].salary=30.10; 5. Show the statements for setting the salary in the 9th structure in the array allemployees to 80.50, using the structure pointer struct_ptr that has been initialized as follows: struct employee *struct_ptr=allemployees; ANSWER: struct_ptr[8]->salary=80.50; 6. (Book problem 7) Write a function named print_data that accepts a structure pointer to the structure of type employee, and prints out the elements employee.name, employee.number, and employee.salary. The printing format for the data is unimporant as long as the data is displayed. void print_data ( employee * ); // prototype: accepts pointer to struct type employee // Calling function from main print_data( struct_ptr ); voind print_data( struct employee * ptr ) { printf("name:%.40s, number:%d, salary:%.2f\n", ptr->name, ptr->number, ptr->salary); }