• 实验二


    #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 << "
    输入英文文本:";
        }
    }

  • 相关阅读:
    JavaScript系列:JavaScript简介
    Fit自适应布局
    JavaScript数值类型及变量
    表格列Column
    JavaScript系列:ECMAScript引用类型
    Absolute绝对定位
    JavaScript系列:ECMAScript运算符
    JavaScript系列:ECMAScript类型转换
    jQuery Uploadify在ASP.NET MVC3中的使用
    JavaScript系列:ECMAScript语句
  • 原文地址:https://www.cnblogs.com/ruanfandd/p/15488927.html
Copyright © 2020-2023  润新知