首页 > 其他分享 >实验三

实验三

时间:2022-10-20 16:34:42浏览次数:43  
标签:string int text 实验 && include cout

实验任务5

#pragma once

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

class Info {
public:
    Info(string nickname1, string contact1, string city1, int n1) : nickname(nickname1), contact(contact1), city(city1), n(n1) {

    }

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

private:
    string nickname;
    string contact;
    string city;
    int n;
};
#include"Info.hpp"
#include<iostream>
#include<string>
#include<vector>
using namespace std;

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

 

实验任务6

#pragma once

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

class TextCoder {
public:
    TextCoder(string text1) : text(text1) {
    }
    string get_ciphertext() {
        return encoder();
    }
    string get_deciphertext() {
        return decoder();
    }

private:
    string text;

private:
    string encoder() {
        for (int i = 0; i < text.length(); i++) {
            if (text[i] >= 'a' && text[i] <= 'u')
                text[i] += 5;
            else if (text[i] >= 'v' && text[i] <= 'z')
                text[i] -= 21;
            else if (text[i] >= 'A' && text[i] <= 'U')
                text[i] += 5;
            else if (text[i] >= 'V' && text[i] <= 'Z')
                text[i] -= 21;
            else
                continue;
        }
        return text;
    }

    string decoder() {
        for (int i = 0; i < text.length(); i++) {
            if (text[i] >= 'f' && text[i] <= 'z')
                text[i] -= 5;
            else if (text[i] >= 'a' && text[i] <= 'e')
                text[i] += 21;
            else if (text[i] >= 'F' && text[i] <= 'Z')
                text[i] -= 5;
            else if (text[i] >= 'A' && text[i] <= 'E')
                text[i] += 21;
            else
                continue;
        }
        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();
}

 

标签:string,int,text,实验,&&,include,cout
From: https://www.cnblogs.com/Zhouzhou-/p/16810351.html

相关文章

  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够......
  • TFboy的实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));//以当前系统时间作为随机种子......
  • 实验五
    一、实验目的1、能够理解POX控制器的工作原理;2、通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3、能够运用POX控制器编写自定......
  • Python实验报告——第6章 函数
    实验报告实例01:输出每日一帖(共享版)代码如下:deffunction_tips():'''功能:每天输出一条励志文字'''importdatetime#导入日期时间类#定义......
  • python实验报告(函数)
    1.输出每日一站(共享版)  结果:   2.根据身高,体重计算BMI指数  结果:  3.根据身高,体重计算BMI指数  结果:  4.模拟结账功能———计算实付金......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.......
  • 实验五
    搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)阅读Hub模块代码,使用tcpdump验证Hub模块;阅读L2_learning模块代码,画出程......
  • 实验2 C语言控制语句应用编程
    实验一#include<math.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够......
  • 第六章实验报告
        实验报告   课程名称:Python语言实训项目: 第六章实例和实战实训班级:21信息与计算科学1班学生姓名:郑于佳学......