实验二

2021/11/2 6:09:53

本文主要是介绍实验二,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#ifndef Info_HPP
#define Info_HPP
#include <iostream>
#include <string>
using namespace std;
class Info
{
    private:
        string nickname,contact,city;
        int n;
    public:
        Info(string x,string y,string z,int a) {nickname=x;contact=y;city=z;n=a;}
        void print();
};
void Info::print()
{
    cout<<"称呼:         "<<nickname<<endl;
    cout<<"联系方式:     "<<contact<<endl;
    cout<<"所在城市:     "<<city<<endl;
    cout<<"预定人数:     "<<n<<endl;
}
#endif
#include "Info.hpp"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    vector<Info>audience_info_list;
    const int capacity=100;
    string x,y,z;
    int count=0,n;
    char choice;
    cout<<"录入信息:"<<endl<<endl;
    cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" <<endl;
    while(cin>>x)
    {
        cin>>y;
        cin>>z;
        cin>>n;
        if(n+count>capacity)
        {
            cout<<"对不起,只剩"<<(capacity-count)<<"个位置。"<<endl;
            cout<<"1.输入u,更新(update)预订信息"<<endl;
            cout<<"2.输入q,退出预定"<<endl;
            cout<<"你的选择:";
            cin>>choice;
            if(choice=='u')
            {
                cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl;
                continue;
            }
            else break;
        }
        
        else
        {
            count+=n;
            audience_info_list.push_back(Info(x,y,z,n));
        }
    }
    cout<<"截止目前,一共有"<<count<<"位听众参与预定。预定听众信息如下:"<<endl;
    for (int i=0;i<audience_info_list.size();i++)
        audience_info_list[i].print();
    return 0;
}

 

 

 

#ifndef TextCoder_HPP
#define TextCoder_HPP
#include<iostream>
#include<String>
using namespace std;
class TextCoder
{
    private:
        string text;
    public:
        TextCoder(string x){text=x;}
        string encoder();
        string decoder();
};
string 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]=text[i]+5;
        }
        else if((text[i]>='V'&&text[i]<='Z')||(text[i]>='v'&&text[i]<='z'))
        {
            text[i]=text[i]-21;
        }    
    }
    return text;
}
string TextCoder::decoder()
{
    for(int i=0;i<text.length();i++)
    {
        if((text[i]>='F'&&text[i]<='Z')||(text[i]>='f'&&text[i]<='z'))
        {
            text[i]=text[i]-5;
        }
        else if((text[i]>='A'&&text[i]<='E')||(text[i]>='a'&&text[i]<='e'))
        {
            text[i]=text[i]+21;
        }
    }
    return text;
}
#endif
#include "TextCoder.hpp"
#include <iostream>
#include <string>

int main()
{
    using namespace std;

    string text, encoded_text, decoded_text;

    cout << "输入英文文本: ";
    while (getline(cin, text))
    {
        encoded_text = TextCoder(text).encoder();  // 这里使用的是临时无名对象
        cout << "加密后英文文本:\t" << encoded_text << endl;

        decoded_text = TextCoder(encoded_text).decoder(); // 这里使用的是临时无名对象
        cout << "解密后英文文本:\t" << decoded_text << endl;
        cout << "\n输入英文文本: ";
    }
}

 

 



这篇关于实验二的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程