首页 > 其他分享 >实验3

实验3

时间:2022-10-23 20:25:36浏览次数:25  
标签:string int text 实验 && include TextCoder

实验任务5

Info.hpp文件源码

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Info{
    public:
        Info(string name,string con,string where,int number):nickname{name},contact{con},city{where},n{number}{};
        void print();
        int get_n();

    private:
    string nickname,contact,city;
    int n;
};
void Info::print(){

    cout<<"昵称:        "<<nickname<<endl;
    cout<<"联系方式:    "<<contact<<endl;
    cout<<"所在城市:    "<<city<<endl;
    cout<<"预定人数:    "<<n<<endl;
    cout<<endl;
}

int Info::get_n(){
    return n;
}

task6.cpp源码

#include <iostream>
#include "Info.hpp"
#include <vector>
#include <string>
#include <iomanip>
int main(){
    using namespace std;
    const int capacity=100;
    vector<Info> audience_info_list;
    cout<<"录入信息:\n\n";
    cout<<"昵称"<<setw(35)<<"联系方式(邮箱/手机号)"<<setw(20)<<"所在城市"<<setw(25)<<"预定参加人数\n";
    int sum=0,number,item=0,left=0;
    string name,con,where;
    while(sum<=capacity&&getline(cin,name,' ')){
        cin>>con;
        cin>>where;
        cin>>number;
        getchar();
        Info push(name,con,where,number);
        left=push.get_n();
        audience_info_list.push_back(push);
        item++;
        sum+=number;
        number=0;
    }
    if(sum>capacity){
        cout<<"对不起,只剩"<<capacity-sum+left<<"个位置\n";
        cout<<"1.输入u,更新(update)预定信息"<<endl;
        cout<<"2.输入q,退出预定" <<endl;
        cout<<"你的选择:";
        char choose;
        cin>>choose;
        cout<<endl;
        cout<<"截至目前,一共有"<<sum-left<<"位听众预定参加。预定听众信息如下:"<<endl;
        for(int i=0;i<item-1;i++){
            audience_info_list.at(i).print();
        }
    }
    else{
        cout<<"截至目前,一共有"<<sum<<"位听众预定参加。预定听众信息如下:"<<endl;
        for(int i=0;i<item;i++){
            audience_info_list.at(i).print();
        }
    }
}

实验任务6

TextCoder.hpp

#include <iostream>
#include <string>
using namespace std;
class TextCoder{
    public:
    TextCoder(string tx);
    string get_ciphertext();
    string get_deciphertext();
    void ciphertext();
    void deciphertext();
    private:
    string text;

};
TextCoder::TextCoder(string tx){
    text=tx;
}
void TextCoder::ciphertext(){
    for(int i=0;i<=text.size();i++){
        if(text[i]>=65&&text[i]<=85){
            text[i]+=5;
        }
        else if(text[i]>=97&&text[i]<=117){
            text[i]+=5;
        }
        else if(text[i]>=86&&text[i]<=90){
            text[i]-=11;
        }
        else if(text[i]>=118&&text[i]<=122){
                text[i]-=11;
        }
    }

}
void TextCoder::deciphertext(){
    for(int i=0;i<=text.size();i++){
        if(text[i]>=70&&text[i]<=90){
            text[i]-=5;
        }
        else if(text[i]>=102&&text[i]<=122){
            text[i]-=5;
        }
        else if(text[i]>=65&&text[i]<=69){
            text[i]-=11;
        }
        else if(text[i]>=97&&text[i]<=101){
                text[i]-=11;
        }
    }

}
string TextCoder::get_ciphertext(){
    this->ciphertext();
    return text;
}
string TextCoder::get_deciphertext(){
    this->deciphertext();
    return text;
}

task6.cpp

#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();
}

 

标签:string,int,text,实验,&&,include,TextCoder
From: https://www.cnblogs.com/dingxincheng/p/16819349.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    基础要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据importre......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;+......
  • 实验2 C语言控制语句应用编程
    1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45intmain()6{7srand(time(0));89intdate=rand()......
  • Centos安装lnmp,云起实验室
    1.执行如下命令,下载并安装MySQL官方的YumRepository。wget-ihttp://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmyum-yinstallmysql57-comm......
  • Python实验报告(第7周)
    实验7:面向对象程序设计一、实验目的和要求1、了解面向对象的基本概念(对象、类、构造方法);2、学会类的定义和使用;3、掌握属性的创建和修改;4、掌握继承的基本语法。 ......
  • 实验五
    1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)2.阅读Hub模块代码,使用tcpdump验证Hub模块;3.阅读L2_learning模块代码,画出程序......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够......
  • 实验6:开源控制器实践——RYU
    一、实验目的能够独立部署RYU控制器;能够理解RYU控制器实现软件定义的集线器原理;能够理解RYU控制器实现软件定义的交换机原理。二、实验环境Ubuntu20.04Desktopamd64......
  • 实验三
    #pragmaonce#include<iostream>#include<string>#include<vector>#include<iomanip>usingnamespacestd;classinfo{public:info(stringn1,stringc1,......