info.hpp
#pragma once #include<iostream> #include<string> using namespace std; class Info { public: Info(string nn, string cont, string ct,int x); void print(); private: string nickname; string contact; string city; int n; }; Info::Info(string nn, string cont, string ct, int x) :nickname{ nn }, contact{ cont }, city{ ct }, n{ x } {} void Info::print() { cout << setw(16) << "昵称:" << nickname << endl << setw(16) << "联系方式:" << contact << endl << setw(16) << "所在城市:" << city << endl << setw(16) << "预定人数:" << n << endl<<endl; }
task.5cpp
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<iomanip> #include<limits> #include"info.hpp" #define MAX 100; using namespace std; int main() { const int capacity = MAX; vector<Info> audience_info_list; string nn,cont,ct; //具体信息 int num=0,sum=0; //录入信息 cout << "录入信息:\n\n"; cout << left << setw(16) << "昵称" << setw(30) << "联系方式(邮箱/手机号)" << setw(16) << "所在城市" << setw(12) << "预定参加人数" << endl; while (cin>>nn>>cont>>ct>>num) { //每输入一组信息,就尝试放到Info类数组中 sum += num; if (sum > capacity) { cout << "对不起,只剩" << capacity-sum + num << "个位置.\n"; sum -= num; cout << "1.输入u,更新(update)预定信息\n2.输入q,退出预定\n你的选择:"; char choice; cin >> choice; if (choice == 'u') { cout << "请输入更新预定信息:\n"; continue; } else if (choice == 'q') break; } else audience_info_list.push_back( Info (nn, cont, ct, num)); } //打印信息 cout <<endl<< "截至目前,一共有" << sum << "位听众参加。预定听众信息如下:\n"; for (auto& item : audience_info_list) item.print(); }
texthoder.hpp
#pragma once #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; } string text; void TextCoder::encoder() { for (int i = 0; i < text.size(); ++i) { if ((text.at(i) >= 'a' && text.at(i) <= 'u') || (text.at(i) >= 'A' && text.at(i)<='U')) text.at(i) += 5; else if ((text.at(i) >= 'v' && text.at(i) <= 'z') || (text.at(i) >= 'V' && text.at(i) <= 'Z')) text.at(i) -= 21; } } void TextCoder::decoder(){ for (int i = 0; i < text.size(); ++i) { if ((text.at(i) >= 'f' && text.at(i) <= 'z') || (text.at(i) >= 'F' && text.at(i) <= 'Z')) text.at(i) -= 5; else if ((text.at(i) >= 'a' && text.at(i) <= 'e') || (text.at(i) >= 'A' && text.at(i) <= 'E')) text.at(i) += 21; } }
task6.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 << "加密后英文文本:" << encoded_text << endl; decoded_text = TextCoder(encoded_text).get_deciphertext(); // 使用临时无名对象 cout << "解密后英文文本:" << decoded_text << endl; cout << "输入英文文本:"; } } int main() { test(); }
标签:string,int,text,实验,&&,include,TextCoder From: https://www.cnblogs.com/qazmlp10/p/16827256.html