18.04.28 17年程設考試題


編程填空部分

A01:編程填空:統計動物數量

描述

代碼填空,使得程序能夠自動統計當前各種動物的數量

#include <iostream>
using namespace std;
// 在此處補充你的代碼
void print() {
    cout << Animal::number << " animals in the zoo, " << Dog::number << " of them are dogs, " << Cat::number << " of them are cats" << endl;
}

int main() {
    print();
    Dog d1, d2;
    Cat c1;
    print();
    Dog* d3 = new Dog();
    Animal* c2 = new Cat;
    Cat* c3 = new Cat;
    print();
    delete c3;
    delete c2;
    delete d3;
    print();
}

輸入

輸出

0 animals in the zoo, 0 of them are dogs, 0 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats
6 animals in the zoo, 3 of them are dogs, 3 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats樣例輸入

None

樣例輸出

0 animals in the zoo, 0 of them are dogs, 0 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats
6 animals in the zoo, 3 of them are dogs, 3 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats
 1 #include <iostream>
 2 using namespace std;
 3 class Animal {
 4 public:
 5     static int number;
 6     Animal() {
 7         number++;
 8     }
 9     Animal(Animal &a) {
10         number++;
11     }
12     virtual ~Animal() {
13         number--;
14     }
15 };
16 class Dog :public Animal {
17 public:
18     static int number;
19     Dog() {
20         number++;
21     }
22     Dog(Dog &a) {
23         number++;
24     }
25     ~Dog() {
26         number--;
27     }
28 };
29 class Cat :public Animal {
30 public:
31     static int number;
32     Cat() {
33         number++;
34     }
35     Cat(Cat &a) {
36         number++;
37     }
38     ~Cat() {
39         number--;
40     }
41 };
42 int Animal::number = 0, Dog::number = 0,Cat::number=0;
43 void print() {
44     cout << Animal::number << " animals in the zoo, " << Dog::number << " of them are dogs, " << Cat::number << " of them are cats" << endl;
45 }
46 
47 int main() {
48     print();
49     Dog d1, d2;
50     Cat c1;
51     print();
52     Dog* d3 = new Dog();
53     Animal* c2 = new Cat;
54     Cat* c3 = new Cat;
55     print();
56     delete c3;
57     delete c2;
58     delete d3;
59     print();
60 }
View Code

A02:編程填空:簡單的計算

描述

補充代碼,使程序按要求輸出 

#include <iostream>
using namespace std;
template <class T>
class Add{
public:
// 在此處補充你的代碼
};

int main(){
    double f;
    int n;
    while( cin >> f >> n) {
        
        Add<double> a1(f);
        Add<int> a2(n);
        double x,y;
        int p,q;
        cin >> x >> y >> p >> q;
        cout << a1(x, y) << endl;
        cout << a2(p, q) << endl;
    }
    return 0;
}

輸入

有若干組數據
每組數據三行
第一行是一個浮點數f和一個整數 n
第二行是兩個浮點數 x 和 y
第三行是兩個整數 p 和q

輸出

對每組數據
先輸出 x + y - f
再輸出 p + q - n樣例輸入

2.2 3
1.0 2.0
10 20
4.5 30
4.8 9.2
100 200

樣例輸出

0.8
27
9.5
270
 1 #include <iostream>
 2 using namespace std;
 3 template <class T>
 4 class Add{
 5 public:
 6 float minus;
 7     Add(float a) :minus(a) {}
 8     float operator ()(T x, T y) {
 9         return (float)(x + y) - minus;
10     }
11 };
12 
13 int main(){
14     double f;
15     int n;
16     while( cin >> f >> n) {
17         
18         Add<double> a1(f);
19         Add<int> a2(n);
20         double x,y;
21         int p,q;
22         cin >> x >> y >> p >> q;
23         cout << a1(x, y) << endl;
24         cout << a2(p, q) << endl;
25     }
26     return 0;
27 }
View Code

A04:編程填空:回調函數

描述

輸入x1 x2 x3 x4 x5 ,輸出y = x5^5 + x4^4 + x3^3 + x2^2 + x1^1 + 1的y的值

#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <map>
#include <set>

