首页 > 其他分享 >实验三

实验三

时间:2022-10-26 13:25:28浏览次数:62  
标签:info city string int text 实验 include

task5:

info.hpp:

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

class info{
    private:
        string nickname;
        string contact;
        string city;
        int n;
    public:
        info(){}
        info(string name,string cont,string city,int n):
        nickname(name),contact(cont),city(city),n(n){}
        ~info(){}
            
        void print() const;    
};
void info::print() const
{
    cout << "昵称:    \t\t"  << nickname << endl;
    cout << "联系方式:\t\t"  << contact << endl;
    cout << "所在城市:\t\t"  << city << endl;
    cout << "预定人数:\t\t"  << n << endl; 
    cout << endl;
}

 

task5.cpp:

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

 

 

task6:

textcoder.hpp:

 

#pragma once
#include<iostream>
#include<string>
using namespace std;
class TextCoder{
    public:
        TextCoder(){}
        TextCoder(string te) :text{te}{}
        ~TextCoder(){}
        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.length(); i++) {
        if (text.at(i)>= 'a' && text.at(i)<= 'z')
            text.at(i)= (text.at(i) - 'a' + 5) % 26 + 'a';
        if (text.at(i)>= 'A' && text.at(i) <= 'Z')
            text.at(i)= (text.at(i) - 'A' + 5) % 26 + 'A';
        }
    }
void TextCoder::decoder() {
    for (int i = 0; i < text.length(); i++) {
        if (text.at(i)>= 'a' && text.at(i)<= 'z')
            text.at(i)= (text.at(i) - 'a' +21) % 26 + 'a';
        if (text.at(i)>= 'A' && text.at(i)<= 'Z')
            text.at(i)= (text.at(i) - 'A' +21) % 26 + 'A';
    }
}
 

 

 

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,city,string,int,text,实验,include
From: https://www.cnblogs.com/1539238856cy/p/16805963.html

相关文章

  • 实验环境安装配置
    实验环境安装配置......
  • 实验3 数组、指针与现代c++标准库
    实验任务5info.hpp#pragmaonce#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classinfo{public:info(stringname,string......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。实验要求基......
  • 实验7:基于REST API的SDN北向应用实践
    实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。实验要求(一)基本要求1.编写Python程序,调用OpenDayli......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实......
  • 实验7:基于REST API的SDN北向应用实践
    目录一、实验目的二、实验环境三、实验要求(一)基本要求(二)进阶要求四、个人总结一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调......
  • 实验三
    #pragmaonce#include<iostream>#include<string>#include<iomanip>#include<vector>usingnamespacestd;classinfo{public:info(stringN......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据。delete......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境1.下载虚拟机软件OracleVisua......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验要求(一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表......