首页 > 其他分享 >实验三

实验三

时间:2022-10-25 17:24:20浏览次数:32  
标签:Info city string text void 实验 include

 1 #include <iostream>
 2 #include <string>
 3 #include <iomanip>
 4 using namespace std;
 5 class Info
 6 {
 7 public:
 8     Info() {}
 9     Info(string x, string y, string z, int num) : nickname{x}, contact{y}, city{z}, n{num} {}
10     ~Info() {}
11     void set_nickname(string m)
12     {
13         nickname = m;
14     }
15     void set_contact(string r)
16     {
17         contact = r;
18     }
19     void set_city(string p)
20     {
21         city = p;
22     }
23     void set_n(int e)
24     {
25         n = e;
26     }
27     void print()
28     {
29         cout << left << setw(8) << "昵称:" << nickname << endl;
30         cout << left << setw(8) << "联系方式:" << contact << endl;
31         cout << left << setw(8) << "所在城市:" << city << endl;
32         cout << left << setw(8) << "预定人数:" << n << endl;
33     }
34 
35 private:
36     string nickname, contact, city;
37     int n;
38 };
 1 源文件
 2 #include <iostream>
 3 #include <vector>
 4 #include "info.h"
 5 
 6 using namespace std;
 7 
 8 void test()
 9 {
10     const int capacity=100;
11     vector<Info> audience_info_list;
12     int n, sum = 0;
13     string name, number, city;
14     cout << "录入信息\n" << endl;
15     cout << "昵称\t" << "联系方式(邮箱/手机号)\t" << "所在城市\t" << "预定参加人数" << endl;
16     while (cin >> name)
17     {
18         cin >>number ;
19         cin >> city;
20         cin >> n;
21         sum = sum + n;
22         if (capacity >= sum)
23         {
24             Info T = Info(name, number, city, n);
25             audience_info_list.push_back(T);
26         }
27         else
28         {
29             string x;
30             sum = sum - n;
31             cout << "对不起,只剩" << capacity-sum << "个位置."<<endl;
32             cout << "1.输入u,更新(update)预定信息" << endl;
33             cout << "2.输入q,退出预定" << endl;
34             cout << "你的选择:"<< endl;
35             cin >> x;
36             if (x == "u")
37             {
38                 cout << "录入信息\n" << endl;
39                 cout << "昵称\t" << "联系方式(邮箱/手机号)\t" << "所在城市\t" << "预定参加人数" << endl;
40                 continue;
41             }
42             else if (x == "q")
43             {
44                 break;
45             }
46         }
47         if (sum == capacity) break;
48     }
49     cout << "截至目前,一共有" << sum << "位听众预定参加。预定听众信息如下:" << endl;
50     for (int j = 0; j < audience_info_list.size(); j++)
51     {
52         audience_info_list.at(j).print();
53     }
54 }
55 
56 int main()
57 {
58     test();
59 }
60 头文件
61 #pragma once
62 #include <iostream>
63 
64 using namespace std;
65 
66 class Info
67 {
68 public:
69     Info();
70     Info(string nickname,string contact,string city,int n):nickname{ nickname },contact{ contact },city{ city },n{n}{}
71     void print();
72 private:
73     string nickname, contact, city;
74     int n;
75 };
76 
77 void Info::print()
78 {
79     cout << "昵称:\t  \t" << nickname << endl;
80     cout << "联系方式:\t" << contact << endl;
81     cout << "所在城市:\t" << city << endl;
82     cout << "预定人数:\t" << n << endl;
83 }

 

 

 

 实验三 task6

 1 1 #pragma once
 2  2 #include <iostream>
 3  3 #include <string>
 4  4 
 5  5 using namespace std;
 6  6 
 7  7 class TextCoder {
 8  8 private:
 9  9     string text;
10 10     void encoder();
11 11     void decoder();
12 12 
13 13 public:
14 14     TextCoder(string text0) : text{ text0 } {}
15 15     string get_ciphertext() ;
16 16     string get_deciphertext() ;
17 17 };
18 18 
19 19 void TextCoder::encoder() {
20 20     for (int i=0;i<text.length();i++)
21 21     {
22 22         if (text.at(i) >= 'a' && text.at(i) <= 'u')
23 23             text.at(i) += 5;
24 24         else if (text.at(i) >= 'v' && text.at(i) <= 'z')
25 25             text.at(i) -= 21;
26 26         else if (text.at(i) >= 'A' && text.at(i) <= 'U')
27 27             text.at(i) += 5;
28 28         else if (text.at(i) >= 'V' && text.at(i) <= 'Z')
29 29             text.at(i) -= 21;
30 30         
31 31     }
32 32 }
33 33 
34 34 void TextCoder::decoder() {
35 35     for (int i=0;i<text.length();i++)
36 36     {
37 37         if (text.at(i) >= 'f' && text.at(i) <= 'z')
38 38             text.at(i) -= 5;
39 39         else if (text.at(i) >= 'a' && text.at(i) <= 'e')
40 40             text.at(i) += 21;
41 41         else if (text.at(i) >= 'F' && text.at(i) <= 'Z')
42 42             text.at(i) -= 5;
43 43         else if (text.at(i) >= 'A' && text.at(i) <= 'E')
44 44             text.at(i) += 21;
45 45 
46 46     }
47 47 }
48 48 
49 49 string TextCoder::get_ciphertext() {
50 50     encoder();
51 51     return text;
52 52 }
53 53 
54 54 string TextCoder::get_deciphertext() {
55 55     decoder();
56 56     return text;
57 57 }
58 
59 TextCoder.hpp

 

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

运行测试截图

 

 

 

标签:Info,city,string,text,void,实验,include
From: https://www.cnblogs.com/yy-L886/p/16825548.html

相关文章

  • 实验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......
  • 实验2 C语言控制语句应用编程
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i)......