实验三

#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(); 
}
#include <iostream>
#include <string>
#include <cctype>
 
 using namespace std;
 class TextCoder {
 
 public:
     TextCoder(string str):text(str) {}
     string get_ciphertext();
     string get_deciphertext();
     
 private:
     string text;
     void encoder();
     void decoder();
     };
 void TextCoder::encoder() {
     for(auto &c: text) {
        if(c <= 'u' && c >= 'a' || c <= 'U' && c >= 'A') {
            c = c + 5;         } else if(c > 'u' && c <= 'z' || c > 'U' && c <= 'Z') {
             c = c - 21;
         }
     }
 }
 void TextCoder::decoder() {
     for(auto &c: text) {
         if(c <= 'z' && c >= 'f' || c <= 'Z' && c >= 'F') {
             c = c - 5;
        } else if(c >= 'a' && c < 'f' || c >= 'A' && c < 'F') {
            c = c + 21;
         }
     }
 }
 
 string TextCoder::get_ciphertext() {
     encoder();
     return text;
 }

 string TextCoder::get_deciphertext() {
     decoder();
    return text;
}

 

 

 

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

class Info{
    public:    
    Info(string name="",string con="",string ci="",int nu=0):nickname{name},contact{con},city{ci},n{nu}{}
    ~Info()=default;
    void print(){
        cout<<"称呼:     "<<nickname<<endl;
        cout<<"联系方式: "<<contact<<endl;
        cout<<"所在城市:"<<city<<endl;
        cout<<"预订人数:"<<n<<endl;
    }
    private:
    string nickname;
    string contact;
    string city;
    int n;    
    
};
#include"Info.hpp"
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
    const int capacity=100;
    int Number=100,count=0;
    vector<Info> audience_info_list;
    cout<<"录入信息"<<endl;
    cout<<endl;
    cout<<"称呼/昵称     联系方式(邮箱/手机号)    所在城市    预定参加人数"<<endl;
    string s1,s2,s3,s4;
    int n1;
    while(cin>>s1)
    {
        cin>>s2>>s3>>n1;
        audience_info_list.push_back(Info(s1,s2,s3,n1));
        if(Number-n1<0)
        {
            cout<<"对不起,只剩下"<<Number<<"个位置"<<endl;
            cout<<"1.输入u,更新(update)预定信息"<<endl;
            cout<<"2.输入q,退出预定"<<endl;
            char a;
            cin>>a;
            if(a=='q')
            {
                cout<<"你的选择:q"<<endl;
                audience_info_list.pop_back() ;
                break;
            }
            if(a=='u')
            {
                audience_info_list.pop_back() ;
                continue;
            }
         } 
        Number -= n1;
        count+=n1;
    }
    cout<<"截至目前,一共有"<<count<<"位听众参加预定。预定听众信息如下:"<<endl;
    for(auto it=audience_info_list.begin() ;it!=audience_info_list.end();it++)
    it->print();
    return 0;
}

 

 

 

posted @ 2022-10-20 17:26  waitwaitw  阅读(18)  评论(0编辑  收藏  举报