首页 > 其他分享 >实验三

实验三

时间:2022-10-22 14:44:51浏览次数:29  
标签:info string text void add 实验 include

实验五

info.hpp

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

class info {
public:
    info(string ni0, string co0, string ci0, int n0) : nickname(ni0), contact{ co0 }, city{ ci0 }, n{ n0 } {}
    void print();
private:
    string nickname;
    string contact;
    string city;
    int n;
};
void info::print() {
    cout << "昵称:     " << nickname << endl;
    cout << "联系方式: " << contact << endl;
    cout << "所在城市: " << city << endl;
    cout << "预定人数: " << n << endl << endl;;
}

  tesk5.cpp

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

 

 

 

 实验六

TestCoder.hpp

#include <iostream>
#include <string>
#include <cctype>
 
 using namespace std;
 class TextCoder {
 
 public:
     TextCoder(string str):text(str) {}
     string get_ciphertext();
     string get_deciphertext();
     
 private:
     string text;
     void encoder();
     void decoder();
     };
 void TextCoder::encoder() {
     for(auto &c: text) {
        if(c <= 'u' && c >= 'a' || c <= 'U' && c >= 'A') {
            c = c + 5;         } else if(c > 'u' && c <= 'z' || c > 'U' && c <= 'Z') {
             c = c - 21;
         }
     }
 }
 void TextCoder::decoder() {
     for(auto &c: text) {
         if(c <= 'z' && c >= 'f' || c <= 'Z' && c >= 'F') {
             c = c - 5;
        } else if(c >= 'a' && c < 'f' || c >= 'A' && c < 'F') {
            c = c + 21;
         }
     }
 }
 
 string TextCoder::get_ciphertext() {
     encoder();
     return text;
 }

 string TextCoder::get_deciphertext() {
     decoder();
    return text;
}

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,text,void,add,实验,include
From: https://www.cnblogs.com/yzhag/p/16816072.html

相关文章

  • 实验一:决策树算法实验
    实验一:决策树算法实验|博客班级|https://edu.cnblogs.com/campus/czu/classof2020BigDataClass3-MachineLearning||----|----|----||作业要求|https://edu.cnblogs.com/......
  • 实验5:开源控制器实践——POX
    实验5:开源控制器实践——POX一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够运......
  • 实验5:开源控制器实践——POX
    一、基础实验(1)tcpdump验证Hub模块h1-->h2和h1-->h3(2)tcpdump验证Switch模块h1-->h2和h1-->h3(3)L2_learning模块代码流程图二、进阶实验(1)进阶一(2)进阶二......
  • 《MiniPRO H750开发指南》第六十四章 综合测试实验
    第六十四章综合测试实验​为了方便大家使用和验证综合例程,本章内容是综合例程的使用介绍。目的是展示STM32H7的强大处理能力,并且可以测试开发板的大部分功能。本实验代码只......
  • 实验5:开源控制器实践——POX
    (一)基本要求(1)阅读Hub模块代码,使用tcpdump验证Hub模块;(2)阅读L2_learning模块代码,画出程序流程图,使用tcpdump验证Switch模块。流程图(二)进阶要求(1)重新搭建(一)的拓扑,此......
  • 实验5:开源控制器实践——POX
    一、实验目的能够理解POX控制器的工作原理;通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;能够运用POX控制器编写自定义网络......
  • 小孩的游戏 - 2021数据结构 排序和选择实验题
    小孩的游戏-2021数据结构排序和选择实验题pre做都做了,干脆发上来算了:D题目分析算法与数据结构实验题5.18小孩的游戏★实验任务一群小孩子在玩游戏,游戏......
  • 【计组实验】实验f1 mux21a
    一、实验目标测试mux21a二选一多路选择器的功能,并做出仿真波形。二、实验原理用VHDL代码实现mux21a二选一多路选择器的功能,用QuartusⅡ编译代码并展示元件图,最后制造波......
  • 【计组实验】实验f3 正弦信号发生器
    一、实验目标使用正弦波信号发生器,生成仿真波形。二、实验原理用VHDL代码完成正弦信号发生器以及data_rom的功能,生成一组正弦信号数据rom.mif。进行波形仿真,给正弦信号......
  • 【计组实验】实验f2 一位全加器
    一、实验目标测试全加器f_adder的功能,并做出仿真波形。二、实验原理全加器f_adder由两个半加器h_adder和一个或门or2a组成,先完成半加器和或门的VHDL代码,然后在全加器的V......