C_全國計算機二級真題(含上機題答案)_第1頁
C_全國計算機二級真題(含上機題答案)_第2頁
C_全國計算機二級真題(含上機題答案)_第3頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、百度文庫 - 讓每個人平等地提升自我vc+vc+ 全國計算機二級題庫全國計算機二級題庫第一套請使用vc6打開考生文件夾下的工程proj1,該工程含有一個源程序文件。其中每個注釋注意:只需要修改注釋 endl; endl; private:private:const int value;const int value;static int count;static int count; ;how();how();().show();().show();coutendl(),()endl;coutendl(),()endl;return 0;return 0; 第四套第四套請使用答題菜單或使用vc

2、6打開考生文件夾下的工程proj1,該工程含有一個源程序文件。其中每個注釋etx()-getdownright().getx()*etx()-getdownright().getx()*(getdownright().gety()-getupleft().gety();(getdownright().gety()-getupleft().gety(); int main( )int main( ) myrectangle r(mypoint(0,2),mypoint(2,0);myrectangle r(mypoint(0,2),mypoint(2,0);().show();().show()

3、;().show();().show();().show();().show();().show();().show();cout()endl;cout()endl;return 0;return 0; 第六套第六套請使用答題菜單或使用vc6打開考生文件夾下的工程proj1,該工程含有一個源程序文件。其中位于每個注釋1注意:只需修改注釋+countshow(); delete pb; return 0;請使用答題菜單或使用vc6打開考生目錄下的工程文件proj3, 此工程包含一個源程序文件,補充編制c+程序,其功能是從文本文件中讀取全部整數(shù),將整數(shù)序列存放到intarray類的對象myarra

4、y中。然后對整數(shù)序列按非遞減排序。最后由函數(shù)writetofile選擇序列中的部分?jǐn)?shù)據(jù)輸出到文件中。文件中的整數(shù)個數(shù)不大于300個。要求:補充編制的內(nèi)容寫在1979年5月10日注意:只需修改注釋endl; else coutsorryendl;int main()秒”的格式顯示時間 int c=(0); the value is 10 max number is 20 destructor called.注意:只需修改注釋 y ? x : y; endl; private: int value;int main() myclass obj(10);how(); writetofile(, li

5、st1+list2); return 0;第十六套第十六套請使用vc6打開考生文件夾下的工程proj1,該工程含有一個源程序文件。其中位于每個注釋 the value is 10 copy constructor called. the value is 10 destructor called. destructor called.注意:只需修改注釋 endl; endl;void print() cout the value is value endl; endl; private:int value;int main()myclass obj1;();myclass obj2(obj1)

6、;();return 0;請使用答題菜單或使用vc6打開考生文件夾下的工程proj2,該工程含有一個源程序文件,其中定義了sort類和insertsort類。sort是一個表示排序算法的抽象類,成員函數(shù)mysort為各種排序算法定義了統(tǒng)一的接口,成員函數(shù)swap實現(xiàn)了兩個整數(shù)的交換操作。insertsort是sort的派生類,它重新定義了基類中的成員函數(shù)mysort,具體實現(xiàn)了簡單插入排序法。本程序的正確輸出結(jié)果應(yīng)為:before sorting a=5, 1, 7, 3, 1, 6, 9, 4, 2, 8, 6,after sorting a=1, 1, 2, 3, 4, 5, 6, 6,

7、7, 8, 9,請首先閱讀程序,分析輸出結(jié)果,然后根據(jù)下列要求在橫線處填寫適當(dāng)?shù)拇a并刪除橫線。 (1) 將sort類的成員函數(shù)swap補充完整,實現(xiàn)兩個整數(shù)的交換操作; (2) 將insertsort類的構(gòu)造函數(shù)補充完整; (3) 將insertsort類的成員函數(shù)mysort補充完整,實現(xiàn)簡單插入排序法(在交換數(shù)據(jù)時,請使用基類的成員函數(shù) swap)。注意:只能在橫線處填寫適當(dāng)?shù)拇a,不要改動程序中的其他內(nèi)容,也不能刪除或移動. .private:private:char* m_str;char* m_str; ;2百度文庫 - 讓每個人平等地提升自我int main(int argc,

8、char *argv)int main(int argc, char *argv) mystring str1(abc), str2(defg);mystring str1(abc), str2(defg);cout before reverse: n;cout before reverse: n;();();();();();();();();cout after reverse: n;cout after reverse: n;();();();();return 0;return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj3。其中聲明了cdeepcopy 類,它是