using namespace std;
class MyFunc
{
// 在此處補充你的代碼
};
int main()
{
    int n;
    cin >> n;
    while(n--) {
        vector<MyFunc> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(MyFunc(i+1));
        int ans = 1;
        for (int i = 0; i < 5; ++i)
        {
            int m;
            cin >> m;
            ans += v[i](m);
        }
        cout << ans <<endl;
    }
}

輸入

多組數據。第一行是數據組數 n
每組數據為一行,5個整數,x1 x2 x3 x4 x5。數值不大,不必考慮溢出

輸出

對每組數據,輸出一個整數y, y = x5^5 + x4^4 + x3^3 + x2^2 + x1^1 + 1

樣例輸入

2
2 2 2 2 2
1 1 1 1 1

樣例輸出

63
6
 1 #include <algorithm>
 2 #include <iostream>
 3 #include <stack>
 4 #include <queue>
 5 #include <vector>
 6 #include <cstring>
 7 #include <cstdlib>
 8 #include <string>
 9 #include <cmath>
10 #include <map>
11 #include <set>
12 
13 using namespace std;
14 class MyFunc
15 {
16 public:
17     int mult;
18     MyFunc(int i):mult(i){}
19     int operator()(int m) {
20         return pow(m, mult);
21     }
22 };
23 int main()
24 {
25     int n;
26     cin >> n;
27     while(n--) {
28         vector<MyFunc> v;
29         for (int i = 0; i < 5; ++i)
30             v.push_back(MyFunc(i+1));
31         int ans = 1;
32         for (int i = 0; i < 5; ++i)
33         {
34             int m;
35             cin >> m;
36             ans += v[i](m);
37         }
38         cout << ans <<endl;
39     }
40 }
View Code

A05:編程填空:二進制輸出

描述

給出一個int表示范圍內的正整數x,輸出其二進制表示。一共要輸出31位,不足處要補0。

#include <iostream>
#include <string>
using namespace std;
string dec2bin(int x){
// 在此處補充你的代碼
}
int main(){
    int n;
    cin >> n;
    while(n--) {
        int x;
        cin >> x;
        cout << dec2bin(x) << endl;
    }
    return 0;
}

輸入

第一行是整數n(n<15),表示有n個正整數要處理
第二行是n個正整數

輸出

對每個給出的正整數,輸出其二進制表示。不足31位則用0補齊到31位樣例輸入

3
1 2 3

樣例輸出

0000000000000000000000000000001
0000000000000000000000000000010
0000000000000000000000000000011
 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 string dec2bin(int x){
 5     string bina = "";
 6     while (x != 0) {
 7         bina += to_string(x % 2);
 8         x /= 2;
 9     }
10     while (bina.length() < 31) {
11         bina += to_string(0);
12     }
13     string b = "";
14     b.resize(31);
15     for (int i = 0; i <= 30; i++) {
16         b[i] = bina[30 - i];
17     }
18     return b;
19 }
20 int main(){
21     int n;
22     cin >> n;
23     while(n--) {
24         int x;
25         cin >> x;
26         cout << dec2bin(x) << endl;
27     }
28     return 0;
29 }
View Code

這道!我當時想的是二進制數一定是32位的,31位是從0開始數的……然后調了很久

雖然是我自己的問題但我覺得還是很坑

A06:編程填空:去除重復元素排序

描述

程序填空,使其按要求輸出

#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <stack>
#include <iostream>
#include <set>
using namespace std;

int main() {
    int t;
    int  a[100];
    cin >> t;
    while(t--) {
        for(int i = 0;i < 12; ++i)
            cin >> a[i];
// 在此處補充你的代碼
std::copy(b.begin(), b.end(), c);
        cout << endl;

    }
    return 0;
}

輸入

第一行是個整數,表示輸入數據組數 
每組數據一行,有12個整數

輸出

對每組數據, 將12個整數從小到大排序並去除重復元素后輸出樣例輸入

2
34 5 4 6 3 9 8 34 5 3 3 18
31 2 4 6 2 9 8 31 5 3 3 18

樣例輸出

3 4 5 6 8 9 18 34 
2 3 4 5 6 8 9 18 31 

提示注意:行末都有一個空格

A07:編程填空:還是Fun和Do

描述

填寫代碼,使輸出結果為
A::Fun
B::Do
C::Fun
C::Do
A::Fun
B::Do

