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

正文內(nèi)容

c語(yǔ)言程序設(shè)計(jì)課后習(xí)題答案-資料下載頁(yè)

2025-07-27 19:09本頁(yè)面

【導(dǎo)讀】1-1簡(jiǎn)述計(jì)算機(jī)程序設(shè)計(jì)語(yǔ)言的發(fā)展歷程。言是一種面向?qū)ο蟮木幊陶Z(yǔ)言,也屬于高級(jí)語(yǔ)言。的描述客觀世界中存在的事物以及它們之間的關(guān)系。通過(guò)類的繼承與多態(tài)可以很方便地實(shí)現(xiàn)代碼重用,大大縮短了軟件開發(fā)。得軟件風(fēng)格統(tǒng)一。因此,面向?qū)ο蟮木幊陶Z(yǔ)言使程序能夠比較直接地反問(wèn)題域的。軟件開發(fā)人員能夠利用人類認(rèn)識(shí)事物所采用的一般思維方法來(lái)進(jìn)行軟件開發(fā)。前應(yīng)用最廣的面向?qū)ο蟮木幊陶Z(yǔ)言。循環(huán)三種基本結(jié)構(gòu)組成;其模塊化實(shí)現(xiàn)的具體方法是使用子程序。設(shè)計(jì)任務(wù)分解成許多易于控制和處理的子任務(wù),便于開發(fā)和維護(hù)。據(jù)和處理數(shù)據(jù)的過(guò)程分離為相互獨(dú)立的實(shí)體。當(dāng)數(shù)據(jù)結(jié)構(gòu)改變時(shí),所有相關(guān)的處。對(duì)同類型對(duì)象抽象出其共性,形成類。類通過(guò)一個(gè)簡(jiǎn)單的外部接口,與外界發(fā)生關(guān)系,對(duì)象與對(duì)象之間通過(guò)消息。位,并盡可能隱蔽對(duì)象的內(nèi)部細(xì)節(jié)。其缺點(diǎn)是它表示數(shù)的容量較小,表示同一個(gè)數(shù),二進(jìn)制較其。正數(shù)的反碼和補(bǔ)碼與原碼表示相同。查出更多的類型錯(cuò)誤。

  

