首页 > 其他分享 >实验三

实验三

时间:2022-10-20 17:15:00浏览次数:40  
标签:Info string text void 实验 include TextCoder

Info.hpp

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

class Info{
    public:    
    Info(string name="",string con="",string ci="",int nu=0):nickname{name},contact{con},city{ci},n{nu}{}
    ~Info()=default;
    void print(){
        cout<<"称呼:     "<<nickname<<endl;
        cout<<"联系方式: "<<contact<<endl;
        cout<<"所在城市:"<<city<<endl;
        cout<<"预订人数:"<<n<<endl;
    }
    private:
    string nickname;
    string contact;
    string city;
    int n;    
    
};

task5

#include"Info.hpp"
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
    const int capacity=100;
    int Number=100,count=0;
    vector<Info> audience_info_list;
    cout<<"录入信息"<<endl;
    cout<<endl;
    cout<<"称呼/昵称     联系方式(邮箱/手机号)    所在城市    预定参加人数"<<endl;
    string s1,s2,s3,s4;
    int n1;
    while(cin>>s1)
    {
        cin>>s2>>s3>>n1;
        audience_info_list.push_back(Info(s1,s2,s3,n1));
        if(Number-n1<0)
        {
            cout<<"对不起,只剩下"<<Number<<"个位置"<<endl;
            cout<<"1.输入u,更新(update)预定信息"<<endl;
            cout<<"2.输入q,退出预定"<<endl;
            char a;
            cin>>a;
            if(a=='q')
            {
                cout<<"你的选择:q"<<endl;
                audience_info_list.pop_back() ;
                break;
            }
            if(a=='u')
            {
                audience_info_list.pop_back() ;
                continue;
            }
         } 
        Number -= n1;
        count+=n1;
    }
    cout<<"截至目前,一共有"<<count<<"位听众参加预定。预定听众信息如下:"<<endl;
    for(auto it=audience_info_list.begin() ;it!=audience_info_list.end();it++)
    it->print();
    return 0;
}

TextCoder.hpp

#include <iostream>
#include <string>
#include <cctype>
 
 using namespace std;
 class TextCoder {
 
 public:
     TextCoder(string str):text(str) {}
     string get_ciphertext();
     string get_deciphertext();
     
 private:
     string text;
     void encoder();
     void decoder();
     };
 void TextCoder::encoder() {
     for(auto &c: text) {
        if(c <= 'u' && c >= 'a' || c <= 'U' && c >= 'A') {
            c = c + 5;         } else if(c > 'u' && c <= 'z' || c > 'U' && c <= 'Z') {
             c = c - 21;
         }
     }
 }
 void TextCoder::decoder() {
     for(auto &c: text) {
         if(c <= 'z' && c >= 'f' || c <= 'Z' && c >= 'F') {
             c = c - 5;
        } else if(c >= 'a' && c < 'f' || c >= 'A' && c < 'F') {
            c = c + 21;
         }
     }
 }
 
 string TextCoder::get_ciphertext() {
     encoder();
     return text;
 }

 string TextCoder::get_deciphertext() {
     decoder();
    return text;
}

task6

#include "textcoder.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(); 
}

 

标签:Info,string,text,void,实验,include,TextCoder
From: https://www.cnblogs.com/wyh-205113/p/16810516.html

相关文章

  • 实验5:开源控制器实践——POX
    (一)基本要求:1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)1)生成拓扑:sudomn--topo=single,3--mac--controller=remote,ip......
  • 实验三
    实验任务5#pragmaonce#include<iostream>#include<string>usingnamespacestd;classInfo{public:Info(stringnickname1,stringcontact1,stringcity......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够......
  • TFboy的实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子......
  • 实验五
    一、实验目的1、能够理解POX控制器的工作原理;2、通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3、能够运用POX控制器编写自定......
  • Python实验报告——第6章 函数
    实验报告实例01:输出每日一帖(共享版)代码如下:deffunction_tips():'''功能:每天输出一条励志文字'''importdatetime#导入日期时间类#定义......
  • python实验报告(函数)
    1.输出每日一站(共享版)  结果:   2.根据身高,体重计算BMI指数  结果:  3.根据身高,体重计算BMI指数  结果:  4.模拟结账功能———计算实付金......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.......
  • 实验五
    搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)阅读Hub模块代码,使用tcpdump验证Hub模块;阅读L2_learning模块代码,画出程......
  • 实验2 C语言控制语句应用编程
    实验一#include<math.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=......