首页 > 其他分享 >实验(3)

实验(3)

时间:2022-10-26 08:56:40浏览次数:37  
标签:Info 26 string text 实验 include cout

实验5

task_5.cpp

 1 #include"info.hpp"
 2 #include<vector>
 3 //#include<iomanip>
 4 
 5 int main(){
 6     using namespace std;
 7     const int capacity = 100;
 8     vector<Info>audience_info_list;
 9     cout << "录入信息:" << endl;
10     cout << endl;
11     cout << "昵称\t" << "联系方式(邮箱/手机号)\t" << "所在城市\t" << "预定参加人数\t" << endl;
12     string nickname;
13     string contact;
14     string city;
15     int n=0;
16     int sum = 0;
17     char k;
18     //录入信息
19     while (cin >> nickname) {
20         //cin>>nickname;
21         cin >> contact >> city >> n;
22         sum += n;
23 
24 
25         if (capacity - sum >= 0) {
26             Info temp = Info(nickname, contact, city, n);
27             audience_info_list.push_back(temp);
28         }
29         else {
30             sum = sum - n;
31             cout << "对不起,只剩" << capacity - sum << "个位置"<<endl;
32             cout << "1.输入u,更新(update)预定信息" << endl;
33             cout << "2.输入q,退出预定" << endl;
34             cout << "你的选择:";
35             cin >> k;
36             if (k == 'u') {
37                 continue;
38             }
39             else 
40                 if (k == 'q') { break; }
41 
42         }
43     }
44         cout << "截至目前,一共有" << sum << "位听众预定参加,预定听众信息如下:" << endl;
45         for (int i = 0; i < audience_info_list.size(); i++) {
46             audience_info_list.at(i).print();
47             cout << endl;
48         }
49 }

info.hpp

 1 #pragma once
 2 
 3 #include<iostream>
 4 #include<string>
 5 
 6 using std::cout;
 7 using std::endl;
 8 using std::string;
 9 
10 class Info{
11 public:
12     Info();
13     Info(string a,string b,string c ,int t):nickname{a},contact{b},city{c},n{t}{}
14     void print();
15 private:
16     string nickname;
17     string contact;
18     string city;
19     int n;
20 };
21 
22 Info::Info() {
23     nickname = "";
24     contact = "";
25     city = "";
26     n = 100;
27 }
28 
29 
30 void Info::print() {
31     cout << "昵称:        " << nickname << endl;
32     cout << "联系方式:    " << contact << endl;
33     cout << "所在城市:    " << city << endl;
34     cout << "预定人数:    " << n <<endl;
35 }

 

实验6

task_6.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 }

textcoder.hpp

 1 #pragma once
 2 
 3 #include<iostream>
 4 #include<string>
 5 
 6 using namespace std;
 7 
 8 class TextCoder {
 9 
10 public:
11     TextCoder(string t) :text{ t }{}
12      string get_ciphertext();
13      string get_deciphertext();
14 private:
15     string text;
16     void encoder() {
17         for (int i = 0; i < size(text); i++) {
18             if (text.at(i) <= 'z' && text.at(i) >= 'a') {
19                 text.at(i) = (text.at(i) -'a' + 5) % 26+'a';
20             }
21             if (text.at(i) <= 'Z' && text.at(i) >= 'A') {
22                 text.at(i) = (text.at(i) - 'A' + 5) % 26 + 'A';
23             }
24         }
25 
26     };
27     void decoder() {
28         for (int i = 0; i < size(text); i++) {
29             if (text.at(i) <= 'z' && text.at(i) >= 'a') {
30                 text.at(i) = (text.at(i) - 'a' - 5+26) % 26 + 'a';
31             }
32             if (text.at(i) <= 'Z' && text.at(i) >= 'A') {
33                 text.at(i) = (text.at(i) - 'A' - 5+26) % 26 + 'A';
34             }
35         }
36 
37     };
38 
39 };
40 string TextCoder::get_ciphertext() {
41     TextCoder::encoder();
42     return text;
43 }
44 string TextCoder::get_deciphertext() {
45     TextCoder::decoder();
46     return text;
47 }

 

标签:Info,26,string,text,实验,include,cout
From: https://www.cnblogs.com/zx1229/p/16827086.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    三、实验要求(一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验要求1.编写Python程序,调用OpenDayl......
  • 实验7:基于REST API的SDN北向应用实践
    基本要求1、编写Python程序,调用OpenDaylight的北向接口实现以下功能:(1)利用Mininet平台搭建拓扑,并连接OpenDaylight(2)下发指令删除s1上的流表数据代码delete.py#!/u......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBox或......
  • 实验三
    task5:Info.hpp#pragmaonce#include<iostream>#include<string>#include<iomanip>usingnamespacestd;classInfo{public:Info(stringnick,stringcont......
  • 实验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;......