#include <iostream> 
using namespace std;

class A { 
    public: 
        virtual void Fun() { 
            cout << "A::Fun" << endl; 
        }; 
        virtual void Do() { 
            cout << "A::Do" << endl; 
        } 
};
// 在此處補充你的代碼
{ 
    p.Fun(); 
    p.Do(); 
} 

void Call2(B p) {
    p.Fun();
    p.Do();
}



int main() { 
    C c;
    B b;
    Call1(b);
    Call1(c); 
    Call2(c);
    return 0;
}

 

輸入

輸出

A::Fun
B::Do
C::Fun
C::Do
A::Fun
B::Do樣例輸入

None

樣例輸出

A::Fun
B::Do
C::Fun
C::Do
A::Fun
B::Do
 1 #include <iostream> 
 2 using namespace std;
 3 
 4 class A { 
 5     public: 
 6         virtual void Fun() { 
 7             cout << "A::Fun" << endl; 
 8         }; 
 9         virtual void Do() { 
10             cout << "A::Do" << endl; 
11         } 
12 };
13 class B:public A {
14 public:
15     void Do() {
16         cout << "B::Do" << endl;
17     }
18 };
19 class C:public B {
20 public:
21     void Do() {
22         cout << "C::Do" << endl;
23     }
24     void Fun() {
25         cout << "C::Fun" << endl;
26     };
27 };
28 void Call1(A &p)
29 { 
30     p.Fun(); 
31     p.Do(); 
32 } 
33 
34 void Call2(B p) {
35     p.Fun();
36     p.Do();
37 }
38 
39 
40 
41 int main() { 
42     C c;
43     B b;
44     Call1(b);
45     Call1(c); 
46     Call2(c);
47     return 0;
48 }
View Code

A08:編程填空:Printer

描述

完成以下程序,使得輸入的整數x,以及若干正整數,將
大於x的正整數輸出;然后輸入若干字符串,將字符串長度大於x的字符串輸出

#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>

using namespace std;


class Printer{
// 在此處補充你的代碼
int main(){

    int t;
    cin >> t;
    while(t--) {
        int n,x;
        cin>>x>>n;
        
        vector<int> intVec;
        for(int i = 0;i < n; ++i) {
            int y;
            cin >> y;
            intVec.push_back(y);
        }
        for_each(intVec.begin(), intVec.end(), Printer(x));
        cout<<endl;
        
        vector<string> strVec;
        for(int i = 0;i < n; ++i) {
            string str;
            cin >> str;
            strVec.push_back(str);
        }
        for_each(strVec.begin(), strVec.end(), Printer(x));
        cout<<endl;
    }
    return 0;
}

輸入

第一行是整數t,表示一共t組數據
每組數據有三行 
第一行是整數x和整數 n 
第二行是n個整數 
第三行是n個不帶空格的字符串

輸出

對每組數據
先按原序輸出第一行中大於x的正整數(數據保證會有輸出) 
再按原序輸出第二行中長度大於x的字符串 (數據保證會有輸出)樣例輸入

2
5 6
1 3 59 30 2 40
this is hello please me ha
1 1
4
this

樣例輸出

59,30,40,
please,
4,
this,
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<vector>
 4 #include<bitset>
 5 
 6 using namespace std;
 7 
 8 
 9 class Printer{
10 public:
11     int x;
12     Printer(int _x):x(_x){}
13     void operator()(int a) {
14         if (a > x)
15             cout << a << ",";
16     }
17     void operator()(string a) {
18         if (a.length() > x)
19             cout << a << ",";
20     }
21 };
22 int main(){
23 
24     int t;
25     cin >> t;
26     while(t--) {
27         int n,x;
28         cin>>x>>n;
29         
30         vector<int> intVec;
31         for(int i = 0;i < n; ++i) {
32             int y;
33             cin >> y;
34             intVec.push_back(y);
35         }
36         for_each(intVec.begin(), intVec.end(), Printer(x));
37         cout<<endl;
38         
39         vector<string> strVec;
40         for(int i = 0;i < n; ++i) {
41             string str;
42             cin >> str;
43             strVec.push_back(str);
44         }
45         for_each(strVec.begin(), strVec.end(), Printer(x));
46         cout<<endl;
47     }
48     return 0;
49 }
View Code

A09:編程填空:前K大的偶數描述

輸入

n個整數,輸出整數數列中大小排名前k的偶數

#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <map>
#include <set>

using namespace std;
class MyQueue
{
// 在此處補充你的代碼
};
int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n, k;
        cin >> n >> k;
        MyQueue q(k);
        for (int i = 0; i < n; ++i)
            cin >> q;
        cout<<q;
        cout << endl;
    }
    return 0; 
}

