首页 > 其他分享 >实验5

实验5

时间:2023-12-01 10:00:53浏览次数:24  
标签:Info string int text 实验 include TextCoder

#program once
#include<iostream>
#include<string>

using namespace std;

class TextCoder{
private:
    string text;
    void encoder();
#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(); 
}

#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Info
{
public:
    Info(string name, string contact, string city, int n);
    void print();
private:
    string name, contact, city;
    int n;
};
Info::Info(string name, string contact, string city, int n)
{
    name = name0; contact = contact0; city = city0; n = n0;
}
void Info::print()
{
    cout << "昵称:        " << name << endl;
    cout << "联系方式:    " << contact << endl;
    cout << "所在城市:    " << city << endl;
    cout<<"预定人数:    " << n << endl;
}

  

#include<iostream>
#include<string>
#include<vector>
#include"info.hpp"
int main()
{
    string a, b, c; int d,sum=0;
    int const capacitd = 100;
    vector<Info> x;
    cout << "录入信息:" << endl<<endl;
    cout << "昵称\t    " << "联系方式(邮箱/手机号)\t    " << "所在城市\t    " << "预定参加人数\t" << endl;
    for ( sum ;;)
    {
        cin >> a >> b>> c >> d;
        Info z(a, b, c, d);
        int y = sum;
        if (sum+d > capacitd)
        {
            cout << "对不起,只剩" << capacitd - y << "个位置" << endl;
            cout << "1.输入u,更新(update)预定信息" << endl;
            cout << "2.输入o,退出(out)预定" << endl; char s;
            cout << "您的选择:"; cin >> s;
            if (s == 'u')    continue; cout << endl;
            break;
        }
        else
        {
            sum += d;
            x.push_back(z);
        }
    }
    cout << "截至目前,一共有" << sum << "听众预定参加。预定听众信息如下。" << endl;
    for (int i = 0; i < x.size(); i++)
    {
        x[i].print();
    }
}

  

 

    void decoder();
public:
    TextCoder(string &str);
    string get_ciphertext();
    string get_deciphertext();
    
};

TextCoder::TextCoder(string &str){
    text=str;
}

string TextCoder::get_ciphertext() {
    encoder();
    return text;
}

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

void TextCoder::encoder(){
    for(auto &i : text){
        if (i >= 'a' && i <= 'z')
            i = 'a' + ((i -'a')+7) % 26;
       else if (i >= 'A' && i <= 'Z')
                i = 'A' + ((i -'A')+7) % 26;
   }
}
void TextCoder::decoder() {
     for (auto &i : text) {
         if (i >= 'a' && i <= 'z')
             i = 'a' + ((i -'a') + 26-7) % 26;
         else if (i >= 'A' && i <= 'Z')
                  i = 'A' + ((i -'A') + 26-7) % 26;
    }
}

  

 

标签:Info,string,int,text,实验,include,TextCoder
From: https://www.cnblogs.com/gycgy/p/17869086.html

相关文章

  • 实验四-现代C++标准库与类模板
    1#include<iostream>23usingstd::cout;4usingstd::endl;56classA{7public:8A(intx0,inty0):x{x0},y{y0}{}9voidshow()const{cout<<x<<","<<y<<endl;}10private:11......
  • 实验4
    实验任务5#include<iostream>#include<string>usingnamespacestd;classTextCoder{public:TextCoder()=default;TextCoder(stringstr);stringget_ciphertext();stringget_deciphertext();~TextCoder()=default;private:......
  • 实验四
    #programonce#include<iostream>#include<string>usingnamespacestd;classTextCoder{private:stringtext;voidencoder();voiddecoder();public:TextCoder(string&str);stringget_ciphertext();stringget_dec......
  • 实验四 现代C++标准库类与模板
    实验任务1task1.cpp源码task1_1.cpp:#include<iostream>usingstd::cout;usingstd::endl;//类A的定义classA{public:A(intx0,inty0):x{x0},y{y0}{}voidshow()const{cout<<x<<","<<y<<endl;}......
  • 实验4 现代C++标准库与类模板
    实验任务5textcoder.hpp#programonce#include<iostream>#include<string>usingnamespacestd;classTextCoder{private:stringtext;voidencoder();voiddecoder();public:TextCoder(string&str);stringget_ciphertext(......
  • 实验4 现代C++标准库与类模板
    实验任务51#include<iostream>2#include<string>3usingnamespacestd;4classTextCoder5{6public:7TextCoder()=default;8TextCoder(stringstr);9stringget_ciphertext();10stringget_deciphertext();11......
  • 实验4 现代c++标准库与类模板
    实验任务1task1.cpp源码task1_1.cpp:1#include<iostream>23usingstd::cout;4usingstd::endl;56//类A的定义7classA{8public:9A(intx0,inty0):x{x0},y{y0}{}10voidshow()const{cout<<x<<","<......
  • 实验四 现代c++ 标准库与类的模板
    1.普通数组、array、vector的相关性,以及,区别相关性存储多个元素:1.普通数组:使用C风格数组声明和定义,大小固定。2.array:是C++11引入的标准库容器,提供了数组的替代,大小固定。3.vector:是C++标准库中的动态数组,大小可以动态调整。元素访问:1.普通数组和array:使用索......
  • 实验4
    #include<iostream>#include<string>usingstd::string;classTextCoder{private:stringtext;voidencoder();voiddecoder();public:TextCoder(string&str);TextCoder(constTextCoder&......
  • 实验4 现代C++标准库与类模板
    实验任务5task5.cpp#include"Textcoder.hpp"#include<iostream>#include<string>voidtest(){ usingnamespacestd; stringtext,encoded_text,decoded_text; cout<<"输入英文文本:"; while(getline(cin,text)) { encoded_t......