9、一個用于表示動態(tài)數(shù)組的類。請編寫其中的拷貝構(gòu)造函數(shù)。要求:補充編制的內(nèi)容寫在ength() ;ength() ; double length2()const ength();double length2()const ength(); double length3()const ength();double length3()const ength(); double area()constdouble area()const double height()const ength();double height()const ength(); double lengthofdiagonal()

10、constdouble lengthofdiagonal()constength();ength(); ength();ength();double area()constdouble area()constthere is a motley dog named hihi.注意:只能修改每個endl;endl;there is a black dog named haha. ; ;int main()int main()注意:只能修改每個endl;endl; int main()int main()rectangle r1(1,8,5,2);rectangle r1(1,8,5,2);show

11、(r1);show(r1);3百度文庫 - 讓每個人平等地提升自我return 0;return 0; 請使用vc6打開考生文件夾下的工程proj2,其中定義了 employee類和manager類。employee用于表示某公司的雇員,其屬性包括姓名(name)和工作部門(dept)。manager是 employee的公有派生類,用于表示雇員中的經(jīng)理。除了姓名和工作部門之外,manager的屬性還包括級別(level)。employee類的成員函數(shù)print負(fù)責(zé)輸出雇員的信息;manager 類的成員函數(shù)print負(fù)責(zé)輸出經(jīng)理的信息。請在程序中的橫線處填寫適當(dāng)?shù)拇a,然后刪除橫線,以實現(xiàn)上

12、述類定義。此程序的正確輸出結(jié)果應(yīng)為:name: sally smithdept: saleslevel: 2注 意 : 只 能 在 橫 線 處 填 寫 適 當(dāng) 的 代 碼 , 不 要 改 動 程 序 中 的 其 他 內(nèi) 容 ,也 不 能 刪 除 或 移 動.str1 = 1str2 = 9要求:補充編制的內(nèi)容寫在.nn;.nn;ifstream infile(inname);ifstream infile(inname);if () if () cerr cerr 打開輸入文件失敗!打開輸入文件失?。? ;exit(1);exit(1); char buf4096;char buf4096;(

13、buf, 4096);(buf, 4096);mystring str1(dog), str2(the quick brown fox jumps over the lazy dog), str3(buf);mystring str1(dog), str2(the quick brown fox jumps over the lazy dog), str3(buf);();();cout str1 = () endl;cout str1 = () endl;cout str2 = () endl endl;cout str2 = () endl endl;writetofile(pathnam

14、e, ();writetofile(pathname, ();return 0;return 0; 第二十五套第二十五套請使用vc6打開考生文件夾下的工程proj1。程序中位于每個there are 1 objects.注意:只能修改每個 endl; endl;delete p;delete p;cout there are myclass:getcount() objects. endl;cout there are myclass:getcount() objects. endl;return 0;return 0; 請使用vc6打開考生文件夾下的工程proj2,其中定義了vehicle類

15、,并派生出motorcar類和bicycle類。然后以motocar和bicycle作為基類,再派生出motocycle類。要求將vehicle作為虛基類,避免二義性問題。請在程序中的橫線處填寫適當(dāng)?shù)拇a,然后刪除橫線,以實現(xiàn)上述類定義。此程序的正確輸出結(jié)果應(yīng)為:801501001注意:只能在橫線處填寫適當(dāng)?shù)拇a,不要改動程序中的其他內(nèi)容, 也不能刪除或移動my name is wang and my is .my name is li,i have 8 publications.4百度文庫 - 讓每個人平等地提升自我注意:只能在橫線處填寫適當(dāng)?shù)拇a,不要改動程序中的其他內(nèi)容, 也不能刪除或移

16、動n;n; void setname(char* s)void setname(char* s) name = new charstrlen(s)+1;name = new charstrlen(s)+1;strcpy(name, s);strcpy(name, s); protected:protected:char* name;char* name; ;class student : public personclass student : public personpublic:public:n;n; private:private:float gpa;float gpa; ;class

17、 professor : public personclass professor : public personpublic:public:void setpubls(int n)publs=n; void setpubls(int n)publs=n; void disp()void disp() cout my name is namecout my name is name,i have publs publications.n;i have publs publications.n; private:private:int publs;int publs; ;int main()in

18、t main() 1978 年 4 月 20 日 1965 年 9 月 3 日 1965 年 9 月 5 日 1973 年 5 月 30 日 1978 年 4 月 20 日 1973 年 5 月 30 日 1965 年 9月 5 日 1965 年 9 月 3 日how();how(); sortbyage(staff,size); sortbyage(staff,size); coutendlendl coutendlendl排序后:排序后:; ; for(i=0; isize; i+) staffi.show(); for(i=0; isize; i+) staffi.show(); cou