輸入

有多組數據
第一行是數據組數 t
對每組數據: 
第一行為整數n (n>=3)和k
接下來的一行為n個整數,保證這些整數中至少有k個偶數。

輸出

對每組數據,輸出k個整數,降序排列,表示選出來的大小排名前k的偶數樣例輸入

2
9 4
1 2 4 3 6 6 7 8 9
3 2
18 16 14

樣例輸出

8 6 6 4
18 16
 1 #include <algorithm>
 2 #include <iostream>
 3 #include <stack>
 4 #include <queue>
 5 #include <vector>
 6 #include <cstring>
 7 #include <cstdlib>
 8 #include <string>
 9 #include <map>
10 #include <set>
11 
12 using namespace std;
13 class MyQueue
14 {
15 public:
16     int k;
17     multiset<int, greater<int>> que;
18     MyQueue(int _k):k(_k){}
19     friend istream & operator>>(istream&is, MyQueue &a) {
20         int l;
21         is >> l;
22         if (l % 2 == 0)a.que.insert(l);
23         return is;
24     }
25     friend ostream & operator <<(ostream&os, MyQueue &a) {
26         multiset<int>::iterator p=a.que.begin();
27         int count = 0;
28         for (;count<=a.k-1; p++) {
29             if (count)os << " ";
30             os << *p ;
31             count++;
32         }
33         return os;
34     }
35 };
36 int main()
37 {
38     int t;
39     cin >> t;
40     while(t--) {
41         int n, k;
42         cin >> n >> k;
43         MyQueue q(k);
44         for (int i = 0; i < n; ++i)
45             cin >> q;
46         cout<<q;
47         cout << endl;
48     }
49     return 0; 
50 }
View Code

A10:編程填空:MyClass

描述

補充下列代碼,使得程序的輸出為:
A:3
A:15
B:5
3
15
5

#include <iostream>
using namespace std;
class CMyClassA {
    int val;
public:
    CMyClassA(int);
    void virtual print();
};
CMyClassA::CMyClassA(int arg) {
    val = arg;
    printf("A:%d\n", val);
}
void CMyClassA::print() {
    printf("%d\n", val);
    return;
}
// 在此處補充你的代碼
int main(int argc, char** argv) {
    CMyClassA a(3), *ptr;
    CMyClassB b(5);
    ptr = &a; ptr->print();
    a = b;
    a.print();
    ptr = &b; ptr->print();
    return 0;
}

輸入

輸出

見樣例

樣例輸入

None

樣例輸出

A:3
A:15
B:5
3
15
5
 1 #include <iostream>
 2 using namespace std;
 3 class CMyClassA {
 4     int val;
 5 public:
 6     CMyClassA(int);
 7     void virtual print();
 8 };
 9 CMyClassA::CMyClassA(int arg) {
10     val = arg;
11     printf("A:%d\n", val);
12 }
13 void CMyClassA::print() {
14     printf("%d\n", val);
15     return;
16 }
17 class CMyClassB :public CMyClassA {
18 public:
19     int val2;
20     CMyClassB(int x) :CMyClassA(3 * x), val2(x) {
21         printf("B:%d\n", val2);
22     }
23     void print() {
24         printf("%d\n", val2);
25     }
26 };
27 int main(int argc, char** argv) {
28     CMyClassA a(3), *ptr;
29     CMyClassB b(5);
30     ptr = &a; ptr->print();
31     a = b;
32     a.print();
33     ptr = &b; ptr->print();
34     return 0;
35 }
View Code

A11:編程填空:又是MyClass

描述

補充下列代碼,使得程序能夠按要求輸出

