首页 > 其他分享 >实验三

实验三

时间:2022-10-25 17:57:50浏览次数:32  
标签:info ch string int text 实验 include

实验 任务5 info.hpp

 1 #pragma once
 2 #include<iostream>
 3 #include<string>
 4 #include<vector>
 5 using namespace std;
 6 class info {
 7 private:
 8     string nickname;
 9     string contact;
10     string city;
11     int   n;
12     //static int m;
13 public:
14     info(string nickname0=0, string contact0=0, string city0=0, int  n0=0) :nickname{ nickname0 }, contact{ contact0 }, city{ city0 }, n{ n0 } {}
15     void print();
16 };
17 //int info::m = 0;
18 void info::print() {
19     std::cout << "昵称:       " << nickname << endl;
20     std::cout << "联系方式:  " << contact << endl;
21     std::cout << "所在城市:  " << city << endl;
22     std::cout << "预定人数:  " << n << endl;
23     std::cout << endl;
24 }

实验任务5 源文件

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

实验任务6.hpp

 1 #pragma once
 2 #include<iostream>
 3 #include<string>
 4 using namespace std;
 5 class TextCoder
 6 {
 7 private:
 8 
 9     string text;
10     void encoder();
11     void decoder();
12 public:
13     TextCoder(string text0) :text{ text0 } {}
14     TextCoder(TextCoder& t) :text{ t.text } {}
15     TextCoder() {}
16     string get_ciphertext() { encoder(); return text; }
17     string get_deciphertext() { decoder(); return text; }
18 };
19 void TextCoder::encoder()
20 {
21     for (auto& ch : text)
22     {
23         if ((ch >= 'a' && ch < ='v')||(ch>='A'&&ch<='V'))
24             ch = ch + 5;
25         else if (ch >= 'v' && ch <= 'z')
26             ch = ch + 5 - 'a';
27         else if(ch >= 'V' && ch <= 'Z')
28             ch = ch + 5 - 'A';
29     }
30 }
31 void TextCoder::decoder() {
32     for (auto& ch : text)
33     {
34         if ((ch >= 'f' && ch <= 'z') || (ch >= 'F' && ch <= 'Z'))
35             ch = ch - 5;
36         else if (ch >= 'a' && ch <= 'e')
37             ch = ch - 5 +'a';
38         else if (ch >= 'A' && ch <= 'E')
39             ch = ch - 5 +'A';
40     }
41 }

实验任务6 cpp

#include<iostream>
#include"textcoder.hpp"
#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,ch,string,int,text,实验,include
From: https://www.cnblogs.com/aomijia/p/16825703.html

相关文章

  • 实验三
    1#include<iostream>2#include<string>3#include<iomanip>4usingnamespacestd;5classInfo6{7public:8Info(){}9Info(stringx,......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境Ubuntu20.04Desktopamd64......
  • Optimize(优化实验)
    十大优化法则1.更快(本课程重点!)2.更省(存储空间、运行空间)3.更美(UI交互)4.更正确(本课程重点!各种条件下)5.更可靠6.可移植7.更强大(功能)8.更方便(使用)9.更范(格式符合编......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践(一)基本要求1.编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)......
  • pintos实验多级页表结构的应用
    pintos实验多级页表结构的应用------------由线性地址找物理地址图中给出了二级表的查找过程。其中CR3寄存器指定页目录表的基地址。线性地址的高10位用于索引这个页目......
  • 实验三
     #include<iostream>#include<string>usingstd::string;usingstd::cout;usingstd::cin;usingstd::endl;classInfo{public:Info(stringni="",stri......
  • 实验3 数组、指针与现代C++标准库
    实验任务5:info.hpp文件源码 1#pragmaonce2#include<string>3#include<iostream>4#include<iomanip>5usingnamespacestd;6classinfo{7pub......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践(一)基本要求1、编写Python程序,调用OpenDaylight的北向接口实现以下功能:(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDayligh......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N......
  • 实验7:基于REST API的SDN北向应用实践
    一、基本要求:①、编写Python程序,调用OpenDaylight的北向接口实现以下功能:1、删除s1上的流表数据代码及其截图:#!/usr/bin/pythonimportrequestsfromrequests.authim......