19、tendl; coutendl; writetofile(); writetofile(); return 0; return 0; 第三十套第三十套請使用答題菜單或使用 vc6 打開考生文件夾下的工程文件 proj1。 此工程中包括類 point、 函數(shù) fun 和主函數(shù) main。程序中位于每個how();how();();();().show();().show();();();().show();().show();coutendl;coutendl;return 0;return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj3,其中包含了類integers和主函

20、數(shù)main的定義。一個5百度文庫 - 讓每個人平等地提升自我integers對象就是一個整數(shù)的集合,其中包含0個或多個可重復(fù)的整數(shù)。成員函數(shù)add將一個元素添加到集合中,成員函數(shù)remove從集合中刪除指定的元素(如果集合中存在該元素),成員函數(shù)sort將集合中的整數(shù)按由小到大的次序進(jìn)行排序。請編寫這個sort函數(shù)。此程序的正確輸出結(jié)果應(yīng)為:5 28 2 4 5 3 2 75 27 66 315 28 2 4 5 3 2 75 27 66 31 65 28 2 4 5 3 2 75 27 66 31 6 195 28 2 4 5 3 75 27 66 31 6 195 28 2 4 5 3 7

21、5 27 66 31 6 19 42 3 4 4 5 5 6 19 27 28 31 66 75要求:補充編制的內(nèi)容寫在how();how();cout,(),perimeter(c),area(c)endl;cout,(),perimeter(c),area(c)endl;return 0;return 0; 第三十二套第三十二套請使用答題菜單或使用 vc6 打開考生文件夾下的工程文件 proj1。此工程包含程序文件,其中有類 tvset(電視機)和主函數(shù) main 的定義。程序中位于每個 29 英寸 29 英寸how();how();delete arrayp;delete arrayp;

22、writetofile();writetofile(); 第三十三套第三十三套請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj1。此工程包含程序文件,其中有類cdate(日期)和主函數(shù)main的定義。程序中位于每個2005-9-252006-4-11978年4月20日1965年8月3日1965年9月5日1973年5月30日1973年5月30日1965年8月3日1965年9月5日1978年4月20日how(); sortbyname(staff,size); coutendlendl排序后:; for(i=0; isize; i+) staffi.show(); coutendl;

23、return 0;請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj3,其中聲明了valarray類,該類在內(nèi)部維護(hù)一個動態(tài)分配的int型數(shù)組v。valarray類的成員函數(shù)cycle用于對數(shù)組元素進(jìn)行向左循環(huán)移動。調(diào)用一次cycle后,數(shù)組的第二個元素到最后一個元素都將向左移動一個位置, 而最左端元素將循環(huán)移動到最右端位置上。 例如, 若valarray表示的數(shù)組為1, 2, 3,4, 5,則第一次調(diào)用cycle后,數(shù)組變?yōu)?, 3, 4, 5, 1,第二次調(diào)用cycle后,數(shù)組變?yōu)?, 4, 5, 1, 2,依此類推。請編寫成員函數(shù)cycle。在main函數(shù)中給出了一組測試數(shù)據(jù),

24、此情況下程序的輸出應(yīng)該是:v = 1, 2, 3, 4, 5v = 2, 3, 4, 5, 1v = 3, 4, 5, 1, 2v = 4, 5, 1, 2, 3v = 5, 1, 2, 3, 4要求:補充編制的內(nèi)容寫在請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj1。此工程包含程序文件,其中有類door(門)和主函數(shù)main的定義。程序中位于每個.門是鎖著的,打不開。開503號門的鎖.鎖開了。打開503號門.門打開了。打開503號門.門是開著的,無需再開門。鎖上503號門.先關(guān)門.門鎖上了。注意:只能修改每個.;.;6百度文庫 - 讓每個人平等地提升自我if(!closed)i

25、f(!closed)coutcout門是開著的,無需再開門。門是開著的,無需再開門。; ;else if(locked)else if(locked)coutcout門是鎖著的,打不開。門是鎖著的,打不開。; ;elseelseclosed=false;closed=false;coutcout門打開了。門打開了。; ; void close()void close().;.;if(closed)if(closed)coutcout門是關(guān)著的,無需再關(guān)門。門是關(guān)著的,無需再關(guān)門。; ;elseelseclosed=true;closed=true;coutcout門關(guān)上了。門關(guān)上了。; ; v

26、oid lock()void lock().;.;if(locked)if(locked)coutcout門是鎖著的,無需再鎖門。門是鎖著的,無需再鎖門。; ;elseelse.;.;closed=true;closed=true; locked=true;locked=true;coutcout門鎖上了。門鎖上了。; ; void unlock()void unlock().;.;if(!locked)if(!locked)coutcout門沒有上鎖,無需再開鎖。門沒有上鎖,無需再開鎖。; ;elseelselocked=false;locked=false;coutcout鎖開了。鎖開了。

27、; ; ; ;int main()int main()door door(503);door door(503);();();();();();();();();();();return 0;return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj2。此工程包含一個程序文件,其中有類cpolygon(多邊形)、crectangle(矩形)、ctriangle(三角形)的定義。請在程序中的橫線處填寫適當(dāng)?shù)拇a,然后刪除橫線,以實現(xiàn)上述類定義。此程序的正確輸出結(jié)果應(yīng)為: 20 10注意:只能在橫線處填寫適當(dāng)?shù)拇a,不要改動程序中的其他內(nèi)容, 也不能刪除或移動請使用答題菜單或

28、7百度文庫 - 讓每個人平等地提升自我使用 vc6 打開考生文件夾下的工程文件 proj1,此工程包含程序文件,其中有類 book(書)和主函數(shù) main 的定義。程序中位于每個how();how();coutp2=;coutp2=;().show();().show();coutendl;coutendl;return 0;return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程文件proj3,其中聲明了intset類,該類是一個用于表示正整數(shù)集合的類。 intset的成員函數(shù)intersection的功能是求當(dāng)前集合與另一個集合的交集。 請完成成員函數(shù)intersection。

29、 在main函數(shù)中給出了一組測試數(shù)據(jù),此時程序的輸出應(yīng)該是:求交集前:1 2 3 5 8 102 8 9 11 30 56 67求交集后:1 2 3 5 8 102 8 9 11 30 56 672 8要求:補充編制的內(nèi)容寫n;n;writetofile();writetofile();return 0;return 0; 第四十三套第四十三套請使用答題菜單或使用 vc6 打開考生文件夾下的工程文件prog1。程序中位于每個etname()etname() cout cout辦公室:辦公室:().getoffice()endl;().getoffice()endl; int main()int

30、 main() department dept( department dept(人事處人事處,521);,521); staff zhang(0789, staff zhang(0789,張三張三,dept), li(0513,dept), li(0513,李四李四,dept);,dept);coutcout改換辦公室前:改換辦公室前:endl;endl; showstaff(zhang); showstaff(zhang); showstaff(li); showstaff(li); etclassid() etclassid(); ; cout cout教室:教室:getclass().

31、getclassroom()endl;getclass().getclassroom()endl; int main()int main() class cla(062113,521); class cla(062113,521); student zhang(0789, student zhang(0789,張三張三,cla), li(0513,cla), li(0513,李四李四,cla);,cla);coutcout改換教室前:改換教室前:endl;endl; showstudent(&zhang); showstudent(&zhang); showstudent(&a

32、mp;li); showstudent(&li);8在; ;百度文庫 - 讓每個人平等地提升自我.coef4中的系數(shù)依次為: 、 、 、 、 , 也即對于i次項, 其系數(shù)就保存在coefi中。 成員函數(shù)getvalue計算多項式的值,多項式中x的值由參數(shù)指定。請補充完成文件中成員函數(shù)getvalue的定義。此程序的正確輸出結(jié)果應(yīng)為:value of p1 when x= :value of p2 when x= :注意:只需在函數(shù)getvalue的0 m1 misbn: 1c+ primer is authored by lippman. isbn: 2注意:只需修改注釋isbn: i

33、sbnendl;isbn: isbnendl; int main()int main() book b1(1,programming with c+,hubbard); book b1(1,programming with c+,hubbard); book b2(2,c+ primer,lippman); book b2(2,c+ primer,lippman); coutthere are book:how_many() book(s): endl; coutthere are book:how_many() book(s): endl; (); (); (); (); return 0;

34、 return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程proj2,此工程包含程序文件,其中有類animal(動物)、類dog(狗)、類cat(貓)的定義和主函數(shù)main的定義。請在程序中的橫線處填寫適當(dāng)?shù)拇a,然后刪除橫線,以實現(xiàn)上述定義。此程序的正確輸出結(jié)果應(yīng)為:dog named lucky speaks woofcat named daisy speaks miaow注意:只能在橫線處填寫適當(dāng)?shù)拇a,不要改動程序中的其他內(nèi)容,也不能刪除或移動char*: stl powerinsert char* into ministring:string stl handling c

35、+ style.注意:只需在函數(shù) insert 的; ; char istr=stl power; char istr=stl power;9百度文庫 - 讓每個人平等地提升自我 cout initial strings:n; cout initial strings:n; cout ministring: mstr endl; cout ministring: mstr endl; cout char*: istr endl endl; cout char*: istr endl endl; cout insert char* into ministring:n; cout insert c

