電大C++語言程序設計期末考試試題及答案小抄參考
《電大C++語言程序設計期末考試試題及答案小抄參考》由會員分享,可在線閱讀,更多相關《電大C++語言程序設計期末考試試題及答案小抄參考(12頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、專業(yè)好文檔 C++語言程序設計 期末考試試題及答案 姓名 ____________ 學號 ____________ 班號 ___________ 題 號 一 二(1) 二(2) 三 總 分 成 績 一、填空 1.在類中必須聲明成員函數(shù)的 原型 ,成員函數(shù)的 實現(xiàn) 部分可以寫在類外。 2.如果需要在被調(diào)函數(shù)運行期間,改變主調(diào)函數(shù)中實參變量的值,則函數(shù)的形參應該是 引用 類型或 指針 類型。 3. 抽象 類只能作為基類使用,而不能聲明它的對象。 4
2、.進行函數(shù)重載時,被重載的同名函數(shù)如果都沒有用const修飾,則它們的形參 個數(shù) 或 類型 必須不同。 5.通過一個 常 對象只能調(diào)用它的常成員函數(shù),不能調(diào)用其他成員函數(shù)。 6.函數(shù)的遞歸調(diào)用是指函數(shù)直接或間接地調(diào)用 自身 。 7.拷貝構造函數(shù)的形參必須是 本類對象的引用 。 二、閱讀下列程序,寫出其運行時的輸出結果 如果程序運行時會出現(xiàn)錯誤,請簡要描述錯誤原因。 1.請在以下兩題中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。 (1)程序: - 12 - #include
3、 4、ic:
Derived1(int m=1):
Base("Base",m-1)
{ n=m; }
void output(void)
{ cout< 5、 }
};
int main()
{
Base B("Base Class",1);
Derived2 D;
B.output();
D.output();
}
運行結果:
1
Base Class
2
1
0
Base
(2)程序:
#include 6、;}
protected:
int i;
int j;
};
int main()
{
Samp *p;
p=new Samp[5];
if(!p)
{ cout<<"Allocation error\n";
return 1;
}
for(int j=0;j<5;j++)
p[j].Setij(j,j);
for(int k=0;k<5;k++)
cout<<"Muti["< 7、
Muti[0] is:0
Muti[1] is:1
Muti[2] is:4
Muti[3] is:9
Muti[4] is:16
Destroying..4
Destroying..3
Destroying..2
Destroying..1
Destroying..0
2.請在以下兩題中任選一題,該題得分即為本小題得分。如兩題都答,則取兩題得分之平均值為本小題得分。
(1)程序:
#include 8、=100);
int& Elem(int ndx);
void Display(void);
void Set(void);
~Vector(void);
protected:
int size;
int *buffer;
};
Vector::Vector(int s)
{
buffer=new int[size=s];
}
int& Vector::Elem(int ndx)
{
if(ndx<0||ndx>=size)
{
cout<<"error in index"< 9、l;
exit(1);
}
return buffer[ndx];
}
void Vector::Display(void)
{
for(int j=0; j 10、b(a);
a.Set();
b.Display();
}
運行結果:
1
2
3
4
5
6
7
8
9
10
最后出現(xiàn)錯誤信息,原因是:聲明對象b是進行的是淺拷貝,b與a共用同一個buffer,程序結束前調(diào)用析構函數(shù)時對同一內(nèi)存區(qū)進行了兩次釋放。
(2)程序:
#include 11、etAge( int age )
{ *itsAge=age; }
protected:
int * itsAge;
};
CAT::CAT()
{
itsAge=new int;
*itsAge=5;
}
CAT::~CAT()
{
delete itsAge;
itsAge=NULL;
}
int main()
{
CAT a;
cout<<"as age:"< 12、out<<"bs age:"< 13、 程序功能說明:從鍵盤讀入兩個分別按由小到大次序排列的整數(shù)序列,每個序列10個整數(shù),整數(shù)間以空白符分隔。用這兩個序列分別構造兩個單鏈表,每個鏈表有10個結點,結點的數(shù)據(jù)分別按由小到大次序排列。然后將兩個鏈表合成為一個新的鏈表,新鏈表的結點數(shù)據(jù)仍然按由小到大次序排列。最后按次序輸出合并后新鏈表各結點的數(shù)據(jù)。
程序運行結果如下,帶下劃線部分表示輸入內(nèi)容,其余是輸出內(nèi)容:
1 3 5 7 9 11 13 15 17 19
2 4 6 8 10 12 14 16 18 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
14、#include 15、 Node 16、int position; // 當前元素在表中的位置序號。由函數(shù)Reset使用
Node 17、 //(假設當前表為空)。被拷貝構造函數(shù)、operator=調(diào)用
public:
LinkedList(void); // 構造函數(shù)
LinkedList(const LinkedList 18、 int ListEmpty(void) const; //size為0時返回TRUE,否則返回FALSE
void Reset(int pos = 0); //將指針currPtr移動到序號為pos的節(jié)點,
//prevPtr相應移動,position記錄當前節(jié)點的序號
void Next(void); //使prevPtr和currPtr移動到下一個節(jié)點
int EndOfList(void) const; // currPtr等于NULL時返回TRUE, 否則返回FA 19、LSE
int CurrentPosition(void) const; //返回數(shù)據(jù)成員position
void InsertFront(const T& item); //在表頭插入一個數(shù)據(jù)域為item的節(jié)點
void InsertRear(const T& item); //在表尾添加一個數(shù)據(jù)域為item的節(jié)點
void InsertAt(const T& item); //在當前節(jié)點之前插入一個數(shù)據(jù)域為item的節(jié)點
void InsertAfter(const T& item); //在當前節(jié)點之后插入 20、一個數(shù)據(jù)域為item的節(jié)點
T DeleteFront(void); //刪除頭節(jié)點,釋放節(jié)點空間,更新prevPtr、currPtr和size
void DeleteAt(void); //刪除當前節(jié)點,釋放節(jié)點空間,更新prevPtr、currPtr和size
T& Data(void); // 返回對當前節(jié)點成員data的引用
void ClearList(void); // 清空鏈表:釋放所有節(jié)點的內(nèi)存空間。
};
//類實現(xiàn)部分略......
template 21、t(LinkedList 22、 { lc->InsertRear(lb->Data());
lb->DeleteAt();
}
}
while ( !la->ListEmpty() )
{
lc->InsertRear(la->Data());
la->DeleteAt();
}
while ( !lb->ListEmpty() )
{
lc->InsertRear(lb->Data());
lb->DeleteAt();
}
23、
}
int main()
{
LinkedList 24、
lb.Reset();
MergeList(&la, &lb, &lc);//合并鏈表
lc.Reset();
// 輸出各節(jié)點數(shù)據(jù),直到鏈表尾
while(!lc.EndOfList())
{
cout < 25、ed the courage to do it."
His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FAs celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.
CSKA general director Roman Babaev says the matter has been "exaggerated" by the Iv 26、orian and the British media.
Blatter, 77, said: "It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them.
"It is a nonsense to have matches played without spectators because it is against the spirit 27、of football and against the visiting team. It is all nonsense.
"We can do something better to fight racism and discrimination.
"This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football."
The (lack of) a 28、ir up there
Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.
"I am going to be at the match tomorrow and I have asked to meet 29、Yaya Toure," he told BBC Sport.
"For me its about how he felt and I would like to speak to him first to find out what his experience was."
Uefa hasopened disciplinary proceedings against CSKAfor the "racist behaviour of their fans" duringCitys 2-1 win.
Michel Platini, president of European footba 30、lls governing body, has also ordered an immediate investigation into the referees actions.
CSKA said they were "surprised and disappointed" by Toures complaint. In a statement the Russian side added: "We found no racist insults from fans of CSKA."
Baumgartner the disappointing news: Mission aborte 31、d.
The supersonic descent could happen as early as Sunda.
The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm -- winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move 32、through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratospher 33、e. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.
The balloon will slowly drift to the edge of space at 120,000 feet (
Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.
Below, the Earth become 34、s the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.
Skydiver preps for the big jump
When he jumps, he 35、is expected to reach the speed of sound -- 690 mph (1,110 kph) -- in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.
If he goes too fast or spins out of control, 36、he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).
In order to deploy this chute successfully, he will have to slow to 37、 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.
Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).
cause there
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 建筑施工重大危險源安全管理制度
- 安全培訓資料:典型建筑火災的防治基本原則與救援技術
- 企業(yè)雙重預防體系應知應會知識問答
- 8 各種煤礦安全考試試題
- 9 危險化學品經(jīng)營單位安全生產(chǎn)管理人員模擬考試題庫試卷附答案
- 加壓過濾機司機技術操作規(guī)程
- 樹脂砂混砂工藝知識總結
- XXXXX現(xiàn)場安全應急處置預案
- 某公司消防安全檢查制度總結
- 1 煤礦安全檢查工(中級)職業(yè)技能理論知識考核試題含答案
- 4.燃氣安全生產(chǎn)企業(yè)主要負責人模擬考試題庫試卷含答案
- 工段(班組)級安全檢查表
- D 氯化工藝作業(yè)模擬考試題庫試卷含答案-4
- 建筑起重司索信號工安全操作要點
- 實驗室計量常見的30個問問答題含解析