首页 > 其他分享 >实验三

实验三

时间:2022-10-26 00:12:31浏览次数:34  
标签:Info string int text void 实验 include

task5:

Info.hpp

#pragma once

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

class Info {
public:
    Info(string nick,string cont,string cit,int n0) :nickname{nick},contact{cont},city{cit},n{n0}{}
    void print() const;

private:
    string nickname, contact, city;
    int n;
};
void Info::print() const{
    cout << left << setw(8) << "昵称:" << nickname<<endl;
    cout << left << setw(8) << "联系方式:" << contact<<endl;
    cout << left << setw(8) << "所在城市:" << city<<endl;
    cout << left << setw(8) << "预定人数:" << n<<endl;
    cout << endl;
}

task5.cpp

#include"Info.hpp"
#include<iostream>
#include<vector>
using namespace std;

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

测试结果1:

测试结果2:

task6

Textcoder.hpp

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

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

task6.cpp

#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,void,实验,include
From: https://www.cnblogs.com/Augusteleven/p/16826805.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境1.下载虚拟机软件OracleVisua......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......
  • 实验7:基于REST API的SDN北向应用实践
    目录(一)基本要求(二)进阶要求个人总结(一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;......
  • 实验7:基于REST API的SDN北向应用实践
    一、基础要求1.编写Python程序,调用OpenDaylight的北向接口下发指令删除s1上的流表数据importrequestsfromrequests.authimportHTTPBasicAuthif__name__=="......
  • 实验3
    task5stringname1,contact1,city1,choice,obj;intn1,i;intcount=0;vector<info>audience_info_list;cout<<"录入信息:"<<endl;cout......
  • 实验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){......