📄 page_1018.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_1018</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1017.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1018</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1019.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 1018</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">If we run the program and find too many or too few employee records printed out, or if the records are not in alphabetical order, the problem lies in the record list objectthe object responsible for reading the file, sorting, and printing. Using a hand trace, debug output statements, or the system debugger, we should check the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">RecordList</font><font face="Times New Roman, Times, Serif" size="3"> member functions in the following order: </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ReadAll</font><font face="Times New Roman, Times, Serif" size="3"> (to verify that the file data was read into the list correctly), </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3"> (to confirm that the records are ordered by employee last name), then </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PrintAll</font><font face="Times New Roman, Times, Serif" size="3"> (to ensure that all records are output properly).</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">After the program works correctly for the file of test data, we should also run the program against the following files: a nonexistent file and an empty file. With a nonexistent file, the program should halt after the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">OpenForInput</font><font face="Times New Roman, Times, Serif" size="3"> function prints its error message. With an empty file, the program should terminate successfully but produce no output at all. (Look at the loops in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ReadAll</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PrintAll</font><font face="Times New Roman, Times, Serif" size="3"> functions to see why.)</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Are we required to test the program with a file of more than 1000 employee records? No. Clearly, the program would misbehave if the index into the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ptrList</font><font face="Times New Roman, Times, Serif" size="3"> array exceeds 999. However, our program correctly satisfies the problem definition, which states a precondition for the entire programnamely, that the input file contains at most 1000 records. The user of the program must be informed of this precondition and is expected to comply. If the problem definition were changed to eliminate this precondition, then, of course, we would have to modify the program to deal with an input file that is too long.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">One final remark: Regarding the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3"> function, what we have tested is that the program correctly sorts the data using pointers to dynamic variables of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PersonnelData</font><font face="Times New Roman, Times, Serif" size="3">. But the output may still be slightly wrong. Because </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3"> compares the strings that make up the last names, it is ordering the names according to the machine's particular character set. As we mentioned in Chapter 12, such comparisons can lead to problems when uppercase and lowercase characters are mixed. For example, in the ASCII set. Macartney would come <i>after</i> MacDonald. Case Study Follow-Up Exercise 1 asks you to modify </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SelSort</font><font face="Times New Roman, Times, Serif" size="3"> so that it orders names regardless of the case of the individual characters.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="17"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Problem-Solving Case Study Dynamic Arrays</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3"><img src="029385c267d065ea56e58fa6cd823f2a.gif" border="0" alt="1018-01.gif" width="118" height="103" /></font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Problem: In Chapter 15, Programming Warm-Up Exercise 10 described a safe array class (</font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">intArray</font><font face="Times New Roman, Times, Serif" size="3">) that prevents array indices from going out of bounds. The public member functions were: a class constructor, to create an array of up to </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">MAX_SIZE</font><font face="Times New Roman, Times, Serif" size="3"> elements and initialize all elements to zero; a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Store</font><font face="Times New Roman, Times, Serif" size="3"> function, to store a value into a particular array element; and a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ValueAt</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1017.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1018</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1019.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -