首页 > 其他分享 >实验三

实验三

时间:2022-10-25 20:47:39浏览次数:42  
标签:string int text void 实验 include textcoder

实验五

hpp

#pragma once
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class Info {
public:
    Info(string name0,string contact0,string city0,int n):nickname(name0),contact(contact0),city(city0),n(n){}
    void print();
private:
    string nickname, contact, city;
    int n;
};
void Info::print()
{
    cout << setw(10) << "昵称:\t" << nickname << endl;
    cout << setw(10) << "联系方式:\t" << nickname << endl;
    cout << setw(10) << "所在城市:\t" << nickname << endl;
    cout << setw(10) << "预订人数:\t" << n<< endl;
}

cpp

#include"info.hpp"
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    const int capacity = 100;
    vector<Info> audience_info_list;
    cout << "录入信息" << endl;
    cout << endl;
    cout << "昵称\t";
    cout << "联系方式\t";
    cout << "所在城市\t";
    cout << "预订人数\t" << endl;
    string nickname, contact, city;
    int num, sum = 0;
    while (cin >> nickname) {
        cin >> contact >> city >> num;
        sum += num;
        if (capacity - sum > 0)
        {
            Info p = Info(nickname, contact, city, sum);
            audience_info_list.push_back(p);
        }
        else
        {
            sum -= num;
            char c;
            cout << "对不起,只剩" << capacity - sum << "个位置" << endl;
            cout << "1.输入u,更新(update)预定信息" << endl;
            cout << "2.输入q,退出预订" << endl;
            cout << "你的选择:";
            cin >> c;
            cout << endl;
            if (c == 'q')
                break;
            else if (c == 'u')
            {
                cout << "请更新您的预定信息" << endl;
                continue;
            }
        }
    }
    cout << "截至目前,一共有" << sum << "名听众预定参加.预定听众信息于下:" << endl;
    for (int i = 0; i < audience_info_list.size(); i++) {
        audience_info_list.at(i).print();
        cout << endl;
    }

}

运行结果

实验6

hpp

#pragma once
#include<iostream>
#include<string>

using namespace std;

class textcoder {
public:
    textcoder(string text0) :text{ text0 } {}
    textcoder(textcoder& t) :text{ t.text } {}
    string get_ciphertext();
    string get_deciphertext();
private:
    string text;
    void encoder();
    void decoder();
};
void textcoder::encoder() {
    for (int i = 0; i < text.size(); i++) {
        if (isupper(text.at(i))) text.at(i) = (text.at(i) + 5 - 65) % 26 + 65;
        else if (islower(text.at(i))) text.at(i) = 97 + (text.at(i) + 5 - 97) % 26;
    }
}
void textcoder::decoder() {
    for (int i = 0; i < text.size(); i++) {
        if (isupper(text.at(i))) text.at(i) = (text.at(i) - 65 - 5 + 26) % 26 + 65;
        else if (islower(text.at(i))) text.at(i) = (text.at(i) - 97 - 5 + 26) % 26 + 97;
    }
}
string textcoder::get_ciphertext() {
    encoder();
    return text;
}
string textcoder::get_deciphertext() {
    decoder();
    return text;
}

 

cpp

#include<iostream>
#include"textcoder.hpp"
#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,void,实验,include,textcoder
From: https://www.cnblogs.com/zqpqaz151034/p/16826225.html

相关文章

  • 实验三
    task5://info.hpp#include<iostream>#include<string>usingnamespacestd;classinfo{private:stringnickname,contact,city;intn;staticin......
  • 实验3
    #include"info.hpp"#include<iostream>#include<vector>#include<cstring>intmain(){intcount=0;constintcapacity=100;vector<Info>audience_......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBox或......
  • 实验7:基于REST API的SDN北向应用实践
    实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。实验要求(一)基本要求编写Python程序,调用OpenDayl......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境1.下载虚拟机软件OracleVisua......
  • 决策树算法实验
     【实验目的】理解决策树算法原理,掌握决策树算法框架;理解决策树学习算法的特征选择、树的生成和树的剪枝;能根据不同的数据类型,选择不同的决策树算法;针对特定应用场......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i)......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......