首页 > 其他分享 >实验三

实验三

时间:2022-10-23 17:46:08浏览次数:39  
标签:info string text 实验 && include textcoder

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

class info {
public:
    info(string n1, string c1, string c2, int n2)
    {
        nickname=n1;
        contact=c1;
        city=c2;
        n=n2;
    }
    void print()
    {
        cout << "昵称:         " << nickname << endl;
        cout << "联系方式:     " << contact << endl;
        cout << "所在城市:     " << city << endl;
        cout << "预定参加人数: " << n << endl;
}
private:
    string nickname;
    string contact;
    string city;
    int n;
};
int main()
{
    const int capacity=100;
    vector<info> audience_info_list;
    cout << "录入信息:" << endl << endl;
    cout << "昵称        " << "联系方式(邮箱/手机号)      " << "所在城市        " << "预定参加人数" << endl;
    int num = 0,n,f=0;
    string nickname, contact, city;
    while (cin >> nickname >> contact >> city >> n)
    {
        while (n + num > 100)
        {
            char choice;
            cout << "对不起,只剩" << capacity - num << "个位置" << endl;
            cout << "1. 输入u,更新预定信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            cout << "你的选择:";
            cin >> choice;
            if (choice == 'q')
            {
                f = 1;
                break;
            }
            else
            {
                cin >> nickname >> contact >> city >> n;
            }
        }
        if (f == 1)
            break;
        num += n;
        info t(nickname, contact, city, n);
        audience_info_list.push_back(t);
    }
    cout << "截至目前,一共有" << num << "位听众预定参加,预定的观众信息如下:" << endl;
    for (auto people : audience_info_list)
    {
        people.print();
    }
    return 0;
}

 

 

 

 

 

 

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

class textcoder
{
public:
    textcoder(string wenben)
    {
        text=wenben;
    }
    string get_ciphertext();
    string get_deciphertext();
private:
    void encoder();
    void decoder();
    string text;
};
string textcoder::get_ciphertext()
{
    encoder();
    return text;
}
string textcoder::get_deciphertext()
{
    decoder();
    return text;
}
void 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]+=5;
        }
        else if((text[i]>='v'&&text[i]<='z')||(text[i]>='V'&&text[i]<='Z'))
        {
            text[i]-=21;
        }
    }
}

void textcoder::decoder()
{
    for(int i=0;i<text.length();i++)
    {
        if((text[i]>='a'&&text[i]<='e')||(text[i]>='A'&&text[i]<='E'))
        {
            text[i]+=21;
        }
        else if((text[i]>='f'&&text[i]<='z')||(text[i]>='F'&&text[i]<='Z'))
        {
            text[i]-=5;
        }
    }
}
void test() {

   using namespace std;
   string text, encoder_text, decoder_text;
   cout << "输入英文文本: ";
   while (getline(cin, text))
    {
   encoder_text = textcoder(text).get_ciphertext();
   cout << "加密后英文文本:\t" << encoder_text << endl;
   decoder_text = textcoder(encoder_text).get_deciphertext();
   cout << "解密后英文文本:\t" << decoder_text << endl;
   cout << "\n输入英文文本: ";
  }
}
int main() {
test();
}

 

 

标签:info,string,text,实验,&&,include,textcoder
From: https://www.cnblogs.com/czba/p/16818987.html

相关文章

  • 实验5:开源控制器实践——POX
    一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够运用POX控制器编写自定义网络......
  • 实验2 C语言控制语句应用编程
     任务一:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){nu......
  • 实验三:数组、指针与现代C++
    实验任务五task.cpp#include"info.h"#include<iostream>#include<string>#include<vector>usingnamespacestd;intmain(){constintcapacity=100;v......
  • ensp静态路由配置实验
    一、绘制网络拓扑图:二、配置pc配置IP地址、掩码、网关一定要填好,填好后点击应用。路由器配置:R1<Huawei>undottInfo:Currentterminaltrappingisoff.<Huawe......
  • 实验3 数组、指针与现代C++标准库
    任务五info.hpp1#pragmaonce2#include<iostream>3#include<string>4#include<iomanip>5usingnamespacestd;6classinfo7{8public:9......
  • 实验三 数组、指针与现代C++标准库
    实验五代码:Info.hpp1#pragmaonce23#include<iostream>4#include<string>5#include<iomanip>67usingstd::string;8usingstd::cout;9us......
  • 实验5:开源控制器实践——POX
    实验要求(一)基本要求1、搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)(1)搭建拓扑命令:sudomn--topo=single,3--mac--controll......
  • 实验三
    任务五info.hpp#include<iostream>#include<string>usingnamespacestd;classinfo{private:stringnickname,contact,city;intn;public:in......
  • 实验6:开源控制器实践——RYU
    一、基础要求 1、使用OpenFlow1.0搭建SDN拓扑。连接Ryu控制器,并图形界面查看网络拓扑topo=single,3时Ryu的图行界面 2、阅读Ryu文档,验证并分析Ryu的L2Switch和Pox......
  • 实验5:开源控制器实践 _POX
    一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.能够运用POX控制器编写自定义网......