36、har* into ministring:n; (7, istr,4); (7, istr,4); cout mstr endl; cout mstr endl; writetofile(); writetofile(); return 0; return 0; 第五十五套第五十五套請使用答題菜單或使用vc6打開考生文件夾下的工程proj1文件。此工程中包括類date(日期)和主函數(shù)main的定義。程序中位于每個2006-1-12005-12-312005-12-312006-1-1.- 反轉(zhuǎn)前 -str1 = abcdefstr2 = abcdefg- 反轉(zhuǎn)后 -str1 = fedcbas

37、tr2 = gfedcba要求:補充編制的內(nèi)容寫在。輸出函數(shù) writetofile 已經(jīng)編譯為 obj 文件,并且在本程序中調(diào)用。#include #include #include #include using namespace std;using namespace std;class mystring class mystring public:public:mystring(const char* s)mystring(const char* s) str = new charstrlen(s) + 1;str = new charstrlen(s) + 1;strcpy(str,

38、 s);strcpy(str, s); mystring() delete str; mystring() delete str; void reverse();void reverse();friend ostream& operator (ostream &os, const mystring &mystr)friend ostream& operator (ostream &os, const mystring &mystr) os ;os ;return os;return os; private:private:char *str;ch

39、ar *str; ;void writetofile(char *, const mystring&);void writetofile(char *, const mystring&);#include #include #include #include 10百度文庫 - 讓每個人平等地提升自我void mystring:reverse()void mystring:reverse() ; ;sprintf(inname, %s, pathname) ;sprintf(inname, %s, pathname) ;cout cout 讀取輸入文件讀取輸入文件.nn;.nn;

40、ifstream infile(inname);ifstream infile(inname);if () if () cerr cerr 打開輸入文件失敗!打開輸入文件失敗!; ;exit(1);exit(1); char buf4096;char buf4096;(buf, 4096);(buf, 4096);mystring str1(abcdef), str2(abcdefg), str3(buf);mystring str1(abcdef), str2(abcdefg), str3(buf);cout -cout - 反轉(zhuǎn)前反轉(zhuǎn)前 -n;-n;cout str1 = str1 end

41、l;cout str1 = str1 endl;cout str2 = str2 endl endl;cout str2 = str2 endl endl;();();();();();();cout -cout - 反轉(zhuǎn)后反轉(zhuǎn)后 -n;-n;cout str1 = str1 endl;cout str1 = str1 endl;cout str2 = str2 endl endl;cout str2 = str2 endl endl;writetofile(pathname, str3);writetofile(pathname, str3);return 0;return 0; 第五十六套

42、第五十六套請使用答題菜單或使用vc6打開考生文件夾下的工程proj1。此工程包含程序文件。程序中位于每個1958年3月23日2001年11月5日2001年11月5日1958年3月23日2001年11月5日2001年11月5日運有4個樂章莫扎特的g小調(diào)第四十交響樂有4個樂章注意:只能修改每個運運,貝多芬貝多芬,4),4),s2(gs2(g 小調(diào)第四十交響樂小調(diào)第四十交響樂,莫扎特莫扎特,4);,4); (); (); (); (); return 0; return 0; 請使用答題菜單或使用vc6打開考生文件夾下的工程proj2,該工程含有一個源程序文件,其中定義了stack類和arrayst

43、ack類。請在程序中的橫線處填寫適當(dāng)?shù)拇a,然后刪除橫線。此程序的輸出結(jié)果為: c, b, a注意:只需在指定位置編寫適當(dāng)代碼,不要改動程序中的其他內(nèi)容,也不能刪除或移動.coef4中的系數(shù)依次為:、,也即對于i次項,其系數(shù)就保存在coefi中。作為成員函數(shù)重載的運算符+用于計算兩個多項式的和,并返回作為計算結(jié)果的那個多項式。請補充完成文件中重載運算符函數(shù)operator+的定義。此程序的正確輸出結(jié)果應(yīng)為:p1 + p2 的結(jié)果: 4+5p2 + p3 的結(jié)果: 5+4+3+2+1注意:只需在函數(shù) operator + 的ostring()endl;ostring()endl;11百度文庫 - 讓每個人平等地提升自我 coutp2 + p3 coutp2 + p3 的結(jié)果的結(jié)果: (poly2+poly3).tostring()endl;: (poly2+poly3).tostring()endl; writetofile(); writetofile(); return 0; return 0; 第五十九套第五十九套請 使 用 答 題 菜 單 或 使 用 vc6 打 開 考 生 文 件 夾 下 的 工 程 proj1

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論