实验三

#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;

class info {
public:
    info(string n1, string c1, string c2, int n2)
    {
        nickname=n1;
        contact=c1;
        city=c2;
        n=n2;
    }
    void print()
    {
        cout << "昵称:         " << nickname << endl;
        cout << "联系方式:     " << contact << endl;
        cout << "所在城市:     " << city << endl;
        cout << "预定参加人数: " << n << endl;
}
private:
    string nickname;
    string contact;
    string city;
    int n;
};
int main()
{
    const int capacity=100;
    vector<info> audience_info_list;
    cout << "录入信息:" << endl << endl;
    cout << "昵称        " << "联系方式(邮箱/手机号)      " << "所在城市        " << "预定参加人数" << endl;
    int num = 0,n,f=0;
    string nickname, contact, city;
    while (cin >> nickname >> contact >> city >> n)
    {
        while (n + num > 100)
        {
            char choice;
            cout << "对不起,只剩" << capacity - num << "个位置" << endl;
            cout << "1. 输入u,更新预定信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            cout << "你的选择:";
            cin >> choice;
            if (choice == 'q')
            {
                f = 1;
                break;
            }
            else
            {
                cin >> nickname >> contact >> city >> n;
            }
        }
        if (f == 1)
            break;
        num += n;
        info t(nickname, contact, city, n);
        audience_info_list.push_back(t);
    }
    cout << "截至目前,一共有" << num << "位听众预定参加,预定的观众信息如下:" << endl;
    for (auto people : audience_info_list)
    {
        people.print();
    }
    return 0;
}

 

 

 

 

 

 

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

class textcoder
{
public:
    textcoder(string wenben)
    {
        text=wenben;
    }
    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;
        }
    }
}
void test() {

   using namespace std;
   string text, encoder_text, decoder_text;
   cout << "输入英文文本: ";
   while (getline(cin, text))
    {
   encoder_text = textcoder(text).get_ciphertext();
   cout << "加密后英文文本:\t" << encoder_text << endl;
   decoder_text = textcoder(encoder_text).get_deciphertext();
   cout << "解密后英文文本:\t" << decoder_text << endl;
   cout << "\n输入英文文本: ";
  }
}
int main() {
test();
}

 

 

posted @ 2022-10-23 17:32  chenzhongbao  阅读(13)  评论(0)    收藏  举报