首页 > 其他分享 >实验三

实验三

时间:2022-10-22 21:56:06浏览次数:31  
标签:info string int text 实验 && include

实验任务5
info部分:

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
class info {
public:
    info(string nick, string cont, string ci, int m) :nickname{ nick }, contact{ cont }, city{ ci }, n{ m } {};
    void print();
private:
    string nickname,contact,city;
    int n = 0;
};

void info::print() {
    cout << "昵称:" << setw(7) << nickname << endl;
    cout << "联系方式:" << setw(7) << contact << endl;
    cout << "所在城市:" << setw(7) << city << endl;
    cout << "预定人数:" << setw(7) << n << endl;
    cout << endl;
}

task5:
#include "info.hpp"
#include <iostream>
#include<vector>
#include<iomanip>

int main() {
    const int capacity = 100;
    vector<info>audience_info_list ;
    string nickname, contact, city;
     int sum_people = 0,yuding=0;
     char choice;
     cout << "录入信息:" << endl;
     cout << "昵称" << "     联系方式(邮箱/手机号)" <<"     所在城市" <<"     预定参加人数" << endl;
     while (cin >> nickname)
     {
         cin >> contact >> city >> yuding;
         sum_people +=yuding;
         if (sum_people > capacity)
         {
             cout << "对不起,只剩下:" << capacity - (sum_people - yuding) << "个位置了." << endl;;
             cout << "1.输入u,更新(update)预定信息." << endl;
             cout << "2.输入q,退出预定." << endl;
             cout << "你做出的选择是:" ;
             cin >> choice;
             if (choice == 'u')
                 {
                 sum_people -= yuding;
                   continue;
                  }
             else if (choice == 'q')
                 break;
         }
         
         info x(nickname,contact,city,yuding);
         audience_info_list.push_back(x);
     }
     if(sum_people>capacity)
            cout << "截至目前,一共有" << sum_people-yuding << "位听众预定参加,预定听众信息如下:" << endl;
     else
            cout << "截至目前,一共有" << sum_people << "位听众预定参加,预定听众信息如下:" << endl;
     for (auto i = 0; i < audience_info_list.size(); ++i)
         audience_info_list[i].print();
}

#include<iostream>
#include<string>

using namespace std;
class TextCoder {
public:
    TextCoder(string text1) :text{ text1 } {}
    string get_ciphertext() { encoder(); return text; }
    string get_deciphertext() { decoder(); return text; }
private:
    string text;
    void encoder() {
        for (int i = 0; i < text.size(); i++)
        {
            if (text[i] >= 'a' && text[i] <= 'u')
                text[i] += 5;
            else if (text[i] > 'u' && text[i] <= 'z')
                text[i] -= 21;
            if (text[i] >= 'A' && text[i] <= 'U')
                text[i] += 5;
            else if (text[i] > 'U' && text[i] <= 'Z')
                text[i] -= 21;

        }
    }
    void decoder()
    {
        for (int i = 0; i < text.size(); i++)
        {
            if (text[i] >= 'f' && text[i] <= 'z')
                text[i] -= 5;
            else if (text[i] < 'f' && text[i] >= 'a')
                text[i] += 21;
            if (text[i] >= 'F' && text[i] <= 'Z')
                text[i] -= 5;
            else if (text[i] < 'F' && text[i] >= 'A')
                text[i] += 21;
        }
    }
};
上面的代码是textcoder.hpp

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,int,text,实验,&&,include
From: https://www.cnblogs.com/xtc111/p/16817417.html

相关文章

  • 实验5:开源控制器实践——POX
    (一)基本要求1、h1pingh2、h2和h3的tcpdump抓包结果截图2、阅读L2_learning模块代码,使用tcpdump验证Switch模块。3、阅读L2_learning模块代码,画出程序流程图(二)进......
  • 实验5:开源控制器实践——POX
    1.基础要求a)使用tcpdump验证Hub模块,h1pingh2、h2和h3的tcpdump抓包结果截图b)使用tcpdump验证Switch模块,h1pingh2、h2和h3的tcpdump抓包结果截图c)L2_learni......
  • 实验2
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子for(......
  • Python第七章实验报告
    一.实验名称:《零基础学Python》第7章面向对象程序设计二.实验环境:IDLEShell3.9.7三.实验内容:5道实例、4道实战四.实验过程:实例01创建大雁类并定义飞行方法点......
  • GPIO之MIO按键中断实验
    1、INT_TYPE:指定中断类型→电平检测和边沿检测,INT_POLARITY指定高电平触发或者低电平触发;INT_ANY指定边沿触发,可选择同时触发 2、INT_STAT:中断状态寄存器,写1清楚中断,也可......
  • 实验一:决策树算法实验
    【实验目的】理解决策树算法原理,掌握决策树算法框架;理解决策树学习算法的特征选择、树的生成和树的剪枝;能根据不同的数据类型,选择不同的决策树算法;针对特定应用场景及......
  • 实验4:开源控制器实践——OpenDaylight与实验5:开源控制器实践——POX
    实验4:开源控制器实践——OpenDaylight一、实验目的1.能够独立完成OpenDaylight控制器的安装配置;2.能够使用Postman工具调用OpenDaylightAPI接口下发流表。二、实验环境......
  • 实验三
    实验任务五info.hpp:1#pragmaonce2#include<iostream>3#include<iomanip>4usingnamespacestd;5classinfo{6stringnickname;7strin......
  • 实验5:开源控制器实践----POX
    搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)阅读Hub模块代码,使用tcpdump验证Hub模块;阅读L2_learning模块代码,画出程序流程......
  • 实验二
    #include<stdio.h>#include<math.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......