首页 > 其他分享 >实验3

实验3

时间:2022-10-21 20:46:55浏览次数:32  
标签:Info string int text 实验 include TextCoder

task5

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

class Info {
private:
    string nickname, contact, city;
    int n;
public:
    Info(string a,string b,string c,int d):nickname(a),contact(b),city(c),n(d){}
    ~Info() = default;
    void Info_()const;
};

void Info::Info_()const {
    cout << left << setw(9) << "昵称:" << nickname << endl;
    cout << left << setw(9) << "联系方式:" << contact << endl;
    cout << left << setw(9) << "所在城市:" << city << endl;
    cout << left << setw(9) << "预定人数:" << n << endl;
    cout << endl;
}
#include"Info.hpp"
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;

const int capacity = 100;

int main() {
    vector<Info> audience_info_list;
    string a, b, c;
    static int count = 0;
    int m;
    char qu;
    cout << "录入信息:\n\n" << "昵称   " << "联系方式(邮箱/手机号)   " <<
        "所在城市       " << "预定参加人数" << endl;

    while (cin >>a) {
        cin >> b >> c >> m;
        if (count + m < capacity)
        {
            Info audience(a, b, c, m);
            audience_info_list.push_back(audience);
            count += m;
            if (m == capacity)
                break;
        }

    else
        {
        int left = capacity - count;
        cout << "对不起,只剩" << left << "个位置。" << endl;
        cout << "1.输入u,更新(update)预定信息。" << endl;
        cout << "2.输入q,退出预定。" << endl;
        cout << "你的选择:";
        cin >> qu;
        if (qu == 'q')
        {
            cout << endl; break;
        }
        else continue;
        }
}
cout << "截至目前,一共有" << count << "位听众预定参与。预定听众信息如下:" << endl;
for (auto item : audience_info_list)
{
    item.Info_();
}

}

task6

#include<iostream>
#include<string>

using namespace std;
class TextCoder {
public:
    TextCoder(string text);
    ~TextCoder() = default;

    string get_ciphertext();
    string get_deciphertext();

private:
    string text;
    void encoder();
    void decoder();
};

TextCoder::TextCoder(string a) :text(a) {}

void TextCoder::encoder() {
        for (int i = 0; i < text.size(); i++) {
           if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z')) {
                     text[i] += 5;
                    if (text[i] > 'z' || (text[i] > 'Z' && text[i] < 'a'))
                             text[i] -= 26;
         
        }
   
    }
}

void TextCoder::decoder()
{
    for (int i = 0; i < text.length(); i++)
    {
        if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z')) {
            text[i] -= 5;
            if (text[i] < 'A' || (text[i] > 'Z' && text[i] < 'a'))
                text[i] += 26;
        }
    }
}
string TextCoder::get_ciphertext() {
    encoder();
    return text;
}

string TextCoder::get_deciphertext() {
    decoder();
    return text;
}
#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,int,text,实验,include,TextCoder
From: https://www.cnblogs.com/Xl995/p/16814700.html

相关文章

  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){inti,number;srand(time(0));for(i=0;i<=N;++i){......
  • 网络工程知识(二)VLAN的基础和配置:802.1q帧;Access、Trunk、Hybrid接口工作模式过程与配
    介绍-VLANVLAN(VirtualLocalAreaNetwork)即虚拟局域网,工作在数据链路层。交换机将通过:接口、MAC、基于子网、协议划分(IPv4和IPv6)、基于策略的方式划分VLAN的方式,将接......
  • 软件实验设计15
    实验15:职责链模式[实验任务一]:财务审批某物资管理系统中物资采购需要分级审批,主任可以审批1万元及以下的采购单,部门经理可以审批5万元及以下的采购单,副总经理可以审批10......
  • 算法分析与设计 西工大 noj 第二次实验
    算法分析与设计西工大noj第二次实验ProblemA0-1背包问题时限:1000ms内存限制:10000K总时限:3000ms描述:需对容量为c的背包进行装载。从n个物品中选取装入背包的物......
  • 实验三
    info.h#pragmaonce#include<iostream>#include<string>usingnamespacestd;classinfo{public:info(string_nickname,string_contact,string_city,in......
  • 实验3 数组、指针与现代c++标准库
    1.实验任务1程序源码task1_1#include<iostream>usingstd::cout;usingstd::endl;classA{public:A(intx0,inty0):x{x0},y{y0}{}voidshow......
  • Python实验(第8周)
       实验7:面对对象程序设计一、实验目的和要求1、学会类的定义和使用;2、学会创建属性;3、实现类的继承。二、实验环境软件版本:Python3.1064_bit三、实验过程1......
  • 实验6:开源控制器实践——RYU
    一、实验目的能够独立部署RYU控制器;能够理解RYU控制器实现软件定义的集线器原理;能够理解RYU控制器实现软件定义的交换机原理。二、实验环境下载虚拟机软件OracleVisu......
  • 实现实验室和寝室两台电脑文件实时同步
    考虑到白天去实验室工作,晚上又要回寝室,文件传输会很麻烦,于是寻求能够方便进行文件远程同步的方案。1.使用工具内网穿透:zerotier(全平台均可)文件同步(备份)工具:FreeFileSyn......
  • 实验6:开源控制器实践——RYU
    实验6:开源控制器实践——RYU一、实验目的1.能够独立部署RYU控制器;2.能够理解RYU控制器实现软件定义的集线器原理;3.能够理解RYU控制器实现软件定义的交换机原理。二、......