首页 > 其他分享 >实验3

实验3

时间:2022-10-25 23:35:26浏览次数:35  
标签:info string text 实验 && include cout

task5

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

info.hpp

#include<stdio.h>
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class info
{
public:
    info(string name, string con, string ci, int nu) :nickname{ name }, contact{ con }, city{ ci }, n{ nu }{}
    void print()
    {
        cout << std::left << setw(15) <<"昵称:"<<nickname<<endl;
        cout << std::left << setw(15) << "联系方式:" << contact << endl;
        cout << std::left << setw(15) << "所在城市:" << city << endl;
        cout << std::left << setw(15) << "预定人数:" << n << endl;
        cout << endl;
    }
private:
    string nickname;
    string contact;
    string city;
    int n;
};

结果

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();
}

textcoder.hpp

#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
class TextCoder
{
public:
    TextCoder(){}
    TextCoder(string t0) :text{ t0 } {}
    string get_ciphertext()
    {
        encoder();
        return text;
    }
    string get_deciphertext()
    {
        decoder();
        return text;
    }
private:
    string text;
    void encoder()
    {
        int i;
        for (i = 0; i < text.length(); i++)
        {
            if (text.at(i) >= 'a' && text.at(i) <= 'u') 
            {
                text.at(i) += 5;
            }
            else if (text.at(i) >= 'v' && text.at(i) <= 'z') 
            {
                text.at(i) -= 21;
            }
            else if (text.at(i) >= 'A' && text.at(i) <= 'U') 
            {
                text.at(i) += 5;
            }
            else if (text.at(i) >= 'V' && text.at(i) <= 'Z') 
            {
                text.at(i) -= 21;
            }
        }
    }
    void decoder()
    {
        int i;
        for (i = 0; i < text.length(); i++)
        {
            if (text.at(i) >= 'f' && text.at(i) <= 'z') 
            {
                text.at(i) -= 5;
            }
            else if (text.at(i) >= 'a' && text.at(i) <= 'e') 
            {
                text.at(i) += 21;
            }
            else if (text.at(i) >= 'F' && text.at(i) <= 'Z') 
            {
                text.at(i) -= 5;
            }
            else if (text.at(i) >= 'A' && text.at(i) <= 'E') 
            {
                text.at(i) += 21;
            }
        }
    }
};

结果

 

标签:info,string,text,实验,&&,include,cout
From: https://www.cnblogs.com/qiumusu/p/16826801.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    实验要求(一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接;搭建拓扑命令行输入sudomn--topo=sing......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验要求1.基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接Open......
  • 实验三 数组、指针与现代C++标准库
    实验五代码:info.hpp:#pragmaonce#include<iostream>usingnamespacestd;classinfo{public:info(stringni="",stringco="",stringci="",i......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......
  • 实验2
    1.#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北向应用实践
    一、基础要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据。代码......
  • 实验三
    TASK5:info.hpp#pragmaonce#include<iostream>#include<string>#include<iomanip>#include<vector>usingnamespacestd;classinfo{public:......
  • 实验7:基于REST API的SDN北向应用实践
    一、基本要求1、编写Python程序,调用OpenDaylight的北向接口实现以下功能下发指令删除s1上的流表数据。delete.py#!/usr/bin/pythonimportrequestsfromrequests.a......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基础要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;sudomn--topo=single,3--mac--cont......