CSE 232 Spring 2012 Name: __________________________________ Lab Exercise #6 -- Data Aggregates (Records and Arrays) A. Examine the C++ program below, and give the value displayed by the program for each output operation. =============================================================================== struct Record { unsigned A; char B[20]; float C; }; Record Temp, List[100]; int main() { // The operator "sizeof" evaluates to the number of bytes for its operand, // which can be a data type or a data object. cout << endl; cout << "float: " << sizeof(float) << endl; // ____________ cout << "double: " << sizeof(double) << endl; // ____________ cout << "char: " << sizeof(char) << endl; // ____________ cout << "short int: " << sizeof(short int) << endl; // ____________ cout << "int: " << sizeof(int) << endl; // ____________ cout << "unsigned char: " << sizeof(unsigned char) << endl; // ____________ cout << "unsigned short: " << sizeof(unsigned short) << endl; // ____________ cout << "unsigned int: " << sizeof(unsigned int) << endl; // ____________ cout << "unsigned: " << sizeof(unsigned) << endl; // ____________ cout << endl; cout << "Temp: " << sizeof(Temp) << endl; // ____________ cout << "Temp.A: " << sizeof(Temp.A) << endl; // ____________ cout << "Temp.B: " << sizeof(Temp.B) << endl; // ____________ cout << "Temp.C: " << sizeof(Temp.C) << endl; // ____________ cout << "List: " << sizeof(List) << endl; // ____________ cout << "List[0]: " << sizeof(List[0]) << endl; // ____________ cout << "N: " << sizeof(List) / sizeof(List[0]) << endl; // ____________ cout << endl; // Cast all addresses so that they are displayed as decimal values // (instead of hexadecimal values) using a "typedef". // Assume that "List" begins at address 6296832 (base 10) cout << "&List[0]: " << (base10) &List[0] << endl; // ___6296832__ cout << "&List[0].A: " << (base10) &List[0].A << endl; // ____________ cout << "&List[0].B: " << (base10) &List[0].B << endl; // ____________ cout << "&List[0].C: " << (base10) &List[0].C << endl; // ____________ cout << "&List[0].B[0]: " << (base10) &List[0].B[0] << endl; // ____________ cout << "&List[0].B[4]: " << (base10) &List[0].B[4] << endl; // ____________ cout << endl; cout << "&List[5]: " << (base10) &List[5] << endl; // ____________ cout << "&List[5].A: " << (base10) &List[5].A << endl; // ____________ cout << "&List[5].B: " << (base10) &List[5].B << endl; // ____________ cout << "&List[5].C: " << (base10) &List[5].C << endl; // ____________ cout << "&List[5].B[0]: " << (base10) &List[5].B[0] << endl; // ____________ cout << "&List[5].B[4]: " << (base10) &List[5].B[4] << endl; // ____________ cout << endl; } =============================================================================== B. After completing part A, compile and execute the C++ program to check your answers. From your home directory, use the following commands: g++ -Wall ~cse232/Labs/lab06.program.cpp a.out If any of your answers are incorrect, re-work the appropriate questions. C. The file "~cse232/Labs/lab06.skeleton.cpp" contains the outline of a C++ program, which you are to complete and demonstrate to your TA. Copy the skeleton program into your account and use the comments to guide your modifications and enhancements. Test the completed program using a variety of input values. The file "~cse232/Labs/lab06.data" contains a sample data set which you may use for some of your testing. Other test cases that you should consider: a data file which contains too few students or one which contains too many students. Demonstrate the completed program to your TA.