




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第七章習題答案一、選擇填空1、D2、A3、B4、C5、A6、C7、B8、D9、二、判斷下列描述的對的性,對者劃√,錯者劃×。1、√2、×3、×4、×5、√6、×7、√8、√9、√10、×11、√12、√13、×14、√15、√16、×17、√18、√三、分析下列程序的輸出結(jié)果。1、(1)上述結(jié)構(gòu)的DAG圖如下所示。(2)無二義性(3)無二義性2、(1)無(2無(3)有(4)無(5)有四、分析下列程序的輸出結(jié)果1、運營該程序輸出如下結(jié)果。(1,2)5,6(6,9)2、該程序的輸出結(jié)果如下所示(1,2)(6,9)5,6(6,9)3、該程序的輸出結(jié)果如下:(13,22,30,40)4、運營該程序輸出結(jié)果如下所示。D2::display()pri1=4,pri2=5pri4=6pri12=7D2::display()pri1=12,pri2=9pri4=7pri12=85、該程序輸出結(jié)果如下所示:D2::display()pri1=1,pri2=4pri4=6pri12=7D2::display()pri1=9,pri2=8pri4=7pri12=86、該程序輸出結(jié)果如下所示:baseclassbaseclassbaseclassderive1classderive2class五、按下列規(guī)定編寫程序。1、程序內(nèi)容如下所示。#include<iostream.h>#include<iomanip.h>classperson{intno;charname[10];public:voidinput(){cout<<"編號:";cin>>no;cout<<"姓名:";cin>>name;}voiddisp(){cout<<"編號:"<<no<<endl;cout<<"姓名:"<<name<<endl;}};classstudent:publicperson{private:chardepart[6];intdegree;public:voidinput(){person::input();cout<<"班號:";cin>>depart;cout<<"成績:";cin>>degree;}voiddisp(){person::disp();cout<<"班號:"<<depart<<endl;cout<<"成績:"<<degree<<endl;}};classteacher:publicperson{private:charprof[10];chardepart[10];public:voidinput(){person::input();cout<<"職稱:";cin>>prof;cout<<"部門:";cin>>depart;}voiddisp(){person::disp();cout<<"職稱:"<<prof<<endl;cout<<"部門:"<<depart<<endl;}};voidmain(){students1;teachert1;cout<<"輸入一個學生數(shù)據(jù):\n";s1.input();cout<<"輸入一個教師數(shù)據(jù):\n";t1.input();cout<<"顯示一個學生數(shù)據(jù):\n";s1.disp();cout<<"顯示一個教師數(shù)據(jù):\n";t1.disp();}2、程序內(nèi)容如下所示。#include<iostream.h>#include<string.h>classstring{intlength;char*contents;public:intget_length(){returnlength;}char*get_contents(){returncontents;}~string(){deletecontents;}intset_contents(intin_length,char*in_contents);intset_contents(char*in_contents);voidprint(){cout<<contents<<endl;}};classedit_string:publicstring{intcursor;public:intget_cursor_pos(){returncursor;}voidmove_cursor(inthow_much){cursor=how_much;}intadd_at_cursor(string*new_text);intrepl_at_cursor(string*new_text);voiddele_at_cursor(inthow_much);};intstring::set_contents(intin_length,char*in_contents){length=in_length;if(!contents)deletecontents;contents=newchar[length+1];strcpy(contents,in_contents);returnlength;}intstring::set_contents(char*in_contents){length=strlen(in_contents);if(!contents)deletecontents;contents=newchar[length+1];strcpy(contents,in_contents);returnlength;}intedit_string::add_at_cursor(string*new_text){intn,k,m;char*cp,*pt;n=new_text->get_length();pt=new_text->get_contents();cp=this->get_contents();m=this->get_length();char*news=newchar[m+n+1];for(inti=0;i<cursor;i++)news[i]=cp[i];k=i;for(intj=0;j<n;i++,j++)news[i]=pt[j];cursor=i;for(j=k;j<m;j++,i++)news[i]=cp[j];news[i]='\0';set_contents(news);deletenews;returncursor;}intedit_string::repl_at_cursor(string*new_text){intn,m;char*pt,*news;n=new_text->get_length();pt=new_text->get_contents();m=this->get_length();news=newchar[m>n+cursor?m+1:n+cursor+1];news=this->get_contents();for(inti=cursor,j=0;i<n+cursor;j++,i++)news[i]=pt[j];if(m<n+cursor)news[i]='\0';cursor=i;set_contents(news);deletenews;returncursor;}voidedit_string::dele_at_cursor(inthow_much){intm;char*cp,*news;cp=this->get_contents();m=this->get_length();for(inti=cursor;i<m;i++)cp[i]=cp[i+how_much];cp[i]='\0';}voidmain(){strings1;edit_strings2;char*cp;s1.set_contents("Object_OrientedProgramming");cp=s1.get_contents();s2.set_contents(cp);s2.print();s2.move_cursor(15);s1.set_contents("Windwos");s2.add_at_cursor(&s1);s2.print();s2.move_cursor(6);s2.dele_at_cursor(9);s2.print();s1.set_contents("TTT");s2.repl_at(yī)_cursor(&s1);s2.print();}3、程序內(nèi)容如下所示。#include<iostream.h>classvehicle{protected:intwheels;floatweight;public:vehicle(intwheels,floatweight);intget_wheels();floatget_weight();floatwheel_load();voidprint();};classcar:vehicle{intpassenger_load;public:car(intwheels,floatweight,intpassengers=4);intget_passengers();voidprint();};classtruck:vehicle{intpassenger_load;floatpayload;public:truck(intwheels,floatweight,intpassengers=2,floatmax_load=240000.00);intget_passengers();float(yī)efficiency();voidprint();};vehicle::vehicle(intwheels,floatweight){vehicle::wheels=wheels;vehicle::weight=weight;}intvehicle::get_wheels(){returnwheels;}floatvehicle::get_weight(){returnweight/wheels;}voidvehicle::print(){cout<<"車輪:"<<wheels<<"個。"<<endl;cout<<"重量:"<<wheels<<"公斤。"<<endl;}car::car(intwheels,floatweight,intpassengers):vehicle(wheels,weight){passenger_load=passengers;}intcar::get_passengers(){returnpassenger_load;}voidcar::print(){cout<<"小車:"<<endl;vehicle::print();cout<<"載人:"<<passenger_load<<"人。"<<endl;cout<<endl;}truck::truck(intwheels,floatweight,intpassengers,floatmax_load):vehicle(wheels,weight){passenger_load=passengers;payload=max_load;}inttruck::get_passengers(){returnpassenger_load;}float(yī)truck::efficiency(){returnpayload/(payload+weight);}voidtruck::print(){cout<<"卡車"<<endl;vehicle::print();cout<<"載人:"<<passenger_load<<"人。"<<endl;cout<<"效率:"<<efficiency()<<endl;cout<<endl;}voidmain(){carcar1(4,1000,5);trucktru1(10,5000,3,340000);car1.print();tru1.print();}4、程序內(nèi)容如下所示。#include<iostream.h>#include<string.h>classemployee{protected:intno;charname[10];floatsalary;public:employee(){cout<<"職工編號:";cin>>no;cout<<"職工姓名:";cin>>name;salary=0;}voidpay(){}voiddisplay(){}};classtechnician:publicemployee{privat(yī)e:floathourlyrate;intworkhours;public:technician(){hourlyrate=100;}voidpay(){cout<<name<<"本月工作時數(shù):";cin>>workhours;salary=hourlyrat(yī)e*workhours;}voiddisplay(){cout<<"兼職技術(shù)人員:"<<name<<"(編號為:"<<no\<<")"<<"本月工資:"<<salary<<endl;}};classsalesman:virtualpublicemployee{protected:floatcommrate;floatsales;public:salesman(){commrate=0.04;}voidpay(){cout<<name<<"本月銷售額:";cin>>sales;salary=sales*commrate;}voiddisplay(){cout<<"銷售員:"<<name<<"(編號為:"<<no<<")"<<"本月工資:"<<
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 大型游樂設(shè)施租賃合同樣本
- 商業(yè)綜合體地簧門改造合同
- 國內(nèi)海運貨物保險合同樣本
- 擔架使用培訓課件
- 壓力容器安全管理考核試卷
- 動物用藥品店面的環(huán)境設(shè)計與氛圍營造考核試卷
- 有機合成原料在綠色涂料技術(shù)的創(chuàng)新考核試卷
- 木材產(chǎn)品環(huán)保性能提升考核試卷
- 整流器在數(shù)據(jù)中心能源效率優(yōu)化考核試卷
- 智慧城市和自然資源的合理利用考核試卷
- 2025年湖南鐵路科技職業(yè)技術(shù)學院單招職業(yè)技能測試題庫參考答案
- 2022年四川省綿陽市中考化學試卷
- (完整版)微生物檢驗技術(shù)練習題(含答案)
- 佛山市內(nèi)戶口遷移申請表
- 《工程制圖完整》課件
- 常見焊接缺陷以及其處理方法PPT
- 《子宮脫垂護理查房》
- 關(guān)于對項目管理的獎懲制度
- A320主起落架收放原理分析及運動仿真
- 2. SHT 3543-2017施工過程文件表格
評論
0/150
提交評論