亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 021.htm

?? 21天內(nèi)快速掌握c++語言
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
29:
30:       cout << "Done." << endl;
31:     return 0;
32:    }
33:
34:    int sortFunction( const void *a, const void *b)
35:    {
36:       int intOne = *((int*)a);
37:       int intTwo = *((int*)b);
38:       if (intOne < intTwo)
39:          return -1;
40:       if (intOne == intTwo)
41:          return 0;
42:       return 1;
<TT>43: }</TT>
Output: Enter a number: 2
Enter a number: 9
Enter a number: 12
Enter a number: 873
Enter a number: 0
Enter a number: 45
Enter a number: 93
Enter a number: 2
Enter a number: 66
Enter a number: 1
<BR>
Table[0]: 0
Table[1]: 1
Table[2]: 2
Table[3]: 2
Table[4]: 9
Table[5]: 12
Table[6]: 45
Table[7]: 66
Table[8]: 93
Table[9]: 873
Done.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On line 4, the standard library
header is included, which is required by the <TT>qsort()</TT> function. On line 7,
the function <TT>sortFunction()</TT> is declared, which takes the required four parameters.<BR>
<BR>
An array is declared on line 13 and filled by user input on lines 16-20. <TT>qsort()</TT>
is called on line 24, casting the address of the array name <TT>table</TT> to be
a <TT>void*</TT>.</P>
<P>Note that the parameters for <TT>sortFunction</TT> are not passed to the call
to <TT>qsort()</TT>. The name of the <TT>sortFunction</TT>, which is itself a pointer
to that function, is the parameter to <TT>qsort()</TT>.</P>
<P>Once <TT>qsort()</TT> is running, it will fill the constant <TT>void</TT> pointers
<TT>a</TT> and <TT>b</TT> with each value of the array. If the first value is smaller
than the second, the comparison function must return <TT>-1</TT>. If it is equal,
the comparison function must return <TT>0</TT>. Finally, if the first value is greater
than the second value, the comparison function must return <TT>1</TT>. This is reflected
in the <TT>sortFunction()</TT>, as shown on lines 34 to 43.
<H4 ALIGN="CENTER"><A NAME="Heading18"></A><FONT COLOR="#000077">Other Libraries</FONT></H4>
<P>Your C++ compiler supplies a number of other libraries, among them the standard
input and output libraries and the stream libraries that you've been using throughout
this book. It is well worth your time and effort to explore the documentation that
came with your compiler to find out what these libraries have to offer.
<H3 ALIGN="CENTER"><A NAME="Heading19"></A><FONT COLOR="#000077">Bit Twiddling</FONT></H3>
<P>Often you will want to set flags in your objects to keep track of the state of
your object. (Is it in <TT>AlarmState</TT>? Has this been initialized yet? Are you
coming or going?)</P>
<P>You can do this with user-defined Booleans, but when you have many flags, and
when storage size is an issue, it is convenient to be able to use the individual
bits as flags.</P>
<P>Each byte has eight bits, so in a four-byte <TT>long</TT> you can hold 32 separate
flags. A bit is said to be &quot;set&quot; if its value is <TT>1</TT>, and clear
if its value is <TT>0</TT>. When you set a bit, you make its value <TT>1</TT>, and
when you clear it, you make its value <TT>0</TT>. (Set and clear are both adjectives
and verbs). You can set and clear bits by changing the value of the <TT>long</TT>,
but that can be tedious and confusing.
<BR>
<BR>
<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Appendix C, &quot;Binary and Hexadecimal,&quot;
	provides valuable additional information about binary and hexadecimal manipulation.
	
