#include"Info.hpp"
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;
static int t = 0;
const int capacity = 100;
int main()
{
    vector<Info> audience_info_list;
    string nickname0, contact0, city0;
    int n;
    cout << "录入信息:\n\n" << left << setw(10) << "昵称" 
        <<setw(14) << "联系方式" 
        << setw(14) << "所在城市"
    << setw(14) << "参加人数" << endl;
    while (cin >> nickname0)
    {
        cin >> contact0 >> city0 >> n;
        if (t + n <= capacity)
        {
            Info tmp(nickname0, contact0, city0, n);
            audience_info_list.push_back(tmp);
            t += n;
            if (t == capacity)
                break;
        }
        else
        {
            cout << "对不起,只剩" << capacity - t << "个位置." << endl
                << "1.输入u,更新(update)预定信息" << endl
                << "2.输入q,退出预定" << endl
                << "你的选择:";
            char ch;
            cin >> ch;
            if (ch == 'u')
                cout << "请重新输入:" << endl;
            else
            {
                cout << endl;
                break;
            }
        }
    }
    cout << "截至目前,一共有" << t << "位听众预定参加。预定观众信息如下:" << endl;
    for (auto& list : audience_info_list)
        list.print();
    return 0;
}
#include<iostream>
#include<string>

using namespace std;

class Info
{
private:
    string nickname;
    string contact;
    string city;
    int n;
public:
    Info(string nickname0, string contact0, string city0, int n0) :nickname(nickname0), contact(contact0), city(city0), n(n0) {}
    void print() const {
        std::cout << "称呼:\t\t\t" << nickname << endl;
        std::cout << "联系方式:\t\t" << contact << endl;
        std::cout << "所在城市:\t\t" << city << endl;
        std::cout << "预定人数:\t\t" << n << endl;
    }
    ~Info() = default;

};

 

 

 

#include<iostream>
#include<string>
using namespace std;

class textcoder
{
public:
    textcoder(string text0){ text = text0;}
    string get_ciphertext();
    string get_deciphertext();
private:
    void encoder();
    void decoder();
    string text;
};
string textcoder::get_ciphertext(){
    encoder();
    return text;
}
string textcoder::get_deciphertext(){
    decoder();
    return text;
}
void textcoder::encoder(){
    for (int i = 0; i < text.length(); i++){
        if ((text[i] >= 'a' && text[i] <= 'u') || (text[i] >= 'A' && text[i] <= 'U')){
            text[i] += 5;
        }
        else if ((text[i] >= 'v' && text[i] <= 'z') || (text[i] >= 'V' && text[i] <= 'Z'))
{
            text[i] -= 21;
        }
    }
}

void textcoder::decoder()
{
    for (int i = 0; i < text.length(); i++)
    {
        if ((text[i] >= 'a' && text[i] <= 'e') || (text[i] >= 'A' && text[i] <= 'E'))
        {
            text[i] += 21;
        }
        else if ((text[i] >= 'f' && text[i] <= 'z') || (text[i] >= 'F' && text[i] <= 'Z'))
        {
            text[i] -= 5;
        }
    }
}

 

posted on 2022-10-23 20:44  胡嘉瑞  阅读(10)  评论(0)    收藏  举报