#include <iostream>
#include <cstring> 
#include <vector>
#include <cstdio> 
using namespace std;
// 在此處補充你的代碼
int  a[40];
int main(int argc, char** argv) {
    int t;
    scanf("%d",&t);
    while ( t -- ) {
        int m;
        scanf("%d",&m);
        for (int i = 0;i < m; ++i) 
            scanf("%d",a+i);
        char s[100];
        scanf("%s",s);
        CMyClass<int> b(a, m);
        CMyClass<char> c(s, strlen(s));
        printf("%d %c\n", b[5], c[7]);
    }
    return 0;
}

輸入

第一行是整數t表示數據組數 
每組數據有兩行 
第一行開頭是整數m,然后后面是m個整數(5 < m < 30)
第二行是一個沒有空格的字符串,長度不超過50

輸出

對每組數據 先輸出m個整數中的第5個,然后輸出字符串中的第7個字符。
"第i個"中的 i 是從0開始算的。樣例輸入

1
6 1 3 5 5095 8 8
helloworld

樣例輸出

8 r
 1 #include <iostream>
 2 #include <cstring> 
 3 #include <vector>
 4 #include <cstdio> 
 5 using namespace std;
 6 template<class T>
 7 class CMyClass {
 8 public:
 9     T *p;
10     CMyClass(T*s, int wid) {
11         p = new T[wid];
12         for (int i = 0; i < wid; i++) {
13             p[i] = *s;
14             s++;
15         }
16     }
17     T operator[](int x) {
18         return *(p + x);
19     }
20 };
21 int  a[40];
22 int main(int argc, char** argv) {
23     int t;
24     scanf("%d",&t);
25     while ( t -- ) {
26         int m;
27         scanf("%d",&m);
28         for (int i = 0;i < m; ++i) 
29             scanf("%d",a+i);
30         char s[100];
31         scanf("%s",s);
32         CMyClass<int> b(a, m);
33         CMyClass<char> c(s, strlen(s));
34         printf("%d %c\n", b[5], c[7]);
35     }
36     return 0;
37 }
View Code

A12:編程填空:簡單的對象

描述

程序填空,使得程序輸出:
2
1
1
0

#include <iostream>
using namespace std;
class A
{
    static int num;
public:
    A(){num+=1;}
    void func()
    {
        cout<< num <<endl;
    }
// 在此處補充你的代碼
};

int A::num=1;

int main()
{
    A a1;
    const A a2 = a1;
    A & a3 = a1;
    const A & a4 = a1;

    a1.func();
    a2.func();
    a3.func();
    a4.func();

    return 0;
}

輸入

輸出

2
1
1
0

樣例輸入

None

樣例輸出

2
1
1
0
 1 #include <iostream>
 2 using namespace std;
 3 class A
 4 {
 5     static int num;
 6 public:
 7     A(){num+=1;}
 8     void func()
 9     {
10         cout<< num <<endl;
11     }
12     void func()const {
13         num--;
14         cout << num << endl;
15     }
16 };
17 
18 int A::num=1;
19 
20 int main()
21 {
22     A a1;
23     const A a2 = a1;
24     A & a3 = a1;
25     const A & a4 = a1;
26 
27     a1.func();
28     a2.func();
29     a3.func();
30     a4.func();
31 
32     return 0;
33 }
View Code

A13:編程填空:三生三世

描述

近年來,國內電視劇吸引了越來越多的關注;有的以當紅的演員陣容而吸引觀眾,比如《三生三世十里桃花》(Life After Life,Blooms Over Blooms);有的以貼近時代的劇情而備受關注,比如《人民的名義》(In the Name of People);有的則以精湛的演技贏得觀眾的喜歡,比如《大明王朝:1566》(Ming Dynasty: 1566)。
你的任務是根據電視劇的不同屬性(演員、劇情和演技)對電視劇進行排行。

#include<iostream>
#include<cstring>
#include<list>
#include<algorithm>
using namespace std;

