歡迎來(lái)到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁(yè) 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

VisualC++面向?qū)ο缶幊探坛痰?版(王育堅(jiān))清華大學(xué)出版社課后答案

  • 資源ID:9292735       資源大?。?span id="t2b3mwf" class="font-tahoma">264.50KB        全文頁(yè)數(shù):104頁(yè)
  • 資源格式: DOC        下載積分:15積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 微信開(kāi)放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要15積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫(xiě)的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付方式: 支付寶    微信支付   
驗(yàn)證碼:   換一換

 
賬號(hào):
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開(kāi),此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁(yè)到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請(qǐng)使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無(wú)水印,預(yù)覽文檔經(jīng)過(guò)壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒(méi)有明確說(shuō)明有答案則都視為沒(méi)有答案,請(qǐng)知曉。

VisualC++面向?qū)ο缶幊探坛痰?版(王育堅(jiān))清華大學(xué)出版社課后答案

2 45 編寫(xiě)一個(gè)程序 輸入三角形的三條邊的邊長(zhǎng) 求三角形的面積 2 45 include include int main int a b c int s S cin a b c s a b c 2 S powl s s a s b s c 0 5 if S 0 cout 此三邊不能構(gòu)成三角形 endl else cout 面積 endl cout S endl return 0 2 46 從鍵盤(pán)輸入一個(gè)大寫(xiě)字母 然后改用小寫(xiě)字母在屏幕輸出 2 46 include int main char ch int a cout 輸入一個(gè)大寫(xiě)字母 ch if ch 65 a int ch cout ch endl else cout 該字母不是字母或不是字母大寫(xiě) endl return 0 2 47 用戶輸入兩個(gè)整數(shù) 編程輸出稍大于第一個(gè)整數(shù)而又是第 2 個(gè)整數(shù)的倍數(shù)的數(shù) 計(jì)算 公式是 valuel value2 value1 value2 2 47 include int main int value1 value2 int result cin value1 value2 result value1 value2 value1 value2 cout 該整數(shù)為 result endl return 0 2 48 華氏溫度轉(zhuǎn)換為攝氏溫度的公式是 C F 32 5 9 編寫(xiě)一個(gè)程序 輸入一個(gè)華氏 溫度 程序輸出相應(yīng)的攝氏溫度 請(qǐng)將 32 和 5 9 用 const 型變量表示 2 48 include int main const float i 32 0 const float j 5 0 9 0 float degFahr float degCel cin degFahr for degFahr 0 degFahr 300 degFahr 10 degCel j degFahr i cout 華氏溫度 degFahr endl cout 攝氏溫度 degCel endl return 0 2 49 從鍵盤(pán)輸入 20 個(gè)整數(shù) 檢查 100 是否存在于這些整數(shù)中 若是的話 求出他是第幾 個(gè)被輸入的 2 49 include int main int Array 20 int i count 0 c 0 for i 0 i Array i for i 0 i 20 i if Array i 100 count if Array i 100 c if c 19 cout 100 不存在該數(shù)組中 endl for i 0 i 20 i if Array i 100 cout 它是第 i 1 個(gè)被輸入的 endl return 0 2 50 從鍵盤(pán)輸入一個(gè) N X N 的整型數(shù)組 并將每一行的最大值顯示輸出 2 50 include int main int Array 100 100 0 int n temp cin n for int i 0 i n i for int j 0 j Array i j for int x 0 x n x for int y x 1 y n y if Array i x Array i y temp Array i x Array i x Array i y Array i y temp cout 每一行的最大值 endl for i 0 i n i cout Array i 0 cout endl 2 51 輸入三個(gè)整數(shù) 采用指針?lè)椒▽⑷齻€(gè)數(shù)按從大到小的順序輸出 2 51 include include int main int Array 3 int pA Array int a Array int i int temp for i 0 i Array i for i 0 i 3 i a if pA a temp pA pA a a temp a pA a for i 0 i 3 i cout Array i return 0 2 52 采用指針?lè)椒▽⒁粋€(gè)數(shù)組中的所有元素顛倒順序 結(jié)果仍然存放在原來(lái)的數(shù)組中 要 求使用最少的輔助存儲(chǔ)單元 2 52 include int main int n cout 輸入數(shù)組的長(zhǎng)度 小于 100 n cout 輸入 n 個(gè)數(shù) endl int Array 100 int pA Array int i for i 0 i Array i pA for i 0 i n i pA cout pA return 0 2 53 輸入兩個(gè)字符串 如果兩個(gè)字符串的字符和長(zhǎng)度都相同 認(rèn)為它們相等 在屏幕上 輸出 Equal 否則在屏幕上輸出 Unequal 要求使用字符指針 2 53 include int main char pstr Enter a string char str1 100 str2 100 cout pstr endl cin get str1 100 cin get cin get str2 100 int len1 0 len2 0 while str1 len1 0 len1 while str2 len2 0 len2 if len1 len2 cout Unequal endl else if len1 len2 int i 0 for i 0 i len1 i if str1 i str2 i if i len1 1 cout Equal endl else cout Unequal endl return 0 2 54 編程將一個(gè)整數(shù)轉(zhuǎn)換成對(duì)應(yīng)的數(shù)字串 例如將值 1234 轉(zhuǎn)換為數(shù)字串 1234 2 54 include int main int number int Array 100 int i j cin number for i 0 number 0 i Array i number 10 number number 10 j i for i j i 0 i cout Array i 1 cout endl return 0 2 55 編程求兩個(gè)復(fù)數(shù)的和 2 55 include int main float a 2 b 2 c 2 int i for i 0 i a i for i 0 i b i for i 0 i 2 i c i a i b i cout c 0 c 1 endl return 0 2 56 使用結(jié)構(gòu)變量表示每個(gè)學(xué)生的信息 姓名 學(xué)號(hào)和三門課的成績(jī) 從鍵盤(pán)輸入 10 個(gè) 學(xué)生的數(shù)據(jù) 然后輸出每個(gè)學(xué)生的姓名和三門課的平均成績(jī) 2 56 include struct student char num 10 char name 20 float grade 3 float average int main student stu 10 int i j float sum 0 for i 0 i 9 i printf Enter num n scanf s printf Enter name n scanf s printf Enter three grades n for j 0 j 3 j scanf f sum stu i grade j stu i average sum 3 printf f s n stu i average stu i name return 0 2 57 用結(jié)構(gòu)數(shù)組建立并初始化一個(gè)工資表 然后輸入一個(gè)人的姓名 查詢其工資情況 并 在屏幕上輸出 2 57 2 58 用枚舉值 MON TUE WED THU FRI SAT 和 SUN 表示一個(gè)星期中的 7 天 從 鍵盤(pán)輸入一個(gè) 0 6 之間的整數(shù) 根據(jù)輸入的整數(shù)輸出對(duì)應(yīng)的英文縮寫(xiě) 2 58 2 59 編寫(xiě)一個(gè)求解一元二次方程的根的程序 方程的系數(shù)由用戶輸入 2 59 include include int main int a b c int R float p float x1 x2 cin a b c R b b 4 a c if R 0 p sqrt R x1 b p 2 a x2 b p 2 a if x1 x2 cout 僅且只有一個(gè)根 x1 endl else cout 有兩個(gè)不同的根 x1 x2 endl else if R 0 cout 無(wú)根 endl return 0 2 60 從鍵盤(pán)輸入一個(gè)字符 判斷輸入的字符是 m a n 或其他字符 如果是 m 則輸出 Good morning 如果是 a 則輸出 Good afternoon 如果是 n 則輸出 Good night 如果是其他字符則輸出 I can t undersrand 2 60 2 61 編程實(shí)現(xiàn)兩個(gè)整數(shù)的加 減 乘 除四則運(yùn)算 運(yùn)算式形如 32 120 2 61 2 62 編寫(xiě)一個(gè)程序 利用 swith 語(yǔ)句將百分制的學(xué)生成績(jī)轉(zhuǎn)換為優(yōu) 良 中 及格和不及 格 5 分制成績(jī) 2 62 2 63 從鍵盤(pán)輸入一個(gè)字符 判斷輸入的字符是數(shù)字 空格還是其他字符 并給出相應(yīng)的提 示信息 2 63 include int main char ch cout 請(qǐng)輸入一個(gè)字符 cin get ch if ch cout 這是一個(gè)空格 0 else cout 這是一個(gè)其他字符 endl return 0 2 64 從鍵盤(pán)輸入一個(gè)字符序列 編程統(tǒng)計(jì)其中的數(shù)字個(gè)數(shù)和英文字母?jìng)€(gè)數(shù) 輸入的字符序 列以 作為結(jié)束符 2 64 include int main char symbol 100 int i end j 0 k 0 cin symbol for i 0 i 100 i if symbol i end i break for i 0 i 0 else k cout digit j endl cout letter k endl return 0 2 65 輸入一個(gè)由若干單詞組成的文本串 每個(gè)單詞之間用一些空格分隔 統(tǒng)計(jì)此文本串單 詞的個(gè)數(shù) 2 65 include int main char str 1000 int count 1 cin get str 1000 while str 0 for int i 0 str i 0 i if str i cout the count is count endl return 0 2 67 編程求 值 使用如下公式 4 1 1 3 1 5 1 7 直到最后一項(xiàng)的絕對(duì)值小于 10 6 為止 2 67 1 include include int main int i n 1 j 1 double s 0 for i 0 2 i 1 pow 10 6 i cout i endl cout cout 2 i 1 endl cout cout pow 2 i 1 1 endl cout s pow 2 i 1 1 n j 2 i 1 n n 1 cout i endl cout 4 s endl return 0 2 67 2 include include int main float i 0 double s 0 for i 0 2 i 1 pow 10 6 i s pow 1 i 1 2 i 1 cout s 4 endl return 0 2 68 把 100 150 之間不能被 3 整除的數(shù)輸出 要求一行輸出 10 個(gè)數(shù) 2 68 2 69 編程輸出一個(gè)九九乘法表 2 69 include int main char table 9 9 int i j X Y for i 0 i 9 i for j 0 j Y cout X Y cout endl return 0 2 70 編程計(jì)算整型數(shù)各位數(shù)字之和 例如數(shù) 2007 各位數(shù)字之和為 2 0 0 7 9 2 70 include int main int num int sum 0 i cin num for i 0 num 0 i sum num 10 num num 10 cout sum sum endl return 0 2 71 輸入 n 個(gè)整數(shù) 利用冒泡排序法將它們從小到大排列 并在屏幕上輸出 2 71 include int main int n int i j temp int num 100 cin n for i 0 i num i for i 0 i n i for j i 1 j n j if num i num j temp num i num i num j num j temp for i 0 i n i cout num i cout endl return 0 2 72 編程求出從鍵盤(pán)輸入的 10 個(gè)數(shù)之和 遇到負(fù)數(shù)時(shí)終止輸入求和 2 72 include int main int Array 10 int sum 0 for int i 0 i Array i if Array i 0 sum Array i else break cout sum endl return 0 2 73 編程求出從鍵盤(pán)輸入的 10 個(gè)數(shù)中所有正數(shù)之和 負(fù)數(shù)不參加求和 2 73 include int main int num 10 int i sum 0 for i 0 i num i if num i 0 sum num i cout sum is sum endl return 0 2 74 設(shè)計(jì)函數(shù) prime 它只帶一個(gè)整型參數(shù) 當(dāng)這個(gè)參數(shù)的值是素?cái)?shù)時(shí) 該函數(shù)返回非 0 否則返回 0 利用這個(gè)函數(shù)編寫(xiě)一個(gè)程序來(lái)驗(yàn)證哥德巴赫猜想 任何一個(gè)大于 2 的偶數(shù)都 可以表示成兩個(gè)素?cái)?shù)之和 2 74 include int prime int x int i for i 2 i a if a 2 j a j b prime j if b j c a b d prime c if d c cout 該定理成立 endl else cout 此數(shù)不是大于 2 的偶數(shù) endl return 0 2 75 編制如下函數(shù)原型的函數(shù) int index const char str char c 這個(gè)函數(shù)返回字符串 str 中第一次出現(xiàn)字符 c 的位置 2 75 include int index const char str char c int count 1 int Ccount 0 for int i 0 str i 0 i if str i c break count return count int main char string 100 char C int V 0 int result cin string cin C while string V 0 V result index string C if V 1 result cout 此字符不在字符串中 endl else cout result endl return 0 2 76 首先編寫(xiě)以下函數(shù)聲明的函數(shù) void swap float px float py 該函數(shù)用于交換兩個(gè)實(shí) 型變量的值 然后編寫(xiě)一個(gè)主函數(shù)驗(yàn)證函數(shù) swap 的功能 2 76 include void swap float px float py float temp temp px px py py temp int main float X Y cin X Y swap cout 使用 swap 函數(shù)的值 cout X Y endl float temp temp X X Y Y temp cout 驗(yàn)證值 X Y endl return 0 2 77 定義將一個(gè)字符串反轉(zhuǎn)的函數(shù) 例如將字符串 abcd 反轉(zhuǎn)為 dcba 2 77 include include int Array char s int j n char string 100 strcpy string s for j 0 j str z Array str cout 0 i cout str i cout endl return 0 2 78 首先編寫(xiě)一個(gè)冒泡排序函數(shù) 然后在主函數(shù)中調(diào)用排序函數(shù)對(duì) 10 個(gè)整數(shù)從小到達(dá)進(jìn) 行排序 提示 采用數(shù)組名作為函數(shù)參數(shù) 2 78 2 79 將習(xí)題 2 76 中的 swap 函數(shù)改為內(nèi)聯(lián)函數(shù) 并實(shí)現(xiàn)相同的程序功能 2 79 include inline void swap float px float py float temp temp px px py py temp int main float X Y cin X Y swap cout 使用 swap 函數(shù)的值 cout X Y endl float temp temp X X Y Y temp cout 驗(yàn)證值 X Y endl return 0 2 80 編寫(xiě)一個(gè)函數(shù) maxmin 該函數(shù)有兩個(gè)實(shí)型參數(shù) 執(zhí)行函數(shù)后 第一個(gè)參數(shù)為兩個(gè) 參數(shù)中值較大者 第二個(gè)參數(shù)為較小者 要求使用引用作為函數(shù)參數(shù) 并編寫(xiě)主函數(shù)驗(yàn)證 函數(shù)功能 2 80 include void maxmin int if A X Y maxmin X Y cout X Y endl return 0 2 81 編寫(xiě)一個(gè)函數(shù) swapstruct 實(shí)現(xiàn)交換兩個(gè)結(jié)構(gòu)變量的功能 編寫(xiě)主函數(shù)驗(yàn)證函數(shù) swapstruct 的功能 要求使用引用傳遞參數(shù) 2 81 include include struct student char name 20 int score void swapstruct student char s 20 strcpy s s1 name strcpy s1 name s2 name strcpy s2 name s temp s1 score s1 score s2 score s2 score temp int main student stu1 zhangsan 90 student stu2 lisi 85 cout stu1 stu1 name stu1 score endl cout stu2 stu2 name stu2 score endl swapstruct stu1 stu2 cout stu1 stu1 name stu1 score endl cout stu2 stu2 name stu2 score endl return 0 2 82 編寫(xiě)一個(gè)程序 在主函數(shù) main 的外部和內(nèi)部分別聲明兩個(gè)同名的整型變量并賦值 然后在主函數(shù) main 中分別訪問(wèn)兩個(gè)變量 2 82 include int i 3 int main cout i endl int i 5 cout i endl return 0 2 83 一個(gè)程序由兩個(gè) C 源文件組成 在一個(gè)源文件中定義主函數(shù) main 并聲明一個(gè)外部 整型變量 n 在另一個(gè)源文件中定義一個(gè)不帶參數(shù)的函數(shù) factorial void 該函數(shù)用于計(jì)算變 量 n 的階乘 編程在主函數(shù) main 中輸入一個(gè)整數(shù)并求它的階乘 2 83 include int factorial int x int y pro 1 for y x y 0 y pro y return pro void main int n R cout n R factorial n cout The product is R endl 2 84 采用外部函數(shù)的方式使用習(xí)題 2 75 中的函數(shù) index 即在一個(gè)源文件中定義該函數(shù) 然后在另一個(gè)源文件中調(diào)用該函數(shù) 2 84 2 85 編寫(xiě)一段程序 利用 new 運(yùn)算動(dòng)態(tài)分配 float 型 long 型和 char 型三個(gè)內(nèi)存單元 將 它們的首地址分別賦給指針 pf pl 和 pc 給這些存儲(chǔ)但愿賦值 并在屏幕上顯示它們的值 最后利用 delete 運(yùn)算釋放所有動(dòng)態(tài)分配的內(nèi)存單元 2 85 include int main float pf new float pf 3 14 long pl new long pl 2135567889 char pc new char pc A cout pf endl cout pl endl cout pc endl delete pf delete pl delete pc return 0 2 86 編寫(xiě)一個(gè)程序 用 new 運(yùn)算為一個(gè)整型數(shù)組動(dòng)態(tài)分配內(nèi)存空間 對(duì)其進(jìn)行賦值 并在 屏幕上輸出 2 86 include int main int size int num cin size int f new int size for int i 0 i num f i num for i 0 i size i cout f i delete f return 0 2 87 采用動(dòng)態(tài)內(nèi)存分配方法設(shè)計(jì)一個(gè)學(xué)生成績(jī)處理程序 要求輸入任何數(shù)量學(xué)生的學(xué)號(hào) 姓名和四門課的成績(jī) 并按平均成績(jī)的高低輸出每個(gè)學(xué)生的高低輸出每個(gè)學(xué)生的姓名和成 績(jī) 2 87 include include struct student int ID char name 20 int grade 4 float average int main int num int i j k temp float sum 0 char s 20 cin num student stu new student num for i 0 i num i cout 輸入第 i 1 人的信息 endl cout stu i ID cout stu i name cout grade for j 0 j stu i grade j sum stu i grade j stu i average sum 4 sum 0 cout average stu i average endl for i 0 i num i 排序 for j i 1 j num j if stu i average stu j average strcpy s stu i name strcpy stu i name stu j name strcpy stu j name s for k 0 k 4 k temp stu i grade k stu i grade k stu j grade k stu j grade k temp cout 成績(jī)排名 endl cout name grade endl for i 0 i num i cout stu i name for j 0 j 4 j cout stu i grade j cout endl return 0 2 88 輸入一行字符 建立一個(gè)鏈表 鏈表的每一個(gè)結(jié)點(diǎn)含有一個(gè)輸入的字符 通過(guò)訪問(wèn)鏈 表中的每個(gè)結(jié)點(diǎn)計(jì)算鏈表中結(jié)點(diǎn)的總個(gè)數(shù) 2 88 2 89 使用帶參數(shù)的宏定義計(jì)算兩個(gè)實(shí)數(shù)之和 并編寫(xiě)主函數(shù)驗(yàn)證宏的功能 2 89 include define sum a b a b int main int x y cin x y cout 主函數(shù)計(jì)算結(jié)果 x y endl cout 宏定義函數(shù)結(jié)果 sum x y endl return 0 2 90 定義一個(gè)帶參數(shù)的宏 求出三個(gè)數(shù)中最大的一個(gè)數(shù) 并進(jìn)行驗(yàn)證 2 90 include define MAX a b a b a b void main int x y z cin x y z cout 宏定義參數(shù)結(jié)果 cout MAX MAX x y z y if x z cout 驗(yàn)證結(jié)果為 x endl else cout 驗(yàn)證結(jié)果為 z z cout 驗(yàn)證結(jié)果為 y endl else cout 驗(yàn)證結(jié)果為 z endl 2 91 輸入一個(gè)字符串 根據(jù)需要設(shè)置條件編譯 使之能將輸入的字符串以大寫(xiě)字母的形式 或小寫(xiě)字母的形式輸出 2 91 include int main char str 100 char X int i cin str cout 是否輸出大寫(xiě)形式 Y or N X if X Y for i 0 str i 0 i str i str i 32 cout str i else if X N for i 0 str i 0 i cout str i cout endl return 0 2 92 修改習(xí)題 2 61 中的求和程序 在程序中定義一個(gè)調(diào)試宏 利用條件編譯指令編譯不 同的代碼段 使得在調(diào)試程序時(shí)能夠輸出一些調(diào)試信息 2 92 2 93 假設(shè)有三個(gè)文件 test13 h test2 h 和 test cpp 在 test1 h 中定義了一個(gè)宏 PI test2 h 文件包含了 test1 h 文件 而 test cpp 文件又包含了 test1 h 文件和 test2 h 文件 請(qǐng)問(wèn)編譯時(shí) 會(huì)出現(xiàn)什么錯(cuò)誤 如何解決 提示 宏的重復(fù)定義 2 93 3 44 一個(gè)名為 CPerson 的類有如下屬性 姓名 身份證號(hào) 性別和年齡 請(qǐng)用 C 語(yǔ)言定義 這個(gè)類 并為上述屬性定義相應(yīng)的方法 include include class CPerson private char Name 10 char ID 20 char Sex 4 int Age public CPerson char na char id char se int ag void Show CPerson CPerson char na char id char se int ag strcpy Name na strcpy ID id strcpy Sex se Age ag void CPerson Show cout 姓名 Name endl cout 身份證 ID endl cout 性別 Sex endl cout 年齡 Age endl void main CPerson person 王三 610102198506041952 男 21 person Show 3 45 設(shè)計(jì)一個(gè)日期類 Date 該類用于表示日期值 年 月 日 要求除了能夠通過(guò)相應(yīng) 得成 員函數(shù)設(shè)置和獲取日期外 還能夠?qū)崿F(xiàn)將日期加一天的操作 include class date int year int month int day bool flag public date year 0 month 0 day 0 date int yr int mo int da void setdate int getyear int getmonth int getday void addday void show date date int yr int mo int da flag false if mo 1 month mo day da else flag true void date setdate cout 請(qǐng)輸入年分 year cout 請(qǐng)輸入月份 1 12 month while month12 cout 輸入有誤 請(qǐng)重新輸入月份 1 12 month cout 請(qǐng)輸入日期 1 31 day while day31 cout 輸入有誤 請(qǐng)重新輸入日期 1 31 day flag false void date show if flag cout year month day endl else cout 日期設(shè)置有誤 不能輸出 29 若是閏年的二月當(dāng) Day 大于 29 時(shí) Day 1 Mon 增加一 個(gè)月 day 1 month else if day 28 若不是閏年的二月當(dāng) Day 大于 28 時(shí) Day 1 Mon 增加 一個(gè)月 day 1 month else if month 1 month 3 month 5 month 7 month 8 month 10 month 12 if day 31 若不是二月月大時(shí) Day 1 Mon 增加一個(gè)月 day 1 month else if day 30 若不是二月月小時(shí) Day 1 Mon 增加一個(gè)月 day 1 month if month 12 若月大于 12 則 Mon 1 Year 增加一年 month 1 year void main date d1 1999 5 30 d1 show d1 setdate d1 show cout 日期增加一天后為 d1 addday d1 show 3 46 include using namespace std class CRectangle private double X double Y double length double width public CRectangle double s double e double l double w X s Y e length l width w CRectangle void Move double double void Size double double void Where void Area void CRectangle Move double x double y cout 矩形按向量 x y 移動(dòng) endl cout 現(xiàn)在矩形左上角所在的位置 endl cout X x Y y endl void CRectangle Size double cl double cw cout 要更改的長(zhǎng)和寬 cl cw length cl width cw cout length width endl void CRectangle Where cout 現(xiàn)在矩形左上角所在的位置 endl cout X Y endl void CRectangle Area double area area length width cout area int main CRectangle cr 2 3 5 4 cr Where cr Area cr Move 1 2 cr Size 2 3 return 0 3 47 include using namespace std class CRectangle private double X double Y double length double width public CRectangle double s double e double l double w X s Y e length l width w CRectangle void Move double double void Size double double void Where void Area void CRectangle Move double x double y cout 矩形按向量 x y 移動(dòng) endl cout 現(xiàn)在矩形左上角所在的位置 endl cout X x Y y endl void CRectangle Size double cl double cw cout 要更改的長(zhǎng)和寬 cl cw length cl width cw cout length width endl void CRectangle Where cout 現(xiàn)在矩形左上角所在的位置 endl cout X Y endl void CRectangle Area double area area length width cout area int main CRectangle cr 2 3 5 4 cr Where cr Area cr Move 1 2 cr Size 2 3 return 0 3 48 include include class Bank private char number 20 int money public void setnumber char num int mon strcpy number num money mon void changer int mon money mon void show cout 當(dāng)前的總錢數(shù)為 money endl void main char num 20 int money int addmoney cout 輸入用戶名和存入的錢 num money Bank bank bank setnumber num money bank show cout 輸入轉(zhuǎn)賬的錢 addmoney bank changer addmoney bank show 3 49 include using namespace std class Product private char name 20 double price int m count public Product Product void setproduct void sellproduct void show void Product setproduct int n cout 輸入生產(chǎn)產(chǎn)品數(shù)量 n m count n void Product sellproduct int n cout 輸入銷售產(chǎn)品數(shù)量 n m count n void Product show cout 輸出剩余產(chǎn)品數(shù)量 endl cout m count endl int main Product p p setproduct p sellproduct p show return 0 3 50 建立一個(gè)名為 Student 的類 該類有以下幾個(gè)私有成員變量 學(xué)生姓名 學(xué)號(hào) 性別 和年齡 還有以下兩個(gè)成員函數(shù) 一個(gè)用于初始化學(xué)生姓名 學(xué)號(hào) 性別和年齡的構(gòu)造函 數(shù) 一個(gè)用于輸出學(xué)生信息的函數(shù) 編寫(xiě)一個(gè)主函數(shù) 聲明一個(gè)學(xué)生對(duì)象 然后調(diào)用成員 函數(shù)在屏幕上輸出學(xué)生信息 include include class Student public Student char name char num char sex int age Student void show private char Name char Num char Sex int Age Student Student char name char num char sex int age Name new char strlen name 1 注意字符串的賦值 strcpy Name name Num new char strlen num 1 strcpy Num num Sex new char strlen sex 1 strcpy Sex sex Age age Student Student delete Name delete Num delete Sex void Student show cout 姓名 Name endl cout 學(xué)號(hào) Num endl cout 性別 Sex endl cout 年齡 Age endl void main Student student 張三 0401011201 男 18 student show 3 51 設(shè)計(jì)一個(gè) CPetrol 類 包含以下幾個(gè)私有成員 90 號(hào) 93 號(hào) 98 號(hào)汽油加油量和單價(jià) 當(dāng) 天的總收入 類還包含以下幾個(gè)成員函數(shù) 設(shè)置有關(guān)數(shù)據(jù)成員的構(gòu)造函數(shù) 輸入加油量并 計(jì)算總收入的成員函數(shù) 利用類編寫(xiě)主函數(shù) 假設(shè)加油站某天 90 93 98 號(hào)汽油單價(jià)分別為 3 96 4 05 4 38 計(jì)算并輸出加油站一天的收入 include using namespace std class CPetrol public CPetrol void setamount double total private double am 90 double am 93 double am 98 double price 90 double price 93 double price 98 CPetrol CPetrol price 90 3 96 price 93 4 05 price 98 4 38 void CPetrol setamount cout input three amounts am 90 am 93 am 98 total am 90 price 90 am 93 price 93 am 98 price 98 void main CPetrol c c setamount cout The total is c total endl 3 52 修改習(xí)題 3 50 中的類 Student 添加一個(gè)靜態(tài)成員變量 用于表示已創(chuàng)建對(duì)象的數(shù)量 添加兩個(gè)靜態(tài)成員函數(shù) 一個(gè)用于輸出已創(chuàng)建對(duì)象的數(shù)量 一個(gè)用于輸出一個(gè)學(xué)生的姓名 和 學(xué)號(hào) include include class Student public Student char name char num char sex int age Student staticvoid show Student staticvoid showstudentnum private char Name char Num char Sex int Age static int studentnum int Student studentnum 0 Student Student char name char num char sex int age studentnum Name new char strlen name 1 strcpy Name name Num new char strlen num 1 strcpy Num num Sex new char strlen sex 1 strcpy Sex sex Age age Student Student delete Name delete Sex void Student showstudentnum cout 學(xué)生的數(shù)量是 studentnum endl void Student show Student cout 學(xué)號(hào) a Num endl cout 性別 a Sex endl cout 年齡 a Age endl void main Student student1 張三 0401011201 男 18 Student show student1 注意調(diào)用方式 靜態(tài)成員可以通過(guò)類名調(diào)用 Student showstudentnum 注意調(diào)用方式 Student student2 李四 0401011202 男 18 Student show student2 Student showstudentnum 3 53 編寫(xiě)程序用靜態(tài)成員的方法實(shí)現(xiàn)對(duì)班費(fèi)的管理 要求定義一個(gè)類 Student 除了聲明一個(gè)存 放班費(fèi)的靜態(tài)成員 還要分別定義一個(gè)上交班費(fèi)的成員函數(shù) Contribute 花費(fèi)班費(fèi)的成 員函數(shù) Spend 和顯示班費(fèi)的靜態(tài)成員函數(shù) Display student cpp include using namespace std class Student private static double fee fee 班費(fèi) 靜態(tài)成員數(shù)據(jù) public Student 默認(rèn)構(gòu)造函數(shù) 析構(gòu)函數(shù) Student void Contribute double n n 上繳的班費(fèi)數(shù)額 void Spend double n n 花費(fèi)班費(fèi)數(shù)量 static void Display 靜態(tài)成員函數(shù) double Student fee 0 類聲明外面對(duì)靜態(tài)數(shù)據(jù)成員初始化 類方法 void Student Contribute double n fee fee n void Student Spend double n if fee n cout 班費(fèi)不夠 請(qǐng)求失敗 n else fee fee n void Student Display cout 現(xiàn)有班費(fèi) fee endl int main Student stu stu Display stu Contribute 103 4 交錢 stu Display stu Spend 42 3 花錢 stu Display return 0 放在了一個(gè)文件里了 上面是類聲明 下面是測(cè)試小程序 運(yùn)行過(guò)了 沒(méi)問(wèn)題 3 54 定義一個(gè)類 A 該類除了有兩個(gè)數(shù)據(jù)成員 x y 外 還有一個(gè)對(duì)象備份函數(shù) copy copy 函數(shù)的功能說(shuō)明如下 對(duì)于類 A 的對(duì)象 a1 和 a2 函數(shù)調(diào)用 a1 copy a2 表示將對(duì)象 a2 賦值給對(duì)象 a1 提示利用 this 指針?lè)乐挂粋€(gè)對(duì)象對(duì)自己賦值 include using namespace std class Test private char a b public Test a new char 100 b new char 100 Test delete a delete b Test Test int len strlen B a delete a a new char len 1 strcpy a B a len strlen B b delete b b new char len 1 strcpy b B b return this void mytest char str1 char str2 strcpy a str1 strcpy b str2 void myprint cout a b endl A B int main B mytest this is B B myprint A copy B A myprint return 0 3 55 將習(xí)題 3 45 中類 Date 的 日期加一天 成員函數(shù)改為友員函數(shù) include class date int year int month int day bool flag public date year 0 month 0 day 0 date int yr int mo int da void setdate int getyear int getmonth int getday friend void addday date void show date date int yr int mo int da flag false if mo 1 month mo day da else flag true void date setdate cout 請(qǐng)輸入年分 year cout 請(qǐng)輸入月份 1 12 month while month12 cout 輸入有誤 請(qǐng)重新輸入月份 1 12 month cout 請(qǐng)輸入日期 1 31 day while day31 cout 輸入有誤 請(qǐng)重新輸入日期 1 31 day flag false void date show if flag cout year month day endl else cout 日期設(shè)置有誤 不能輸出 29 若是閏年的二月當(dāng) Day 大于 29 時(shí) Day 1 Mon 增加一 個(gè)月 d day 1 d month else if d day 28 若不是閏年的二月當(dāng) Day 大于 28 時(shí) Day 1 Mon 增加 一個(gè)月 d day 1 d month else if d month 1 d month 3 d month 5 d month 7 d month 8 d month 10 d month 12 if d day 31 若不是二月月大時(shí) Day 1 Mon 增加一個(gè)月 d day 1 d month else if d day 30 若不是二月月小時(shí) Day 1 Mon 增加一個(gè)月 d day 1 d month if d month 12 若月大于 12 則 Mon 1 Year 增加一年 d month 1 d year void main date d1 1999 5 30 d1 show d1 setdate d1 show cout 日期增加一天后為 addday d1 d1 show 3 56 將習(xí)題 3 50 中類 Student 的學(xué)生信息輸出函數(shù)改為友員函數(shù) include include class Student public Student char name char num char sex int age Student friend void show Student private char Name char Num char Sex int Age Student Student char name char num char sex int age Name new char strlen name 1 strcpy Name name Num new char strlen num 1 strcpy Num num Sex new char strlen sex 1 strcpy Sex sex Age age 注意字符串的賦值 Student Student delete Name delete Sex void show Student cout 學(xué)號(hào) stu Num endl cout 性別 stu Sex endl cout 年齡 stu Age endl void main Student student 張三 0401011201 男 18 show student 3 57 設(shè)計(jì)一個(gè)直線類 Line 設(shè)直線方程為 ax bx c 0 其中 包含三個(gè)數(shù)據(jù)成員 a b c 一 個(gè)顯示數(shù)據(jù)成員的 disp 成員函數(shù)和一個(gè)求兩直線交點(diǎn)的友元函數(shù) setpoint 并在 main 中給 出對(duì)象或數(shù)據(jù)進(jìn)行測(cè)試 請(qǐng)?zhí)羁胀瓿沙绦虿⑸蠙C(jī)運(yùn)行驗(yàn)證 include class Line friend void setpoint Line private double a double b double c public Line double a1 double b1 double c1 a a1 b b1 c c1 Line void setpoint Line if A a B a A b B b x 100 while 1 if A c A a x A b B c B a x B b 0 00001 break x x 0 00001 cout x A c A a x A b else cout error endl void main Line A 2 1 4 B 1 10 3 setpoint A B 3 58 include include class Student private char name 10 char id 20 char sex 20 int age public Student char pname 10 char pid 20 char psex 5 int page Student void show const Student Student char pname 10 char pid 20 char psex 5 int page strcpy name pname strcpy id pid strcpy sex psex age page void Student show const cout 姓名 name endl 學(xué)號(hào) id endl 性別 sex endl 年齡 age endl int main const Student student1 jane 200931106013 famle 20 student1 show 通過(guò)常對(duì)象只能調(diào)用常函數(shù) Student student2 jane2 200931106013 famle 20 student2 show 通過(guò)普通對(duì)象也能調(diào)用常成員函數(shù) return 0 3 59 include class CPoint private float x float y public CPoint float xx 0 float yy 0 CPoint float Getx float Gety CPoint CPoint float xx float yy x xx y yy CPoint CPoint floa

注意事項(xiàng)

本文(VisualC++面向?qū)ο缶幊探坛痰?版(王育堅(jiān))清華大學(xué)出版社課后答案)為本站會(huì)員(gbs****77)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請(qǐng)重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!