📄 page_825.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_825</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_824.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_825</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_826.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 825</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"><i>Quick Check</i></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">1. Write the type declaration for a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> data type named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeType</font><font face="Times New Roman, Times, Serif" size="3"> with three members: </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hour</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">minute</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">second</font><font face="Times New Roman, Times, Serif" size="3">. The </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hour</font><font face="Times New Roman, Times, Serif" size="3"> member is intended to store integer values from 0 through 23. The other two members store values from 0 through 59. (pp. 772780)</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">2. Assume a variable named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">now</font><font face="Times New Roman, Times, Serif" size="3">, of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeType</font><font face="Times New Roman, Times, Serif" size="3">, has been declared. Write the assignment statements necessary to store the time 8:37:28 into </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">now</font><font face="Times New Roman, Times, Serif" size="3">. (pp. 772780)</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">3. Declare a hierarchical record type named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Interval</font><font face="Times New Roman, Times, Serif" size="3"> that consists of two members of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeType</font><font face="Times New Roman, Times, Serif" size="3">. The members are named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">past</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">present</font><font face="Times New Roman, Times, Serif" size="3">. (pp. 782786)</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">4. Assume a variable named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">channelCrossing</font><font face="Times New Roman, Times, Serif" size="3">, of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Interval</font><font face="Times New Roman, Times, Serif" size="3">, has been declared. Write the assignment statements necessary to store the time 7:12:44 into the past member of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">channelCrossing</font><font face="Times New Roman, Times, Serif" size="3">. Write the assignment statement that stores the contents of variable now into the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">present</font><font face="Times New Roman, Times, Serif" size="3"> member of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">channelCrossing</font><font face="Times New Roman, Times, Serif" size="3">. (pp. 782786)</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">5. Declare a variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">boatTimes</font><font face="Times New Roman, Times, Serif" size="3"> that is an array of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Interval</font><font face="Times New Roman, Times, Serif" size="3"> values to be indexed by an enumeration type named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">BoatNames</font><font face="Times New Roman, Times, Serif" size="3">:</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="24" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">enum聽BoatNames聽{LUCKY,聽MY_PRIDE,聽SWELL_STUFF};</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"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="29" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></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">Then write a statement that stores the contents of variable now into the present member of the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> for the boat named Swell Stuff. (pp. 781782)</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">6. Decide what form of data structure is appropriate for the following problem. A single card in a library catalog system must contain the call number, author, title, and description of a single book. (pp. 787793)</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">7. What is the primary purpose of C++ union types? (pp. 786787)</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">Answers</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="Courier New, Courier, Mono New, Courier, Mono" size="2">1.聽struct聽TimeType<br />聽聽聽{<br />聽聽聽聽聽聽聽int聽hour;聽聽聽聽聽//聽Range聽0..23<br />聽聽聽聽聽聽聽int聽minute;聽聽聽//聽Range聽0..59<br />聽聽聽聽聽聽聽int聽second;聽聽聽//聽Range聽0..59<br />};<br />2.聽now.hour聽=聽8;<br />聽聽聽now.minute聽=聽37;<br />聽聽聽now.second聽=聽28;<br />3.聽struct聽Interval<br />聽聽聽{<br />聽聽聽聽聽聽聽聽TimeType聽past;<br />聽聽聽聽聽聽聽聽TimeType聽present;<br />聽聽聽};<br />4.聽channelCrossing.past.hour聽=聽7;<br />聽聽聽channelCrossing.past.minute聽=聽12;<br />聽聽聽channelCrossing.past.second聽=聽44;<br />聽聽聽channelCrossing.present聽=聽now;<br />5.聽Interval聽boatTimes[3];<br />聽聽聽boatTimes[SWELL_STUFF].present聽=聽now;</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">6. A simple struct with four members is sufficient. 7. The primary purpose is to save memory by forcing different values to share the same memory space, one at a time.</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_824.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_825</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_826.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -