首页 > 其他分享 >实验三

实验三

时间:2022-10-23 20:57:48浏览次数:41  
标签:string int text 实验 && include textcoder



#include"Info.hpp"
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;
static int t = 0;
const int capacity = 100;
int main()
{
    vector<Info> audience_info_list;
    string nickname0, contact0, city0;
    int n;
    cout << "录入信息:\n\n" << left << setw(10) << "昵称" 
        <<setw(14) << "联系方式" 
        << setw(14) << "所在城市"
    << setw(14) << "参加人数" << endl;
    while (cin >> nickname0)
    {
        cin >> contact0 >> city0 >> n;
        if (t + n <= capacity)
        {
            Info tmp(nickname0, contact0, city0, n);
            audience_info_list.push_back(tmp);
            t += n;
            if (t == capacity)
                break;
        }
        else
        {
            cout << "对不起,只剩" << capacity - t << "个位置." << endl
                << "1.输入u,更新(update)预定信息" << endl
                << "2.输入q,退出预定" << endl
                << "你的选择:";
            char ch;
            cin >> ch;
            if (ch == 'u')
                cout << "请重新输入:" << endl;
            else
            {
                cout << endl;
                break;
            }
        }
    }
    cout << "截至目前,一共有" << t << "位听众预定参加。预定观众信息如下:" << endl;
    for (auto& list : audience_info_list)
        list.print();
    return 0;
}
#include<iostream>
#include<string>

using namespace std;

class Info
{
private:
    string nickname;
    string contact;
    string city;
    int n;
public:
    Info(string nickname0, string contact0, string city0, int n0) :nickname(nickname0), contact(contact0), city(city0), n(n0) {}
    void print() const {
        std::cout << "称呼:\t\t\t" << nickname << endl;
        std::cout << "联系方式:\t\t" << contact << endl;
        std::cout << "所在城市:\t\t" << city << endl;
        std::cout << "预定人数:\t\t" << n << endl;
    }
    ~Info() = default;

};

 

 

 

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

class textcoder
{
public:
    textcoder(string text0){ text = text0;}
    string get_ciphertext();
    string get_deciphertext();
private:
    void encoder();
    void decoder();
    string text;
};
string textcoder::get_ciphertext(){
    encoder();
    return text;
}
string textcoder::get_deciphertext(){
    decoder();
    return text;
}
void textcoder::encoder(){
    for (int i = 0; i < text.length(); i++){
        if ((text[i] >= 'a' && text[i] <= 'u') || (text[i] >= 'A' && text[i] <= 'U')){
            text[i] += 5;
        }
        else if ((text[i] >= 'v' && text[i] <= 'z') || (text[i] >= 'V' && text[i] <= 'Z'))
{
            text[i] -= 21;
        }
    }
}

void textcoder::decoder()
{
    for (int i = 0; i < text.length(); i++)
    {
        if ((text[i] >= 'a' && text[i] <= 'e') || (text[i] >= 'A' && text[i] <= 'E'))
        {
            text[i] += 21;
        }
        else if ((text[i] >= 'f' && text[i] <= 'z') || (text[i] >= 'F' && text[i] <= 'Z'))
        {
            text[i] -= 5;
        }
    }
}

 

标签:string,int,text,实验,&&,include,textcoder
From: https://www.cnblogs.com/hjr123/p/16819383.html

相关文章

  • 实验5:开源控制器实践——POX
    基本要求1.阅读Hub模块代码,使用tcpdump验证Hub模块;2.阅读L2_learning模块代码,画出程序流程图,使用tcpdump验证Switch模块;进阶要求1.重新搭建(一)的拓扑,此时交换机......
  • 实验I
    一,在c++中实现清屏:  system("cls"); 需要用到头文件 #include<iostream> 二, 在c++中改变字体和颜色: system("colorXY"); , 其中X为背景颜色,Y为字体颜色。(......
  • 实验3
    实验任务5Info.hpp文件源码#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classInfo{public:Info(stringname,stri......
  • 实验7:基于REST API的SDN北向应用实践
    基础要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据importre......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;+......
  • 实验2 C语言控制语句应用编程
    1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45intmain()6{7srand(time(0));89intdate=rand()......
  • Centos安装lnmp,云起实验室
    1.执行如下命令,下载并安装MySQL官方的YumRepository。wget-ihttp://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmyum-yinstallmysql57-comm......
  • Python实验报告(第7周)
    实验7:面向对象程序设计一、实验目的和要求1、了解面向对象的基本概念(对象、类、构造方法);2、学会类的定义和使用;3、掌握属性的创建和修改;4、掌握继承的基本语法。 ......
  • 实验五
    1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)2.阅读Hub模块代码,使用tcpdump验证Hub模块;3.阅读L2_learning模块代码,画出程序......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......