Textcoder.hpp
#include<iostream> #include<string> using namespace std; class Textcoder { public: Textcoder(string t); string get_ciphertext(); string get_deciphertext(); private: string text; void encoder(); void decoder(); }; Textcoder::Textcoder(string t) { text = t; } string Textcoder::get_ciphertext() { encoder(); return text; } string Textcoder::get_deciphertext() { decoder(); return text; } void Textcoder::encoder() { for (auto& t : text) { if (t >= 'a' && t <= 'z') { t = (t - 'a' + 7) % 26 + 'a'; } if (t >= 'A' && t <= 'Z') { t = (t - 'A' + 7) % 26 + 'A'; } } } void Textcoder::decoder() { for (auto& m : text) { if (m >= 'a' && m <= 'z') { m = 'z' - ('z' - m + 7) % 26; } if (m >= 'A' && m <= 'Z') { m = 'Z' - ('Z' - m + 7) % 26; } } }
cpp
#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(); }
5.hpp
#pragma once #include<iostream> #include<string> #include<vector> using namespace std; class Info { public: Info(string nick, string con, string c, int m); void print(); private: string nickname, contact, city; int n; }; Info::Info(string nick, string con, string c, int m) { nickname = nick; contact = con; city = c; n = m; } void Info::print() { cout << "昵称:" << nickname << endl; cout << "联系方式:" << contact << endl; cout << "城市:" << city << endl; cout << "预定人数:" << n << endl; }
cpp
#include <iostream> #include <string> #include <vector> #include "info.hpp" using namespace std; int main() { int const capacity = 100; int s = 0, n, i; char m; string nickname, contact, city; vector<Info>audience_info_list; vector<Info>& v = audience_info_list; cin >> i; while (i) { cin >> nickname >> contact >> city >> n; if (s + n <= capacity) { Info a(nickname, contact, city, n); v.push_back(a); s = s + n; a.print(); } else { cout << "对不起,还剩" << capacity - s << endl; cout << "输入u, 更新预定信息" << endl; cout << "输入q,退出预定" << endl; cout << "你的选择" << endl; cin >> m; if (m == 'q') { break; } if (m == 'u') { continue; } } } for (int z = 0;z < v.size();z++) { v[i].print(); } }
标签:string,int,text,void,实验,include,Textcoder From: https://www.cnblogs.com/32re/p/17865965.html