首页 > 其他分享 >实验三

实验三

时间:2022-10-24 21:44:08浏览次数:35  
标签:string text void num 实验 && include

#pragma once
#include <iostream>
#include<vector>
#include <string>
#include<iomanip>
using namespace std;
class Info {
public:
    Info() {}
    Info(string a, string b, string c, int d) :nickname{ a }, contact{ b }, city{ c }, n{ d }{};
    void print() {
        cout <<left<< setw(20) << "昵称:" << nickname << endl;
        cout <<left<< setw(20) << "联系方式:" << contact << endl;
        cout <<left<< setw(20) << "所在城市:" << city << endl;
        cout <<left<< setw(20) << "预定人数" << n << endl;
    }
private:
    string nickname, contact, city;
    int n;
};
#include<Info.hpp>
#include <iostream>
#include<vector>
#include <string>
#include<iomanip>


using namespace std;
vector<Info> audience_info_list;
int main() {
    cout << "录入信息:" << endl;
    cout << "昵称         联系方式(邮箱/手机号)     所在城市      预定参加人数" << endl;
    const int capacity = 100;
    int sum = 0;
    string s1, s2, s3;
    int num;
    int count = 0;
    while (cin >> s1 >> s2 >> s3 >> num) {
        sum += num;
        if (sum > capacity) {
            sum -= num;
            cout << "对不起,只剩" << capacity - sum << "个位置." << endl;
            cout << "1.输入u,更新(update)预定信息" << endl
                << "2.输入q, 退出预定" << endl << "你的选择: ";
            string f;
            cin >> f;
            if (f == "u")
            {
                cin >> s1 >> s2 >> s3 >> num;
                Info f(s1, s2, s3, num);
                audience_info_list.push_back(f);
                sum += num;
            }
            else
                break;
        }

        else audience_info_list.push_back(Info(s1, s2, s3, num));
    }
    cout << endl << "截至目前,一共有" << sum << "位听众预定参加。信息如下:" << endl;;
    for (int i = 0; i < audience_info_list.size(); i++)
    {
        audience_info_list.at(i).print();
        cout << endl;
    }
    return 0;
}

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

class TextCoder {
public:
    TextCoder() {}
    TextCoder(string text0) :text{ text0 } {}
    string get_ciphertext() { encoder(); return text; }
    string get_deciphertext() { decoder(); return text; }
private:
    string text;
    void encoder();
    void decoder();
};

void TextCoder::encoder() {
    int i;
    for (i = 0; i < text.length(); i++)
    {

        if ((text[i] >= 86 && text[i] <= 90) || (text[i] >= 118 && text[i] <= 122))
        {
            text[i] = text[i] - 21;
        }
        if ((text[i] < 86 && text[i] >= 65) || (text[i] >= 97 && text[i] < 118))
        {
            text[i] = text[i] + 5;
        }
    }
}

void TextCoder::decoder() {
    int i;
    for (i = 0; i < text.length(); i++)
    {

        if ((text[i] >= 65 && text[i] <= 69) || (text[i] >= 97 && text[i] <= 101))
        {
            text[i] = text[i] + 21;
        }
        if ((text[i] > 69 && text[i] <= 90) || (text[i] > 101 && text[i] <= 122))
        {
            text[i] = text[i] - 5;
        }
    }
}
#include"textcorder.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();
}

 

标签:string,text,void,num,实验,&&,include
From: https://www.cnblogs.com/jh025/p/16823106.html

相关文章

  • 实验2
    实验1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能。(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight。(2)下发指令删除s1上的流表数据#!/us......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0,i<N,i++)......
  • 实验5:开源控制器实践——POX
    一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.能够运用POX控制器编写自定......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据。import......
  • 实验3
    task51#include<iostream>2#include<vector>3#include<string>4#include<iomanip>5usingnamespacestd;6classInfo{7friendvoidprint(vect......
  • 实验一:决策树算法实验
    博客班级https://edu.cnblogs.com/campus/czu/classof2020BigDataClass3-MachineLearning作业要求https://edu.cnblogs.com/campus/czu/classof2020BigDataClass......
  • 实验二
    test1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......
  • 实验5:开源控制器实践——POX
    (一)基本要求1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)sudomn--topo=single,3--mac--controller=remote,ip=127.0.0.1,......
  • 实验三
    实验3数组、指针与现代c++标准库一、task51.源代码:(1)Info.cpp#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classinfo{public:......