class TV_Drama{
    public:
    char name[100];
    int actor;
    int story;
    int acting_skill;
// 在此處補充你的代碼
int main(){
    list<TV_Drama> lst;
    int n;
    
    cin>>n;
    char  _name[100];
    int _actor, _story, _acting_skill;
    for (int i=0; i<n; i++){
        cin.ignore();
        cin.getline(_name,100);
        cin>>_actor>>_story>>_acting_skill;
        lst.push_back(TV_Drama(_name, _actor, _story, _acting_skill));
    }

    lst.sort();
    for_each(lst.begin(), lst.end(), Printer);    
    cout<<endl;

    lst.sort(comparator_1);
    for_each(lst.begin(), lst.end(), Printer);    
    cout<<endl;

    lst.sort(comparator_2());
    for_each(lst.begin(), lst.end(), Printer);    
    cout<<endl;

    return 0;
}

輸入

首先輸入整數n,代表電視劇的個數。接下來,對於每個電視劇有兩行輸入:第一行一個字符串(可能含有空格,逗號,冒號等標點符號)作為電視劇的名字;第二行包括三個整數,分別為演員陣容、劇情和演技的評分。

輸出

輸出包括三行,分別為電視劇按演員陣容、劇情和演技的排行榜(評分由高到低),電視劇名字之間以分號隔開樣例輸入

3
In the Name of People
98 97 99
Life After Life, Blooms Over Blooms
99 82 73
Ming Dynasty: 1566
97 100 100

樣例輸出

Life After Life, Blooms Over Blooms;In the Name of People;Ming Dynasty: 1566;
Ming Dynasty: 1566;In the Name of People;Life After Life, Blooms Over Blooms;
Ming Dynasty: 1566;In the Name of People;Life After Life, Blooms Over Blooms;
 1 #include<iostream>
 2 #include<cstring>
 3 #include<list>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 class TV_Drama{
 8     public:
 9     char name[100];
10     int actor;
11     int story;
12     int acting_skill;
13 TV_Drama(char *_name, int _actor, int _story, int _ac) :actor(_actor), story(_story), acting_skill(_ac) {
14         int len = 0;
15         for (int i = 0; _name[i] != '\0'; i++) {
16             name[i] = _name[i];
17             len++;
18         }
19         name[len] = '\0';
20     }
21     bool operator<(TV_Drama&l) {
22         return actor > l.actor;
23     }
24 };
25 void Printer(TV_Drama x) {
26     cout << x.name << ";";
27 }
28 bool comparator_1(TV_Drama &x1,TV_Drama &x2) {
29     return x1.story > x2.story;
30 }
31 class comparator_2{
32 public:
33     comparator_2() {}
34     bool operator() (TV_Drama &x1, TV_Drama &x2) {
35         return x1.acting_skill > x2.acting_skill;
36     }
37 };
38 int main(){
39     list<TV_Drama> lst;
40     int n;
41     
42     cin>>n;
43     char  _name[100];
44     int _actor, _story, _acting_skill;
45     for (int i=0; i<n; i++){
46         cin.ignore();
47         cin.getline(_name,100);
48         cin>>_actor>>_story>>_acting_skill;
49         lst.push_back(TV_Drama(_name, _actor, _story, _acting_skill));
50     }
51 
52     lst.sort();
53     for_each(lst.begin(), lst.end(), Printer);    
54     cout<<endl;
55 
56     lst.sort(comparator_1);
57     for_each(lst.begin(), lst.end(), Printer);    
58     cout<<endl;
59 
60     lst.sort(comparator_2());
61     for_each(lst.begin(), lst.end(), Printer);    
62     cout<<endl;
63 
64     return 0;
65 }
View Code

選擇題部分

關於復制構造函數,下列說法正確的是
A. 系統不會生成缺省復制構造函數,因此必須自己實現
B. 復制構造函數是形如X::X(X)的函數
C. Myclass c1, c2; c1.n = 1; c2 = c1;第三句將會調用復制構造函數
D. 調用函數A Func(){A a(4); return a;}時,將會調用A的復制構造函數

//D

關於虛函數,下列說法不正確的是
A. 不允許以虛函數作為構造函數
B. 沒有虛函數便無法實現多態
C. 一般來講,如果一個類中定義了虛函數,則不可將析構函數也定義為虛函數
D. 不能用抽象類定義對象

//C

下列類模板不支持迭代器的是
A. stack
B. vector
C. list
D. set

//A

關於this指針,以下說法不正確的是
A. static成員函數內部不可以使用this指針 
B. 在構造函數內部可以使用this指針 
C. 在析構函數內部可以使用this指針
D. const成員函數內部不可以使用this指針  

