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

正文內(nèi)容

c面向?qū)ο蟪绦蛟O(shè)計(jì)習(xí)題解答與上機(jī)指導(dǎo)(第二版)源程序(編輯修改稿)

2025-07-04 13:33 本頁面
 

【文章內(nèi)容簡介】 est fri,fri1。 (fri)。 friend_f(fri1)。 return 0。}【解】includeiostream using namespace std。class CTest{public: CTest() { x=20。 } void use_friend()。private: int x。 friend void friend_f(CTest fri)。}。void friend_f(CTest fri){ =55。}void CTest::use_friend(){ CTest fri。thisfriend_f(fri)。 // 錯(cuò)誤, 友元函數(shù)不是成員函數(shù),// 所以不能用this調(diào)用友元函數(shù) ::friend_f(fri)。}int main(){ CTest fri,fri1。(fri)。 // 錯(cuò)誤友元函數(shù)不是成員函數(shù),// 所以不能用“”調(diào)用友元函數(shù) friend_f(fri1)。 return 0。}【】指出下面程序中的錯(cuò)誤,并說明原因。includeiostream using namespace std。class CTest{public: CTest () { x=20。 } void use_this()。private: int x。}。void CTest::use_this(){ CTest y,*pointer。 this=amp。y。 *=10。 pointer=this。 pointer=amp。y。}int main(){ CTest y。 thisx=235。 return 0。}【解】includeiostream using namespace std。class CTest{public: CTest (){ x=20。 } void use_this()。private: int x。}。void CTest::use_this(){ CTest y,*pointer。 this=amp。y。 // 錯(cuò)誤,不能對this直接賦值。 *=10。 // 錯(cuò)誤, 按優(yōu)先級原句的含義是*()=10,顯然不對// 正確的寫法是(*this).x=10?;? thisx=10。 pointer=this。 pointer=amp。y。}int main(){ CTest y。 thisx=235。 // 錯(cuò)誤,this的引用不能在外部函數(shù)中,只能在內(nèi)部函數(shù)中。 Return 0。}【】寫出下面程序的運(yùn)行結(jié)果。includeiostream using namespace std。class toy{ public: toy(int q, int p) { quan = q。 price = p。 } int get_quan(){ return quan。} int get_price() { return price。}private: int quan, price。 }。int main(){ toy op[3][2]={ toy(10,20),toy(30,48), toy(50,68),toy(70,80), toy(90,16),toy(11,120),}。 for (int i=0。i3。i++) { coutop[i][0].get_quan(),。 coutop[i][0].get_price()\n。 coutop[i][1].get_quan(),。 coutop[i][1].get_price()\n。 } coutendl。 return 0。}【】寫出下面程序的運(yùn)行結(jié)果。includeiostream using namespace std。class example{ public: example(int n) { i=n。 coutConstructing\n 。 } ~example() { cout Destructing\n。 } int get_i() { return i。 }private: int i。}。int sqr_it(example o){ return ()* ()。}int main(){ example x(10)。 cout()endl。 coutsqr_it(x)endl。 return 0。}【】寫出下面程序的運(yùn)行結(jié)果。includeiostream using namespace std。class aClass{ public:aClass(){ total++。}~aClass(){ total。}int gettotal(){ return total。}private:static int total。}。int aClass::total=0。int main(){ aClass o1,o2,o3。 cout() objects in existence\n。 aClass *p。 p=new aClass。 if (!p) { coutAllocation error\n。 return 1。 } cout()。 cout objects in existence after allocation\n。 delete p。 cout()。 cout objects in existence after deletion\n。 return 0。}【】寫出下面程序的運(yùn)行結(jié)果。includeiostream using namespace std。class test{ public: test() 。 ~test(){ }。 private: int i。}。test::test(){ i = 25。 coutHere's the program output. \n。 coutLet′s generate some stuff...\n。 for (int ctr=0。 ctr10。 ctr++) { coutCounting at ctr\n。 }}test anObject。int main( ){ return 0。}【】 構(gòu)建一個(gè)類book,其中含有兩個(gè)私有數(shù)據(jù)成員qu和price, 建立一個(gè)有5個(gè)元素的數(shù)組對象,將qu初始化為1~5,將price 初始化為qu的10倍。顯示每個(gè)對象的qu*price?!窘狻繉?shí)現(xiàn)本題功能的程序如下:includeiostream using namespace std。class book{ public: book(int a, int b) { qu= a。price= b。 } void show_money() { coutqu*price\n。}private: int qu,price。}。int main(){ book ob[5]={ book(1,10),book(2,20), book(3,30),book(4,40),book(5,50) }。 int i。 for(i=0。 i5。 i++) ob[i].show_money()。 return 0。}【】 修改上題,通過對象指針訪問對象數(shù)組,使程序以相反的順序顯示對象數(shù)組的qu*price?!窘狻繉?shí)現(xiàn)本題功能的程序如下:includeiostream using namespace std。class book{ public: book(int a, int b) { qu= a。price= b。 } void show_money() { coutqu*price\n。}private: int qu,price。}。int main(){ book ob[5]={ book(1,10),book(2,20), book(3,30),book(4,40), book(5,50) }。 int i。book *p。p=amp。ob[4]。 for(i=0。 i5。 i++) { pshow_money()。p。 } return 0。}【】使用 C++ 的類建立一個(gè)簡單的賣玩具的程序。類內(nèi)必須具有玩具單價(jià)、售出數(shù)量以及每種玩具售出的總金額等數(shù)據(jù),并為該類建立一些必要的函數(shù),并在主程序中使用對象數(shù)組建立若干個(gè)帶有單價(jià)和售出數(shù)量的對象,顯示每種玩具售出的總金額?!窘狻繉?shí)現(xiàn)本題功能的程序如下:includeiostream using namespace std。class toy{ public: toy(){ } toy(int p,int c){ Price=p。 Count=c。 } void Input(int P, int C) 。 void Compute() 。 void Print() 。private: int Price。 int Count。 long Total。}。void toy::Input (int P, int C){ Price=P。 Count=C。}void toy::Compute(){ Total=(long) Price*Count。}void toy::Print(){ coutPrice=Price Count=Count Total=Total \n。 }int main(){ toy te(2,100)。 // 測試構(gòu)造函數(shù) toy* ob。 ob = new toy[6]。 ob[0].Input(25,130)。 ob[1].Input(30,35)。 ob[2].Input(15,20)。 ob[3].Input(25,120)。 ob[4].Input(45,10)。 ob[5].Input(85,65)。 for (int i=0。 i6。 i++) ob[i].Compute()。 for (i=0。 i6。 i++) ob[i].Print()。 delete ob。 return 0。}【】 構(gòu)建一個(gè)類Stock,含字符數(shù)組stockcode[]及整型數(shù)據(jù)成員quan、雙精度型數(shù)據(jù)成員price。構(gòu)造函數(shù)含3個(gè)參數(shù):字符數(shù)組na[]及q、p。當(dāng)定義Stock的類對象時(shí),將對象的第1個(gè)字符串參數(shù)賦給數(shù)據(jù)成員stockcode,第2和第3個(gè)參數(shù)分別賦給quan、price。未設(shè)置第2和第3個(gè)參數(shù)時(shí),quan的值為1000。成員函數(shù) print()使用this指針,顯示對象內(nèi)容。
【解】實(shí)現(xiàn)本題功能的程序如下:includeiostream u
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)教案相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1