Info.hpp文件源码

#include<iostream>
#include<string>
#include<iomanip> using namespace std; class Info {
public:
Info(){ }
Info(string name, string number, string w, int num) : nickname{ name }, contact{ number }, city{ w }, n{ num } { } void print() const
{
cout << left << setw(10) << "称呼:" << nickname << endl;
cout << setw(10) << "联系方式:" << contact << endl;
cout << setw(10) << "所在城市:" << city << endl;
cout << setw(10) << "预定人数:" << n << endl;
} private:
string nickname;
string contact;
string city;
int n;
};

task5.cpp源码

#include"Info.hpp"
#include<iostream>
#include<vector>
#include<string>
#include<limits> using namespace std; static int num = 0; int main()
{
vector<Info> audience_info_list;
string n_nickname, n_contact, n_city;
int n = 0;
const int capacity = 100; cout << "录入信息:\n" << endl;
cout << "称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" << endl;
while (cin >> n_nickname)
{
cin >> n_contact >> n_city >> n; if (n + num <= capacity)
{
Info audience(n_nickname, n_contact, n_city, n);
audience_info_list.push_back(audience);
num += n;
}
else
{
char input;
cout << "对不起,只剩" << capacity - num << "个位置。" << endl;
cout << "1.输出u,更新(update)预定信息" << endl;
cout << "2.输出q,退出预定" << endl;
cout << "你的选择: ";
cin >> input;
if (input == 'q')
{
break;
}
}
} cout << "截至目前,一共有" << num << "位听众预定参加。预定听众信息如下:" << endl; for (auto item : audience_info_list)
item.print();
}

运行测试结果截图

TextCoder.hpp文件源码

#include <iostream>
#include <string> using namespace std; class TextCoder
{
public:
TextCoder(string tex = NULL) : text{ tex } { }
string encoder()
{
for (auto& item : text)
{
if (item >= 'a' && item <= 'z')
item = 'a' + (item - 'a' + 5) % 26;
else if (item >= 'A' && item <= 'Z')
item = 'A' + (item - 'A' + 5) % 26;
}
return text;
} string decoder()
{
for (auto& item : text)
{
if (item >= 'a' && item <= 'z')
item = 'a' + (item - 'a' + (26 - 5)) % 26;
else if (item >= 'A' && item <= 'Z')
item = 'A' + (item - 'A' + (26 - 5)) % 26;
}
return text;
} private:
string text;
};

task6.cpp源码

#include "textcoder.hpp"
#include <iostream>
#include <string>
int main()
{
using namespace std;
string text, encoded_text, decoded_text;
cout << "输入英文文本: ";
while (getline(cin, text))
{
encoded_text = TextCoder(text).encoder(); // 这里使用的是临时无名对象
cout << "加密后英文文本:\t" << encoded_text << endl;
decoded_text = TextCoder(encoded_text).decoder(); // 这里使用的是临时无名对象
cout << "解密后英文文本:\t" << decoded_text << endl;
cout << "\n输入英文文本: ";
}
}

运行测试结果截图

最新文章

  1. fork函数创建新进程过程分析
  2. Java-继承 共3题
  3. Java对象的访问
  4. WampServer phpadmin apache You don&#39;t have permission to access
  5. python运维开发(十六)----Dom&amp;&amp;jQuery
  6. Art of Unit Test (1) - Breaking Dependency
  7. spring3.1........jar包下载
  8. 部署项目到weblogic时提示文件被锁,导致报错
  9. springMVC web项目 对访问数据库的用户名密码进行加密解密
  10. 14 Fragment 碎片总结
  11. 并发系列(2)之 ThreadLocal 详解
  12. VUE-001-在表格单元格(el-table-column)中添加超链接访问
  13. Java 中 this 和 super 的用法总结
  14. CSS 简介、 选择器、组合选择器
  15. C/C++中如何在main()函数之前执行一条语句?
  16. Python类和实例方法和属性的动态绑定
  17. Cocos Creator 使用protobufjs
  18. 企业面试题-find结合sed查找替换
  19. Java中==号与equals()方法的区别
  20. 进程控制块(PCB)

热门文章

  1. JAVA中使用最广泛的本地缓存?Ehcache的自信从何而来2 —— Ehcache的各种项目集成与使用初体验
  2. 2022USACO-DEC-Silver
  3. [Leetcode]完全平方数
  4. [cocos2d-x]关于坐标系
  5. [NOIP2017 普及组]跳房子 【题解】
  6. 本地文件上传 Gitee 和 GitHub
  7. Ubuntu下的LGT8F328P MiniEVB Arduino开发和烧录环境
  8. pycharm设置python头文件模版
  9. vue学习笔记(一)---- vue指令(在vue中使用样式的方式)
  10. 843. n-皇后问题