首页 > 其他分享 >第三次实验

第三次实验

时间:2022-10-24 22:34:00浏览次数:40  
标签:city 第三次 int text 实验 include nickname string

实验五

hpp

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

cpp

 1 #include"info.hpp"
 2 #include<iostream>
 3 #include<vector>
 4 #include <iomanip>
 5 using namespace std;
 6 int main()
 7 {
 8     
 9      const  int  capacity=100;
10      string a, b, c;
11      int n;
12      int sum = 0;
13      int count = 0;
14      vector<info> audience_info_list(100);
15      int i = 0;
16  flag:
17      cout << left << setw(10) << "昵称" << setw(10) << "联系方式(邮箱/手机号)" << setw(10) << "所在城市"
18          << setw(10) << "预定参加人数" << endl;
19     while (cin>>a>>b>>c>>n)
20      { 
21         sum += n;
22         if (sum <= capacity)
23         {
24             audience_info_list[count].set(a, b, c, n);
25             count++;
26         }
27         else
28         {
29             sum -= n;
30             int other = capacity - sum;
31             cout << "对不起只剩" << other << "个座位" << endl;
32             string choice;
33             cout << "1.输入u,更新(update)预定信息。" << endl;
34             cout << "2.输入q,退出预定。" << endl;
35             cin >> choice;
36             cout << "你的选择:" << choice << endl;
37             if (choice == "q")
38             {
39 
40                 cout << "已退出预定!";
41                 return 0;
42             }
43             else
44             {
45                 cout << "重新开始预定:" << endl;
46                 goto flag;
47             }
48         }
49      }
50     cout << "截至目前,一共有" << sum << "位听众预定参加。预定听众信息如下:" << endl;
51     while (i < count)
52     {
53         audience_info_list[i].print();
54         i++;
55     }
56      
57      
58 }

 

 

实验六

hpp

#pragma once

#include<iostream>
using namespace std;
class TextCoder
{
public:
    TextCoder(string text)
    {
        this->text = text;
    }
    string  get_ciphertext();
    string get_deciphertext();
private:
    string text;
    void encoder();
    void decoder();
    
};
void TextCoder::encoder()
{
    for (int i = 0;text[i] != '\0';i++)
    {
        if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z'))
        {
text[i] += 5;
        if (text[i] > 122 || (text[i] > 90) && text[i] <= 95)
        {
            text[i] -= 26;
        }
        }
        
    }
}
void TextCoder::decoder()
{
    
    for (int i = 0;text[i] != '\0';i++)
    {
        if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z'))
        {
            text[i] -= 5;
                if (text[i] < 65 || (text[i]>=92&&text[i] < 97))
                {
                    text[i] += 26;
                }
        }
    }
}
string TextCoder::get_ciphertext()
{
    encoder();
    return  text;
}
string TextCoder::get_deciphertext()
{
    decoder();
    return  text;
}

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 }

 

标签:city,第三次,int,text,实验,include,nickname,string
From: https://www.cnblogs.com/pdywsf/p/16823295.html

相关文章

  • 实验三
    #pragmaonce#include<iostream>#include<vector>#include<string>#include<iomanip>usingnamespacestd;classInfo{public:Info(){}Info(string......
  • 实验2
    实验1#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)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight。(2)下发指令删除s1上的流表数据#!/us......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0,i<N,i++)......
  • 实验5:开源控制器实践——POX
    一、实验目的1.能够理解POX控制器的工作原理;2.通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;3.能够运用POX控制器编写自定......
  • 实验7:基于REST API的SDN北向应用实践
    (一)基本要求编写Python程序,调用OpenDaylight的北向接口实现以下功能(1)利用Mininet平台搭建下图所示网络拓扑,并连接OpenDaylight;(2)下发指令删除s1上的流表数据。import......
  • 实验3
    task51#include<iostream>2#include<vector>3#include<string>4#include<iomanip>5usingnamespacestd;6classInfo{7friendvoidprint(vect......
  • 实验一:决策树算法实验
    博客班级https://edu.cnblogs.com/campus/czu/classof2020BigDataClass3-MachineLearning作业要求https://edu.cnblogs.com/campus/czu/classof2020BigDataClass......
  • 实验二
    test1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){......
  • 实验5:开源控制器实践——POX
    (一)基本要求1.搭建下图所示SDN拓扑,协议使用OpenFlow1.0,控制器使用部署于本地的POX(默认监听6633端口)sudomn--topo=single,3--mac--controller=remote,ip=127.0.0.1,......