zoukankan      html  css  js  c++  java
  • 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
    ", val);
    }
    void CMyClassA::print() {
        printf("%d
    ", 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
    ", val);
    12 }
    13 void CMyClassA::print() {
    14     printf("%d
    ", 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
    ", val2);
    22     }
    23     void print() {
    24         printf("%d
    ", 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
    ", 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
    ", 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] != ''; i++) {
    16             name[i] = _name[i];
    17             len++;
    18         }
    19         name[len] = '';
    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

    注定失败的战争,也要拼尽全力去打赢它; 就算输,也要输得足够漂亮。
  • 相关阅读:
    gitLab、docker
    Spring源码分析
    Tomcat堆内存分析
    Kafka入门一
    Java NIO
    spring注解
    websocket即时通讯
    pycharm安装dlib库
    python+opencv人脸识别是否戴口罩
    2021年暑假周总结1
  • 原文地址:https://www.cnblogs.com/yalphait/p/8969555.html
Copyright © 2011-2022 走看看