freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

c++語言程序設(shè)計(jì)課后習(xí)題答案(文件)

2025-08-26 19:09 上一頁面

下一頁面
 

【正文】 break。 解: 源程序: include int fn1(int i,int j)。 cout 請輸入另一個(gè)正整數(shù): 。 cout i 和 j 的最大公約數(shù)是: x endl。 i = j。 j = temp。 312在主程序中提示輸入整數(shù) n,編寫函數(shù)用遞歸的方法求 1 + 2 + … + n 的值。 cin i 。 } 程序運(yùn)行輸出: 請輸入一個(gè)正整數(shù): 100 從 1累加到 100的和為: 5050 313編寫遞歸函數(shù) GetPower(int x, int y)計(jì)算 x的 y次冪,在主程序中實(shí)現(xiàn)輸入輸出。 cout Enter a number: 。 answer = GetPower(number, power)。 else return (x * GetPower(x, y1))。 解: 源程 序見 實(shí)驗(yàn)指導(dǎo) 部分實(shí)驗(yàn)三 315用遞歸的方法編寫函數(shù)求 n階勒讓德多項(xiàng)式的值,在主程序中實(shí)現(xiàn)輸入、輸出; 解: include float p(int n, int x)。 cout 請輸入正整數(shù) x: 。 cout P n ( x ) = p(n,x) endl。 } 程序運(yùn)行輸出: 請輸入正整數(shù) n: 1 請輸入正整數(shù) x: 2 n = 1 x = 2 P1(2) = 2 請輸入正整數(shù) n: 3 請輸入正整數(shù) x: 4 n = 3 x = 4 P3(4) = 154 316使用模板函數(shù)實(shí)現(xiàn) Swap( x, y ),函數(shù)功能為交換 x、 y的值。 z = x。 cout j = j k = k endl。 //double cout After swap: endl。 42 protected關(guān)鍵字有何作用? 解: 。 44 數(shù)據(jù)成員可以為公有的嗎?成員函數(shù)可以為私有的嗎? 解: 可以,二者都是合法的。 46 什么叫做拷貝構(gòu)造函數(shù)?拷貝構(gòu)造函數(shù)何時(shí)被調(diào)用? 解: 拷貝構(gòu)造函數(shù)是一種特殊的構(gòu)造函數(shù),具有一般構(gòu)造函數(shù)的所有特性,其形參是本類的對象 的引用,其作用是使用一個(gè)已經(jīng)存在的對象,去初始化一個(gè)新的同類的對象。 解: 源程序: include class Dog { public: Dog (int initialAge = 0, int initialWeight = 5)。} // inline! int GetWeight() { return itsWeight。 Dog::Dog(int initialAge, int initialWeight) { itsAge = initialAge。 cout () years old and。 cout Now Jack is 。 ~Rectangle () {} int GetTop() const { return itsTop。 } void SetTop(int top) { itsTop = top。 } int GetArea() const。 int itsRight。 itsRight = right。 } int main() { Rectangle MyRectangle (100, 20, 50, 80 )。 } 程序運(yùn)行輸出: Area: 3000 Upper Left X Coordinate: 20 410設(shè)計(jì)一個(gè)用于人事管理的 People(人員)類。要求包括:構(gòu)造函數(shù)和析構(gòu)函數(shù)、拷貝構(gòu)造函數(shù)、內(nèi)聯(lián)成員函數(shù)、帶缺省形參值的成 員函數(shù)、聚集。 } ~Rectangle(){}。 } private: float Length。 cout 請輸入矩形的長度: 。 Rectangle r(length, width)。 union { char c。 public: datatype(char ch) { vartype = character。 } datatype(float ff) { vartype = floating_point。 void datatype::print() { switch (vartype) { case character: cout 字符型 : c endl。 case floating_point: cout 浮點(diǎn)型 : f endl。), B(12), C()。 程序運(yùn)行輸出: 字符型 : c 整型 : 12 浮點(diǎn)型 : 413定義一個(gè) Circle類,有數(shù)據(jù)成員半徑 Radius,成員函數(shù) GetArea(),計(jì)算圓的面積,構(gòu) 造一個(gè) Circle的對象進(jìn)行測試。 }。 Circle p(radius)。 public: Tree(int n=0)。 }。 } void Tree::age() { cout 這棵樹的年齡為 ages endl。 } 程序運(yùn)行輸出: 這棵樹的年齡為 12 這棵樹的年齡 為 16 章 C++程序的基本結(jié)構(gòu) 51 什么叫做作用域?有哪幾種類型的作用域? 解: 作用域討論的是標(biāo)識符的有效范圍,作用域是一個(gè)標(biāo)識符在程序正文中有效的區(qū)域。 include void myFunction()。 myFunction()。 return 0。 解: 程序運(yùn)行輸出: x from main: 5 y from main: 7 x from myFunction: 5 y from myFunction: 10 Back from myFunction! x from main: 5 y from main: 7 54 假設(shè)有兩個(gè)無關(guān)系的類 Engine和
。 cout x from myFunction: x \n。 cout x from main: x \n。 int main() { cout x from main: x \n。對于在不同的作用域聲明的標(biāo)識符,遵循的原則是:若有 兩個(gè)或多個(gè)具有包含關(guān)系的 作用域,外層聲明的標(biāo)識符如果在內(nèi)層沒有聲明同名標(biāo)識符時(shí)仍可見,如果內(nèi)層聲明了同名 標(biāo)識符則外層標(biāo)識符不可見。 ()。 } Tree::~Tree() { age()。 void grow(int years)。 } 程序運(yùn)行輸出: 請輸入圓的半徑 : 5 半徑為 5的圓的面積為: 414定義一個(gè) tree類,有成員 ages,成員函數(shù) grow(int years)對 ages 加上 years,age()顯示 tree 對象的 ages 的值。 cout 請輸入圓的半徑: 。} ~Circle(){} float GetArea() { return * Radius * Radius。 ()。 } } void main() { datatype A(39。 case integer: cout 整型 : i endl。 } void print()。 } datatype(int ii) { vartype = integer。 float f。 } 程序運(yùn)行輸出: 請輸入矩形的長度: 5 請輸入矩形的寬度: 4 長為 5寬為 4的矩形的面積為: 20 412定義一個(gè) 數(shù)據(jù)類型 datatype類,能處理包含字符型、整型、浮點(diǎn)型三種類型的數(shù)據(jù), 給出其構(gòu)造函數(shù)。 cout 請輸入矩形的寬度: 。 }。 } float GetLength() { return Length。 411 定義一個(gè)矩形類,有長、寬兩個(gè)屬性,有成員函數(shù)計(jì)算矩形的面積 解: include class Rectangle { public: Rectangle(float len, float width) { Length = len。其中 出生日期 定義為一個(gè) 日期 類內(nèi)嵌子對象。 cout Area: Area \n。 int Height = itsTop itsBottom。 Rectangle::Rectangle(int top, int left, int bottom, int right) { itsTop = top。 int itsLeft。 } void SetBottom (int bottom) { itsBottom = bottom。 } int GetBottom() const { return itsBottom。 } 程序運(yùn)行輸出: Jack is a Dog who is 2 years old and 10 pounds weight. Now Jack is 7 years old 20 pounds weight. 49 設(shè)計(jì)并測試一個(gè)名為 Rectangle 的矩形類,其屬性為矩形的左下角與右上角兩個(gè)點(diǎn)的坐 標(biāo),能計(jì)算矩形的面積。 (7)。 } Dog::~Dog() //destructor, takes no action { } int main() { Dog Jack(2, 10)。} // inline! private: int itsAge, itsWeight。 int GetAge() { return itsAge。 48 定 義一個(gè) Dog 類,包含的 age、 weight等屬性,以及對這些屬性操作的方法。但數(shù)據(jù)成員最好定義 為私有的。 析構(gòu)函數(shù)與構(gòu)造函數(shù)的作用幾乎正好相反,它是用來完成對象被刪除 前的一些清理工作,也 就是專門作掃尾工作的。 cout v = v w = w endl。 swap(j, k)。 } void main() { int j = 1, k = 2。x, T amp。 else if (n == 1) return x。 cout n = n endl。 數(shù) n: 。 fib(1) = fib(2) = 1。 return 0。 cout To what power? 。 { int number, power。 } int fn1(int i) { if (i == 1) return 1。 void main() { int i。 } 程序運(yùn)行輸出: 請輸入一個(gè)正整數(shù): 120 請輸入另一個(gè)正整數(shù): 72 120和 72的最大公約數(shù)是: 24 120和 72的最小公倍數(shù)是: 360 311 什么叫作嵌套調(diào)用?什么叫作遞歸調(diào)用? 數(shù) 1調(diào)用了函數(shù) 2,函數(shù) 2再調(diào)用函數(shù) 3,便形成了函數(shù)的嵌套 調(diào)用。 } whil
點(diǎn)擊復(fù)制文檔內(nèi)容
研究報(bào)告相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1