数组,指针与现代c++标准

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

class Info
{

public:
    Info(string nickname, string contact, string city, int n)
        : nickname{nickname}, contact{contact}, city{city}, n{n} { cnt += n; }

    void print()
    {
        cout << "昵称: " << nickname << endl
             << "联系方式: " << contact << endl
             << "所在城市: " << city << endl
             << "预定人数: " << n << endl
             << endl;
    }

    static int getResult()
    {
        return cnt;
    }

    static const int capacity;
    

private:
    string nickname;
    string contact;
    string city;
    int n;
    static int cnt;
};

int Info::cnt = 0;
const int Info::capacity = 100;

  

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include "Info.hpp"

using namespace std;

vector<Info> audience_info_list;
string nickname;
string contact;
string city;
int n;

int main()
{

    cout << "录入信息:" << endl;
    cout << "昵称" << "       ";
    cout << "联系方式(邮箱/手机号)" << "      ";
    cout << "所在城市" << "       ";
    cout << "预定参加人数" << endl;

    while (cin >> nickname)
    {
        cin >> contact >> city >> n;
        bool flag = true;

        while (n + Info::getResult() > Info::capacity)
        {
            cout << "对不起,只剩" << Info::capacity - Info::getResult() << "个位置" << endl;
            cout << "1.输入u,更新(updata)预订信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            cout << "你的选择:";

            char str;
            cin >> str;

            if (str == 'q')
            {
                flag = false;
                break;
            }
            else
            {
                cout << "更新预定人数:";
                cin >> n;
            }
        }

        if (flag)
        {
            audience_info_list.push_back(Info(nickname, contact, city, n));
            cout << "预定成功 ~ " << endl;
        }
    }

    cout << "截止目前,一共有" << Info::getResult() << "位听众预定参加。预定听众信息如下:" << endl;

    for (auto &now : audience_info_list)
    {
        now.print();
    }

    return 0;
}

  

#include <bits/stdc++.h>

using namespace std;

class TextCoder
{

public:
    TextCoder(string a = "") : text{a} {}

    string get_ciphertext()
    {
        encoder_kaisa();
        return text;
    }

    string get_deciphertext()
    {
        decoder_kaisa();
        return text;
    }

private:
    string text;

    void encoder_kaisa(int position = 5)
    {
        for (auto &ch : text)
        {
            char str;
            if ('a' <= ch && ch <= 'z')
                str = 'a';
            else if ('A' <= ch && ch <= 'Z')
                str = 'A';
            else
                continue;
            ch = str + (ch - str + position + 52) % 26;
        }
    }

    void decoder_kaisa()
    {
        encoder_kaisa(-5);
    }
};

  

#include "textcoder.hpp"
#include <iostream>
#include <string>
void test()
{
    using namespace std;
    string text, encoded_text, decoded_text;
    cout << "输入英文文本: ";
    while (getline(cin, text))
    {
        encoded_text = TextCoder(text).get_ciphertext(); // 这里使用的是临时无名对象
        cout << "加密后英文文本:\t" << encoded_text << endl;
        decoded_text = TextCoder(encoded_text).get_deciphertext(); // 这里使用的是临时无名对象
        cout << "解密后英文文本:\t" << decoded_text << endl;
        cout << "\n输入英文文本: ";
    }
}
int main()
{
    test();
}

  

 

posted on 2022-10-23 00:47  cflxl  阅读(8)  评论(0编辑  收藏  举报

导航