#program once
#include<iostream>
#include<string>
using namespace std;
class TextCoder{
private:
string text;
void encoder();
void decoder();
public:
TextCoder(string &str);
string get_ciphertext();
string get_deciphertext();
};
TextCoder::TextCoder(string &str){
text=str;
}
string TextCoder::get_ciphertext() {
encoder();
return text;
}
string TextCoder::get_deciphertext() {
decoder();
return text;
}
void TextCoder::encoder(){
for(auto &i : text){
if (i >= 'a' && i <= 'z')
i = 'a' + ((i -'a')+7) % 26;
else if (i >= 'A' && i <= 'Z')
i = 'A' + ((i -'A')+7) % 26;
}
}
void TextCoder::decoder() {
for (auto &i : text) {
if (i >= 'a' && i <= 'z')
i = 'a' + ((i -'a') + 26-7) % 26;
else if (i >= 'A' && i <= 'Z')
i = 'A' + ((i -'A') + 26-7) % 26;
}
}
#include "textcoder.hpp"
#include <iostream>
#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();
}
![]()
pragma once
#include <iostream>
#include <string>
#include<iomanip>
#include <vector>
using namespace std;
class Info {
private:
string nickname;
string contact;
string city;
int n;
public:
Info(const string &nickname, const string &contact, const string &city, int n);
void print() const;
};
Info::Info(const string &nick, const string &con, const string &ci, int nn): nickname{nick}, contact{con}, city{ci}, n{nn} {}
void Info::print() const {
cout << left << setw(15) << "昵称: " << nickname << endl;
cout << left << setw(15) << "联系方式: " << contact << endl;
cout << left << setw(15) << "所在城市: " << city << endl;
cout << left << setw(15) << "指定人数: " << n << endl;
}
#include "info.hpp"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int capacity = 100;
int main (){
vector<Info> audience_info_list;
string nick,con,ci;
int nn;
static int x =0;
cout << "录入信息:\n\n";
cout << "昵称 联系方式(邮箱/手机号) 所在城市 预定参加人数" << endl;
while (cin >> nick)
{
cin >> con >> ci >> nn;
if (x + nn <= capacity) {
Info tmp(nick, con, ci, nn);
audience_info_list.push_back(tmp);
x += nn;
if (x == capacity)
break;
}
else
{
char option;
cout << "对不起,只剩" << capacity - x << "个位置." << endl
<< "1. 输入u,更新(update)预定信息" << endl
<< "2. 输入q,退出预定" << endl
<< "你的选择:" << endl;
cin >> option;
if (option == 'u')
{
cout << "请重新输入:" << endl;
}
if (option == 'q')
{
cout << endl;
break;
}
}
}
cout << "\n截至目前,一共有" << x << "位听众预定参加。预定听众信息如下:" << endl;
for (const auto& list : audience_info_list)
list.print();
return 0;
}
![]()
![]()