<HR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
<P>C++ provides bitwise operators that act upon the individual bits.These look like,
but are different from, the logical operators, so many novice programmers confuse
them. The bitwise operators are presented in Table 21.1. <BR>
<BR>
<FONT SIZE="4"><B>Table 21.1. The Bitwise Operators. </B></FONT>
<TABLE BORDER="0" WIDTH="145">
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="64" ALIGN="LEFT"><B><I>symbol</I></B></TD>
		<TD ALIGN="LEFT"><B><I>operator</I></B></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="64" ALIGN="LEFT"><TT>&amp;</TT></TD>
		<TD ALIGN="LEFT"><TT>AND</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="64" ALIGN="LEFT"><TT>|</TT></TD>
		<TD ALIGN="LEFT"><TT>OR</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="64" ALIGN="LEFT"><TT>^</TT></TD>
		<TD ALIGN="LEFT">exclusive <TT>OR</TT></TD>
	</TR>
	<TR ALIGN="LEFT" rowspan="1">
		<TD WIDTH="64" ALIGN="LEFT"><TT>~</TT></TD>
		<TD ALIGN="LEFT">complement</TD>
	</TR>
</TABLE>
<BR>
<CENTER>
<H4><A NAME="Heading20"></A><FONT COLOR="#000077">Operator AND</FONT></H4>
</CENTER>
<P>The <TT>AND</TT> operator (<TT>&amp;</TT>) is a single ampersand, as opposed to
the logical <TT>AND</TT>, which is two ampersands. When you <TT>AND</TT> two bits,
the result is <TT>1</TT> if both bits are <TT>1</TT>, but <TT>0</TT> if either or
both bits are <TT>0</TT>. The way to think of this is: The result is <TT>1</TT> if
bit 1 is set and if bit 2 is set.
<CENTER>
<H4><A NAME="Heading21"></A><FONT COLOR="#000077">Operator OR</FONT></H4>
</CENTER>
<P>The second bitwise operator is <TT>OR</TT> (<TT>|</TT>). Again, this is a single
vertical bar, as opposed to the logical <TT>OR</TT>, which is two vertical bars.
When you <TT>OR</TT> two bits, the result is <TT>1</TT> if either bit is set or if
both are.
<CENTER>
<H4><A NAME="Heading22"></A><FONT COLOR="#000077">Operator Exclusive OR</FONT></H4>
</CENTER>
<P>The third bitwise operator is exclusive <TT>OR</TT> (<TT>^</TT>). When you exclusive
<TT>OR</TT> two bits, the result is <TT>1</TT> if the two bits are different.
<CENTER>
<H4><A NAME="Heading23"></A><FONT COLOR="#000077">The Complement Operator</FONT></H4>
</CENTER>
<P>The complement operator (<TT>~</TT>) clears every bit in a number that is set
and sets every bit that is clear. If the current value of the number is <TT>1010
0011</TT>, the complement of that number is <TT>0101 1100</TT>.
<CENTER>
<H4><A NAME="Heading24"></A><FONT COLOR="#000077">Setting Bits</FONT></H4>
</CENTER>
<P>When you want to set or clear a particular bit, you use masking operations. If
you have a 4-byte flag and you want to set bit 8 TRUE, you need to <TT>OR</TT> the
flag with the value <TT>128</TT>. Why? <TT>128</TT> is <TT>1000 0000</TT> in binary;
thus the value of the eighth bit is <TT>128</TT>. Whatever the current value of that
bit (<TT>set</TT> or <TT>clear</TT>), if you <TT>OR</TT> it with the value <TT>128</TT>
you will set that bit and not change any of the other bits. Let's assume that the
current value of the 8 bits is <TT>1010 0110 0010 0110</TT>. <TT>OR</TT>ing 128 to
it looks like this:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">9 8765 4321
1010 0110 0010 0110   // bit 8 is clear
|   0000 0000 1000 0000   // 128
----------------------
1010 0110 1010 0110   // bit 8 is set
</FONT></PRE>
<P>There are a few things to note. First, as usual, bits are counted from right to
left. Second, the value <TT>128</TT> is all zeros except for bit 8, the bit you want
to set. Third, the starting number <TT>1010 0110 0010 0110</TT> is left unchanged
by the <TT>OR</TT> operation, except that bit 8 was set. Had bit 8 already been set,
it would have remained set, which is what you want.
<CENTER>
<H4><A NAME="Heading25"></A><FONT COLOR="#000077">Clearing Bits</FONT></H4>
</CENTER>
<P>If you want to clear bit 8, you can <TT>AND</TT> the bit with the complement of
128. The complement of 128 is the number you get when you take the bit pattern of
128 (1000 0000), set every bit that is <TT>clear</TT>, and clear every bit that is
<TT>set</TT> (0111 1111). When you <TT>AND</TT> these numbers, the original number
is unchanged, except for the eighth bit, which is forced to zero.</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">1010 0110 1010 0110  // bit 8 is set
&amp; 1111 1111 0111 1111  // ~128
----------------------
1010 0110 0010 0110  // bit 8 cleared
</FONT></PRE>
<P>To fully understand this solution, do the math yourself. Each time both bits are
<TT>1</TT>, write 1 in the answer. If either bit is <TT>0</TT>, write 0 in the answer.
Compare the answer with the original number. It should be the same except that bit
8 was cleared.
<CENTER>
<H4><A NAME="Heading26"></A><FONT COLOR="#000077">Flipping Bits</FONT></H4>
</CENTER>
<P>Finally, if you want to flip bit 8, no matter what its state, you exclusive <TT>OR</TT>
the number with 128. Thus:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">1010 0110 1010 0110  // number
^ 0000 0000 1000 0000  // 128
----------------------
1010 0110 0010 0110  // bit flipped
^ 0000 0000 1000 0000  // 128
----------------------
1010 0110 1010 0110  // flipped back
</FONT></PRE>
<BR>
<BR>
<BLOCKQUOTE>
	<P>
