首頁 >
可做奧鵬全部院校在線離線作業(yè)畢業(yè)論文QQ:3230981406 微信:aopopenfd777
發(fā)布時間:2020/4/17 0:24:43來源:admin瀏覽: 76 次
離線考核《C++程序設(shè)計(高起專)》滿分100分一、判斷題(請給正確的打“√”,錯誤的打 “w”并說明原因。每題4分,共20分。)1 2 3 4 5 6 7 1. 靜態(tài)的成員函數(shù)沒有隱含的this指針 ,所以它們只能訪問靜態(tài)的數(shù)據(jù)成員。( )2. 通過類對象可以訪問類中所有的成員。( )3. 構(gòu)造函數(shù)是可以被派生類繼承的。( )4. 構(gòu)造函數(shù)和析構(gòu)函數(shù)都可以是虛函數(shù)。( )5. 只有類中全部函數(shù)都為純虛函數(shù)時,該類才被稱為抽象類。( )二、簡答題(每小題5分,共20分。)1. 什么是封裝性?請舉例說明。2. 什么是函數(shù)重載和運(yùn)算符重載?為什么要使用重載?3. 拷貝構(gòu)造函數(shù)在哪幾種情況下被調(diào)用?4. 什么是類?什么是對象?對象與類的關(guān)系是什么?三、程序分析題(每小題10分,共40分。)1. 指出下面程序中的1處錯誤,并說明原因。#include<iostream.h> class Point{ int X,Y; public: Point( ){X=0;Y=0;} Point(int x=0,int y=0){X=x;Y=y;} void display( ){cout<<X<<","<<Y<<endl;} };void main(){ Point p; p.display();}答:2. 指出下面程序中的1處錯誤,并說明原因。#include<iostream.h>class CTest{public: CTest(){ x=20; }private: int x; friend void friend_f(CTest fri);};void friend_f(CTest fri) { fri.x=55; }void main(){ CTest c1,c2; c1.friend_f(c2);}答:3. 寫出下面程序的運(yùn)行結(jié)果。#include<iostream.h>class Test {private: int num;public: Test(int n=0){num=n;num++;} ~Test( ){cout<<”Destructor is active,number=”<<num<<endl;}};void main( ){ Test x[2]; cout<<”Exiting main”<<endl;}答:4. 寫出下面程序的運(yùn)行結(jié)果。#include<iostream.h>class Test{private: static int val; int a;public: static int func(); static void sfunc(Test &r);};int Test::val=20;int Test::func(){ val--; return val; }void Test::sfunc(Test &r){ r.a=25; cout<<"Result3="<<r.a; }void main(){ cout<<"Resultl="<<Test::func()<<endl; Test a; cout<<"Result2="<<a.func()<<endl; Test::sfunc(a);}答:四、完成程序題(每小題10分,共20分。)1. 請在橫線處填上適當(dāng)?shù)淖志?,以使程序完整?br/>#include <iostream.h>#include ″math.h″class Point { private:double X,Y;①____ ______Line;public:Point(double x=0, double y=0) { X=x; Y=y; }Point(Point &p){ X=p.X; Y=p.Y; }};class Line{private: Point p1,p2;public: Line(Point &xp1, Point &xp2): ②___ _______{} double GetLength();};double Line::GetLength() { double dx=p2.X-p1.X; double dy=p2.Y-p1.Y;return sqrt(dx*dx + dy*dy);}void main(){ Point p1,p2(3,4); Line L1(p1,p2); cout<<L1.GetLength()<<endl;}2. 設(shè)計一個立方體類Box,使它能計算并輸出立方體的體積和表面積。 要求: Box類包含三個私有數(shù)據(jù)成員:a(立方體邊長)、volume(體積)和area(表面積);Box類包含有構(gòu)造函數(shù)及seta()(設(shè)置立方體邊長)、getvolume()(計算體積)、getarea()(計算表面積)和disp()(輸出體積和表面積)。
桂林市學(xué)無憂教育咨詢有限公司 桂ICP備2021007704號-2
Copyright ? 2010-2024 技術(shù)支持:藍(lán)隊云