zoukankan      html  css  js  c++  java
  • 实验二

    #include <iostream>
    #include <string>
    using namespace std;
    
    class Info {
    
    public:
        Info (string nina, string con, string ci, int num = 0): nickname(nina), contact(con), city(ci), n(num) {};
        void print();
    
    private:
        string nickname, contact, city;
        int n;
    }; 
    
    void Info::print() {
        cout << "称呼:          " << nickname << endl;
        cout << "联系方式:      " << contact << endl;
        cout << "所在城市:      " << city << endl;
        cout << "预定人数:      " << n << endl; 
    }
    #include"info.hpp"
    #include<iostream>
    #include<iomanip>
    #include<vector>
    #include<string>
    int main()
    {
        using namespace std;
        const int capacity = 100;
        string na;
        string co;
        string ci;
        int nu;
        int n=0;
        vector<Info> audience_info_list;
        cout << "录入信息:" <<endl;
        cout << "称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" << endl; 
        while(cin >> na)
        {
            cin >> co;
            cin >> ci;
            cin >> nu;
            if(n + nu > capacity)
            {
                cout << "对不起,只剩" << capacity - n << "个位置" << endl;
                cout << "1.输入u,更新预定信息" << endl;
                cout << "2.输入q,退出预定" << endl; 
                char s;
                cin >> s;
                if(s=='u')
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
            n+=nu;
            audience_info_list.push_back(Info(na, co, ci, nu));
        }
        cout << "截至目前,一共有" << n << "位听众预定参加。预定听众信息如下:" <<endl;
        for(auto it=audience_info_list.begin();it!=audience_info_list.end();++it)
        {
            it -> print();
        } 
    }

     六

    #include <string>
    
    using namespace std;
    
    class TextCoder
    {
        public:
            TextCoder(string s) : text{s} {}
            string encoder();
            string decoder();
        private:
            string text;
    };
    string TextCoder::encoder()
    {
        for(auto &ch : text)
        {
            if(ch >= 'a' && ch <= 'z')
            {
                ch += 5;
                if(ch > 'z')
                  ch -= 'z' - 'a';
            }
            else if(ch >= 'A' && ch <= 'Z')
            {
                ch += 5;
                if(ch > 'Z')
                  ch -= 'Z' - 'A';
            }
        }
        return text;
    }
    string TextCoder::decoder()
    {
        for(auto &ch : text)
        {
            if(ch >= 'a' && ch <= 'z')
            {
                ch -= 5;
                if(ch < 'a')
                  ch += 'z' - 'a';
            }
            else if(ch >= 'A' && ch <= 'Z')
            {
                ch -= 5;
                if(ch > 'Z')
                  ch += 'Z' - 'A';
            }
        }
        return text;
    }
    #include "TextCoder.hpp"
    #include <iostream>
    #include <string>
    
    int main()
    {
        using namespace std;
    
        string text, encoded_text, decode_text;
    
        cout << "输入英文文本:";
        while (getline(cin, text))
        {
            encoded_text = TextCoder(text).encoder();// 这里使用的是临时无名对象
            cout << "加密后英文文本:" << encoded_text << endl;
    
            decode_text = TextCoder(encoded_text).decoder();// 这里使用的是临时无 名对象
            
            cout << "解密后英文文本:" << decode_text << endl;
            cout << "
    输入英文文本:";
        }
    }

  • 相关阅读:
    Statspack之十四"log file sync" 等待事件
    log file sync(日志文件同步) 与 Log file parallel write 等待事件(1)
    OWI诊断的步骤(基础)
    linux下防火墙配置
    linux中oracle开机启动(2)
    Linux开机自动启动ORACLE设置
    linux find mtime参数详解
    linux 下 rman自动备份
    JSTL 标签库 下载及配置
    JSTL I18N 格式标签库 使用之一_____数字日期格式化
  • 原文地址:https://www.cnblogs.com/ruanfandd/p/15488927.html
Copyright © 2011-2022 走看看