task5
#include<iostream> using namespace std; #include<iomanip> class Info { private: string nickname, contact, city; int n; public: Info(string a,string b,string c,int d):nickname(a),contact(b),city(c),n(d){} ~Info() = default; void Info_()const; }; void Info::Info_()const { cout << left << setw(9) << "昵称:" << nickname << endl; cout << left << setw(9) << "联系方式:" << contact << endl; cout << left << setw(9) << "所在城市:" << city << endl; cout << left << setw(9) << "预定人数:" << n << endl; cout << endl; }
#include"Info.hpp" #include<iostream> #include<iomanip> #include<vector> using namespace std; const int capacity = 100; int main() { vector<Info> audience_info_list; string a, b, c; static int count = 0; int m; char qu; cout << "录入信息:\n\n" << "昵称 " << "联系方式(邮箱/手机号) " << "所在城市 " << "预定参加人数" << endl; while (cin >>a) { cin >> b >> c >> m; if (count + m < capacity) { Info audience(a, b, c, m); audience_info_list.push_back(audience); count += m; if (m == capacity) break; } else { int left = capacity - count; cout << "对不起,只剩" << left << "个位置。" << endl; cout << "1.输入u,更新(update)预定信息。" << endl; cout << "2.输入q,退出预定。" << endl; cout << "你的选择:"; cin >> qu; if (qu == 'q') { cout << endl; break; } else continue; } } cout << "截至目前,一共有" << count << "位听众预定参与。预定听众信息如下:" << endl; for (auto item : audience_info_list) { item.Info_(); } }
task6
#include<iostream> #include<string> using namespace std; class TextCoder { public: TextCoder(string text); ~TextCoder() = default; string get_ciphertext(); string get_deciphertext(); private: string text; void encoder(); void decoder(); }; TextCoder::TextCoder(string a) :text(a) {} void TextCoder::encoder() { for (int i = 0; i < text.size(); i++) { if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z')) { text[i] += 5; if (text[i] > 'z' || (text[i] > 'Z' && text[i] < 'a')) text[i] -= 26; } } } void TextCoder::decoder() { for (int i = 0; i < text.length(); i++) { if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z')) { text[i] -= 5; if (text[i] < 'A' || (text[i] > 'Z' && text[i] < 'a')) text[i] += 26; } } } string TextCoder::get_ciphertext() { encoder(); return text; } string TextCoder::get_deciphertext() { decoder(); return text; }
#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(); }
标签:Info,string,int,text,实验,include,TextCoder From: https://www.cnblogs.com/Xl995/p/16814700.html