<HR>
<B>DO</B> set bits by using masks and the <TT>OR</TT> operator. <B>DO</B> clear bits
	by using masks and the <TT>AND</TT> operator.<B> DO </B>flip bits using masks and
	the exclusive <TT>OR</TT> operator.
<HR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
<CENTER>
<H4><A NAME="Heading27"></A><FONT COLOR="#000077">Bit Fields</FONT></H4>
</CENTER>
<P>There are circumstances under which every byte counts, and saving six or eight
bytes in a class can make all the difference. If your class or structure has a series
of Boolean variables, or variables that can have only a very small number of possible
values, you may save some room using bit fields.</P>
<P>Using the standard C++ data types, the smallest type you can use in your class
is a type <TT>char</TT>, which is one byte. You will usually end up using an <TT>int</TT>,
which is two, or more often four, bytes. By using bit fields, you can store eight
binary values in a <TT>char</TT> and 32 such values in a <TT>long</TT>.</P>
<P>Here's how bit fields work: bit fields are named and accessed like any class member.
Their type is always declared to be <TT>unsigned</TT> <TT>int</TT>. After the bit
field name, write a colon followed by a number. The number is an instruction to the
compiler as to how many bits to assign to this variable. If you write 1, the bit
will represent either the value <TT>0</TT> or <TT>1</TT>. If you write 2, the bit
can represent <TT>0</TT>, <TT>1</TT>, <TT>2</TT>, or <TT>3</TT>, a total of four
values. A three-bit field can represent eight values, and so forth. Appendix C reviews
binary numbers. Listing 21.8 illustrates the use of bit fields.</P>
<BR>
<P><A NAME="Heading28"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 21.8. Using
bit fields.</B></FONT>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">0:        #include &lt;iostream.h&gt;
1:        #include &lt;string.h&gt;
2:
3:        enum STATUS { FullTime, PartTime } ;
4:        enum GRADLEVEL { UnderGrad, Grad } ;
5:        enum HOUSING { Dorm, OffCampus };
6:        enum FOODPLAN { OneMeal, AllMeals, WeekEnds, NoMeals };
7:
8:        class student
9:        {
10:        public:
11:        student():
12:            myStatus(FullTime),
13:            myGradLevel(UnderGrad),
14:            myHousing(Dorm),
15:            myFoodPlan(NoMeals)
16:            {}
17:            ~student(){}
18:            STATUS GetStatus();
19:            void SetStatus(STATUS);
20:            unsigned GetPlan() { return myFoodPlan; }
21:
22:        private:
23:           unsigned myStatus : 1;
24:           unsigned myGradLevel: 1;
25:           unsigned myHousing : 1;
26:           unsigned myFoodPlan : 2;
27:        };
28:
29:        STATUS student::GetStatus()
30:        {
31:           if (myStatus)
32:              return FullTime;
33:           else
34:              return PartTime;
35:        }
36:        void student::SetStatus(STATUS theStatus)
37:        {
38:           myStatus = theStatus;
39:        }
40:
41:
42:        int main()
43:        {
44:           student Jim;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美午夜在线一二页| 亚洲精品在线观看视频| 亚洲免费电影在线| 91美女片黄在线观看91美女| 国产精品电影一区二区三区| 9久草视频在线视频精品| 91精品国产一区二区人妖| 免费成人美女在线观看| 在线播放91灌醉迷j高跟美女| 欧美自拍偷拍午夜视频| 亚洲乱码国产乱码精品精的特点 | 亚洲一区二区三区精品在线| 欧美亚洲尤物久久| 免费在线看成人av| 欧美日韩三级在线| 国产精品自拍毛片| 一区二区三区日韩精品视频| 欧美老年两性高潮| 夜夜爽夜夜爽精品视频| 亚洲精品国产无天堂网2021| 精品国产免费久久| 偷拍与自拍一区| 懂色av一区二区夜夜嗨| 国产午夜精品久久久久久免费视 | 国产九色精品成人porny| 91色|porny| 亚洲欧美经典视频| 欧美日韩一区二区在线视频| 国产欧美精品一区二区色综合| 天天综合天天做天天综合| 色婷婷久久综合| 91女神在线视频| 国产精品久久久久久久蜜臀 | 国产日韩欧美不卡在线| 国产一区免费电影| 亚洲一区自拍偷拍| 国产肉丝袜一区二区| 91久久精品一区二区三区| 亚洲一区中文日韩| 黄页网站大全一区二区| 天天操天天干天天综合网| 在线视频一区二区三| 亚洲精品成人a在线观看| 精品视频1区2区| 国产一区二区在线视频| 国产嫩草影院久久久久| 91成人免费网站| 蜜臀久久99精品久久久久久9| 激情五月婷婷综合网| 精品久久久久久久久久久院品网| 国产成人综合亚洲91猫咪| 亚洲影视在线观看| 精品国产第一区二区三区观看体验| 日本不卡1234视频| 蜜桃视频第一区免费观看| 久久99精品久久久久久动态图 | 亚洲视频在线一区二区| 国产精品久久久久影院老司| 91精品一区二区三区久久久久久 | 亚洲男人电影天堂| 亚洲欧洲在线观看av| 亚洲国产日韩一区二区| 久久99精品久久久久久| 久久久久久久久久电影| 精品一区二区免费看| 日韩成人免费在线| 久久超碰97人人做人人爱| 秋霞电影网一区二区| 免费美女久久99| 国产一区二区影院| 北岛玲一区二区三区四区| 欧美性猛片aaaaaaa做受| 在线观看亚洲a| 欧美日本在线观看| 日韩亚洲欧美一区| 国产欧美va欧美不卡在线| 综合婷婷亚洲小说| 亚洲动漫第一页| 国产精品一区久久久久| 在线精品视频免费观看| 欧美亚日韩国产aⅴ精品中极品| 成人激情校园春色| 欧美情侣在线播放| 亚洲图片激情小说| 极品销魂美女一区二区三区| 99久久婷婷国产综合精品| 精品少妇一区二区三区日产乱码| 国产精品久久久久一区| 日韩av电影免费观看高清完整版 | 精品视频在线免费观看| 精品国产在天天线2019| 国产综合久久久久久久久久久久| 国产成人精品影视| 美女国产一区二区三区| 亚洲国产精品久久久久秋霞影院| 午夜精品久久久久影视| 一区二区三区四区高清精品免费观看| 精品成人一区二区三区| 国产精品久久久久久久久久久免费看 | 中文字幕国产一区| 日韩电影在线一区| 色婷婷狠狠综合| 亚洲欧美一区二区视频| 国产成人综合在线播放| 欧美一级黄色录像| 天天综合网 天天综合色| 色八戒一区二区三区| 国产精品传媒视频| 天天色图综合网| 成人小视频免费观看| 国产欧美久久久精品影院| 国产91精品久久久久久久网曝门| 精品日韩在线一区| 国产一区二区三区黄视频 | 中文字幕一区二区三区四区 | 国产精品一二三区| 久久久无码精品亚洲日韩按摩| 日韩激情av在线| wwww国产精品欧美| 91亚洲精品久久久蜜桃网站 | 成人美女视频在线观看| 亚洲精品在线观看视频| 久久成人久久鬼色| 国产午夜精品在线观看| 在线视频一区二区三| 麻豆精品国产传媒mv男同 | 日韩欧美卡一卡二| 国产一区二区在线影院| 亚洲精品免费一二三区| 欧美α欧美αv大片| 色婷婷久久综合| 久久9热精品视频| 亚洲精品一二三| 精品国产电影一区二区| 色综合久久天天| 久久精品国产精品亚洲精品| 亚洲女爱视频在线| 国产亚洲精品免费| 欧美三级中文字幕在线观看| 国产一区二区看久久| 一区二区在线观看视频| 国产午夜精品一区二区三区视频 | 伊人性伊人情综合网| 欧美一级高清大全免费观看| 99麻豆久久久国产精品免费| 免费av网站大全久久| 亚洲与欧洲av电影| 日韩伦理电影网| xnxx国产精品| 精品久久久久久无| 精品精品欲导航| 欧美日韩在线直播| 91在线视频播放| 成人激情午夜影院| 国产精品一二三四五| 激情六月婷婷久久| 亚洲国产va精品久久久不卡综合| 国产精品性做久久久久久| 国产欧美中文在线| 欧美日韩二区三区| 欧美高清视频一二三区| 欧美一级xxx| 国产精品色一区二区三区| 亚洲欧美日韩中文播放 | 欧美精品99久久久**| 日韩一区二区三区四区| 国产精品视频观看| 亚洲午夜久久久久| 国产盗摄一区二区| 在线影视一区二区三区| 久久久久久久久久久久久夜| 亚洲精品美腿丝袜| 国内精品视频666| 欧美片网站yy| 中文字幕综合网| 懂色中文一区二区在线播放| 欧美日韩不卡一区二区| 中文字幕在线不卡一区| 日本欧美久久久久免费播放网| 99久久久久久| 国产亚洲欧美色| 精品一区二区三区免费毛片爱| 91天堂素人约啪| 欧美激情综合网| 极品美女销魂一区二区三区免费| 欧美三级蜜桃2在线观看| 亚洲日本欧美天堂| 不卡的av在线| 国产精品久久久久aaaa樱花| 国产精品一二三在| 久久久久久免费| 国产sm精品调教视频网站| 精品国产免费人成电影在线观看四季| 视频一区欧美精品| 欧美精品在线一区二区三区| 日韩不卡在线观看日韩不卡视频| 欧美在线看片a免费观看| 一级日本不卡的影视| 欧美午夜精品久久久| 肉肉av福利一精品导航|