首页 > 其他分享 >实验三

实验三

时间:2022-10-22 17:15:19浏览次数:29  
标签:obj string text void 实验 && include

  • 实验任务五

info.hpp:

 1 #pragma once
 2 #include<iostream>
 3 #include<iomanip>
 4 using namespace std;
 5 class info {
 6     string nickname;
 7     string contact;
 8     string city;
 9     int n;//预定参加人数
10 public:
11     info(){}
12     info(string name0,string city0,string contact0,int n0):nickname(name0),contact(contact0),city(city0),n(n0){}
13     ~info(){}
14     void set_name(string x) { nickname = x; }
15     void set_city(string x) { city = x; }
16     void set_contact(string x) { contact = x; }
17     void set_num(int x) { n = x; }
18     void print();
19 };
20 void info::print() {
21     cout << setiosflags(ios::left);
22     cout << setw(20) << "昵称:"  << nickname << endl;;
23     cout << setw(20) << "联系方式:" << contact<<endl;
24     cout << setw(20) << "所在城市:" << city << endl;
25     cout << setw(20) << "预定人数:"  << n<<endl;
26 }

liveshow.cpp:

 1 #include"info.hpp"
 2 #include<iostream>
 3 #include<string>
 4 #include<vector>
 5 #include<iomanip>
 6 using namespace std;
 7 int main() {
 8     const int capacity = 100;
 9     vector<info> audience_info_list(100);
10     string t1, t2, t3, choose;
11     int t4,count=0,i=0,flag=1;
12     cout << "录入信息"<<endl<<endl;
13     cout << setiosflags(ios::left);
14     cout <<setw(20)<< "昵称" << setw(40) << "联系方式(邮箱/手机号)" << setw(20) << "所在城市"
15          << "预定参加人数" << endl;
16     while (cin>>t1>>t2>>t3>>t4)
17     {
18         if (t4 <= capacity - count) {
19             audience_info_list[i].set_name(t1);
20             audience_info_list[i].set_contact(t2);
21             audience_info_list[i].set_city(t3);
22             audience_info_list[i].set_num(t4);
23             i++;
24             count += t4;
25         }//if
26         else {
27             cout << "对不起,只剩" << capacity - count << "个位置" << endl;
28             cout << "1.输入u,更新(update),预定信息" << endl;
29             cout << "2.输入q,退出预定" << endl;
30             cout << "你的选择:  ";
31             while (cin >> choose) {
32                 if (choose == "q") {
33                     flag = 0;
34                     break;
35                 }
36                 else if (choose == "u") {
37                     cin >> t1 >> t2 >> t3 >> t4;
38                     if (t4 > capacity - count) {
39                         cout << "对不起,只剩" << capacity - count << "个位置" << endl;
40                         cout << "1.输入u,更新(update),预定信息" << endl;
41                         cout << "2.输入q,退出预定" << endl;
42                         cout << "你的选择";
43                         continue;
44                     }
45                     audience_info_list[i].set_name(t1);
46                     audience_info_list[i].set_contact(t2);
47                     audience_info_list[i].set_city(t3);
48                     audience_info_list[i].set_num(t4);
49                     i++;
50                     count += t4;
51                     break;
52                 }
53             }
54         }//else
55         if (flag == 0||count==capacity)
56             break;
57     }//while
58     cout << "截至目前,一共有" << count << "位听众预定参加,预定听众信息如下:" << endl;
59     for (int j = 0; j < i; j++)
60     {
61         audience_info_list[j].print();
62         cout << endl;
63     }
64 }

运行截图:

  • 实验任务六

Textcoder.hpp:

 1 #pragma once
 2 #include<iostream>
 3 #include<string>
 4 using namespace std;
 5 class TextCoder {
 6     string text;
 7     void encoder();
 8     void decoder();
 9 public:
10     TextCoder(){}
11     TextCoder(string text1):text{text1}{}
12     ~TextCoder(){}
13     string get_ciphertext() { encoder(); return text; }
14     string get_deciphertext() { decoder(); return text; }
15 };
16 void TextCoder::encoder() {
17     for (auto& obj : text) {
18         if ((obj >= 'a' && obj <= 'u') || (obj >= 'A' && obj <= 'U'))
19             obj += 5;
20         else if ((obj > 'u' && obj <= 'z') || (obj > 'U' && obj <= 'Z'))
21             obj = obj - 21;
22     }
23 }
24 void TextCoder::decoder() {
25     for (auto& obj : text) {
26         if ((obj >= 'f' && obj <= 'z') || (obj >= 'F' && obj <= 'Z'))
27             obj = obj - 5;
28         else if ((obj > 'a' && obj <= 'f') || (obj > 'A' && obj <= 'f'))
29             obj += 21;
30     }
31 }

task6.cpp:

 1 #include "textcoder.hpp"
 2 #include <iostream>
 3 #include <string>
 4 
 5 void test() {
 6     using namespace std;
 7 
 8     string text, encoded_text, decoded_text;
 9 
10     cout << "输入英文文本: ";
11     while (getline(cin, text)) {
12         encoded_text = TextCoder(text).get_ciphertext();
13         cout << "加密后英文文本:\t" << encoded_text << endl;
14 
15         decoded_text = TextCoder(encoded_text).get_deciphertext();
16         cout << "解密后英文文本:\t" << decoded_text << endl;
17         cout << "\n输入英文文本: ";
18     }
19 }
20 
21 int main() {
22     test();
23 }

运行截图:

 

标签:obj,string,text,void,实验,&&,include
From: https://www.cnblogs.com/zzzys/p/16816300.html

相关文章

  • 实验5:开源控制器实践----POX
    搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)阅读Hub模块代码,使用tcpdump验证Hub模块;阅读L2_learning模块代码,画出程序流程......
  • 实验二
    #include<stdio.h>#include<math.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......
  • 实验三
    实验五info.hpp#pragmaonce#include<iostream>#include<string>usingnamespacestd;classinfo{public:info(stringni0,stringco0,stringci0,intn......
  • 实验一:决策树算法实验
    实验一:决策树算法实验|博客班级|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小孩的游戏★实验任务一群小孩子在玩游戏,游戏......