【正文】 eight) { itsAge = weight。} // inline! private: int itsAge, itsWeight。 }。 Dog::Dog(int initialAge, int initialWeight) { itsAge = initialAge。 itsWeight = initialWeight。 } Dog::~Dog() //destructor, takes no action { } int main() { Dog Jack(2, 10)。 cout Jack is a Dog who is 。 cout () years old and。 cout () pounds weight.\n。 (7)。 (20)。 cout Now Jack is 。 return 0。 } 程序運(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ì)并測(cè)試一個(gè)名為 Rectangle 的矩形類,其屬性為矩形的左下角與右上角兩個(gè)點(diǎn)的坐 標(biāo),能計(jì)算矩形的面積。 解: 源程序: include class Rectangle { public: Rectangle (int top, int left, int bottom, int right)。 ~Rectangle () {} int GetTop() const { return itsTop。 } int GetLeft() const { return itsLeft。 } int GetBottom() const { return itsBottom。 } int GetRight() const { return itsRight。 } void SetTop(int top) { itsTop = top。 } void SetLeft (int left) { itsLeft = left。 } void SetBottom (int bottom) { itsBottom = bottom。 } void SetRight (int right) { itsRight = right。 } int GetArea() const。 private: int itsTop。 int itsLeft。 int itsBottom。 int itsRight。 }。 Rectangle::Rectangle(int top, int left, int bottom, int right) { itsTop = top。 itsBottom = bottom。 itsRight = right。 } int Rectangle::GetArea() const { int Width = itsRightitsLeft。 int Height = itsTop itsBottom。 return (Width * Height)。 } int main() { Rectangle MyRectangle (100, 20, 50, 80 )。 int Area = ()。 cout Area: Area \n。 return 0。 } 程序運(yùn)行輸出: Area: 3000 Upper Left X Coordinate: 20 410設(shè)計(jì)一個(gè)用于人事管理的 People(人員)類。考慮到通用性,這里只抽象出所有類型 人員都具有的屬性: number(編號(hào))、 sex(性別)、 birthday(出生日期)、 id(身份證號(hào))等 等。其中 出生日期 定義為一個(gè) 日期 類內(nèi)嵌子對(duì)象。用成員函數(shù)實(shí)現(xiàn)對(duì)人員信息的錄入和 顯示。要求包括:構(gòu)造函數(shù)和析構(gòu)函數(shù)、拷貝構(gòu)造函數(shù)、內(nèi)聯(lián)成員函數(shù)、帶缺省形參值的成 員函數(shù)、聚集。 解: 本題用作實(shí)驗(yàn)四的選做題,因此不給出答案。 411 定義一個(gè)矩形類,有長(zhǎng)、寬兩個(gè)屬性,有成員函數(shù)計(jì)算矩形的面積 解: include class Rectangle { public: Rectangle(float len, float width) { Length = len。 Width = width。 } ~Rectangle(){}。 float GetArea() { return Length * Width。 } float GetLength() { return Length。 } float GetWidth() { return Width。 } private: float Length。 float Width。 }。 void main() { float length, width。 cout 請(qǐng)輸入矩形的長(zhǎng)度: 。 cin length。 cout 請(qǐng)輸入矩形的寬度: 。 cin width。 Rectangle r(length, width)。 cout 長(zhǎng)為 length 寬為 width 的矩形的面積為: () endl。 } 程序運(yùn)行輸出: 請(qǐng)輸入矩形的長(zhǎng)度: 5 請(qǐng)輸入矩形的寬度: 4 長(zhǎng)為 5寬為 4的矩形的面積為: 20 412定義一個(gè) 數(shù)據(jù)類型 datatype類,能處理包含字符型、整型、浮點(diǎn)型三種類型的數(shù)據(jù), 給出其構(gòu)造函數(shù)。 解: include class datatype{ enum{ character, floating_point } vartype。 union { char c。 int i。 float f。 }。 public: datatype(char ch) { vartype = character。 c = ch。 } datatype(int ii) { vartype = integer。 i = ii。 } datatype(float ff) { vartype = floating_point。 f = ff。 } void print()。 }。 void datatype::print() { switch (vartype) { case character: cout 字符型 : c endl。 break。 case integer: cout 整型 : i endl。 break。 case floating_point: cout 浮點(diǎn)型 : f endl。 break。 } } void main() { datatype A(39。c39。), B(12), C()。 ()。 ()。 ()。 程序運(yùn)行輸出: 字符型 : c 整型 : 12 浮點(diǎn)型 : 413定義一個(gè) Circle類,有數(shù)據(jù)成員半徑 Radius,成員函數(shù) GetArea(),計(jì)算圓的面積,構(gòu) 造一個(gè) Circle的對(duì)象進(jìn)行測(cè)試。 解: include class Circle { public: Circle(float radius){ Radius = radius。} ~Circle(){} float GetArea() { return * Radius * Radius。 } private: float Radius。 }。 void main() { float radius。 cout 請(qǐng)輸入圓的半徑: 。 cin radius。 Circle p(radius)。 cout 半徑為 radius 的圓的面積為: () endl。 } 程序運(yùn)行輸出: 請(qǐng)輸入圓的半徑 : 5 半徑為 5的圓的面積為: 414定義一個(gè) tree類,有成員 ages,成員函數(shù) grow(int years)對(duì) ages 加上 years,age()顯示 tree 對(duì)象的 ages 的值。 include class Tree { int ages。 public: Tree(int n=0)。 ~Tree()。 void grow(int years)。 void age()。 }。 Tree::Tree(int n) { ages = n。 } Tree::~Tree() { age()。 } void Tree::grow(int years) { ages += years。 } void Tree::age() { cout 這棵樹的年齡為 ages endl。 } void main() { Tree t(12)。 ()。 (4)。 } 程序運(yùn)行輸出: 這棵樹的年齡為 12 這棵樹的年齡 為 16 章 C++程序的基本結(jié)構(gòu) 51 什么叫做作用域?有哪幾種類型的作用域? 解: 作用域討論的是標(biāo)識(shí)符的有效范圍,作用域是一個(gè)標(biāo)識(shí)符在程序正文中有效的區(qū)域。 C++的 作用域分為函數(shù)原形作用域、塊作用域 (局部作用域 )、類作用域和文件作用域 . 52 什么叫做可見(jiàn)性?可見(jiàn)性的一般規(guī)則是什么? 解: 可見(jiàn)性是標(biāo)識(shí)符是否可以引用的問(wèn)題; 可見(jiàn)性的一般規(guī)則是:標(biāo)識(shí)符要聲明在前,引用在后,在同一作用域中,不能聲明同名的標(biāo) 識(shí)符。對(duì)于在不同的作用域聲明的標(biāo)識(shí)符,遵循的原則是:若有 兩個(gè)或多個(gè)具有包含關(guān)系的 作用域,外層聲明的標(biāo)識(shí)符如果在內(nèi)層沒(méi)有聲明同名標(biāo)識(shí)符時(shí)仍可見(jiàn),如果內(nèi)層聲明了同名 標(biāo)識(shí)符則外層標(biāo)識(shí)符不可見(jiàn)。 53 下面的程序的運(yùn)行結(jié)果是什么,實(shí)際運(yùn)行一下,看看與你的設(shè)想有何不同。 include void myFunction()。 int x = 5, y = 7。 int main() { cout x from main: x \n。 cout y from main: y \n\n。 myFunction()。 cout Back from myFunction!\n\n。 cout x from main: x \n。 cout y from main: y \n。 return 0。 } void myFunction() { int y = 10。 cout x from myFunction: x \n。 cout y from myFunction: y \n\n。 解: 程序運(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è)無(wú)關(guān)系的類 Engine和
點(diǎn)擊復(fù)制文檔內(nèi)容
研究報(bào)告相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1