//D

將一個對象放入STL中的容器里時,以下說法正確的是 
A. 實際上被放入的是該對象的指針 
B. 實際上被放入的是該對象的一個拷貝(副本) 
C. 實際上被放入的是該對象的引用 
D. 實際上被放入的就是該對象自身

//B

關於順序容器迭代器的操作,不正確的是

A. vector<int>::iterator iter1, iter2; iter1<iter2;
B.list<int>::iterator iter1, iter2; iter1<iter2;
C. vector<int>::iterator iter1; iter1-=3;
D. deque<int>::iterator iter1; iter1+=5;

//B

map的每個元素包括KEY(first)和VALUE(second)。關於map容器,下列哪種說法錯誤
A. map支持下標運算符
B. map的不同元素可以有相同的VALUE 
C. map支持STL的sort算法
D. map支持雙向迭代器

//C

下列哪個運算符可以被重載
A. ->
B. ?:
C. .
D. ::

//A

關於類的static成員函數,下列哪個說法正確
A. static成員函數中,可以訪問當前類的virtual成員函數
B. static成員函數中,可以訪問父類的private成員函數
C. static成員函數中,不允許調用當前類的非const成員函數
D. static成員函數中,不允許使用this指針 

//D

下列說法錯誤的是
A. 可以在一個類的友元函數中使用this指針
B. 每個類只有一個析構函數
C. 抽象類至少包含一個純虛函數
D. 構造函數不可以是virtual函數

//A

下列說法正確的是
A. 每個類至少有兩個構造函數
B. 構造函數的返回值必須是void類型的
C. 有可能通過基類的指針調用派生類的virtual函數
D. C++語法不允許派生類的成員變量和基類的成員變量同名

//C

下列關於運算符重載的描述中,正確的是: 
A. 運算符只能被重載一次
B. 流插入運算符“<<”可以是類的友元函數
C. 所有的運算符可以被重載為普通函數,也可以重載為成員函數
D. 運算符重載可以改變運算符的優先級

//B

關於繼承和派生的描述中,下列說法錯誤的是:
A. 派生類的成員函數中,不能訪問基類的private成員
B. 在派生類的析構函數執行之前,會先調用基類的析構函數
C. 派生類對象的地址可以賦值給基類指針
D. 派生類可以有和基類同名同參數的成員函數

//B

以下哪種使用std::sort算法的方式是不合法的: 
A. vector<int<int> a; …; sort(a.begin(), a.end());
B. bool b[99]; …; sort(b, b + 99);
C. string c = “2333”; …; sort(c.begin(), c.end());
D. listd; …; sort(d.begin(), d.end());

//D

類A重載的運算符聲明是int operator<(A &other) const,那么以下說法中正確的是
A. 小於號左側的A對象不可以是const的
B. 小於號右側的A對象不可以是const的
C. 這個寫法是錯誤的,因為小於號的返回類型必須是bool
D. 使用小於號的時候,other參數處,傳進來的對象實際上會被復制一次

//B

系統在調用重載函數時,往往根據一些條件確定哪個重載函數被調用,在下列選項中,不能作為依據的是
A. 參數個數 
B. 參數的類型
C. 函數的返回值的類型
D. 函數名稱

//C

關於構造函數,下列選項錯誤的是
A. 構造函數可以是虛函數 
B. 構造函數的參數可以有缺省值
C. 定義了構造函數,則編譯器不生成默認的無參數的構造函數
D. 構造函數不能繼承

//A

以下順序容器不支持隨機訪問迭代器的是
A. vector
B. deque
C. list
D. 以上容器都支持

//C

以下STL中的函數模板哪個可以作用於set
A. sort
B. random_shuffle
C. find
D. 都不行

//C

以下關於多態的說法哪個不正確
A. 在成員函數中調用虛函數,是多態
B. 通過“基類對象名.函數名”的方式調用虛函數,不是多態
C. 多態的函數調用語句中,函數一定是虛函數
D. 通過“基類引用名.函數名”的方式調用虛函數,是多態

//A

    題好多……原以為能在十分鍾排完的……所以可能排的時候並不認真,也許選擇題部分會有錯誤

 做了一遍發現基本上知識點全忘了(x


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM