task5
string name1, contact1, city1, choice,obj; int n1,i; int count=0; vector<info> audience_info_list; cout << "录入信息:" << endl; cout << "昵称\t"; cout << "联系方式(邮箱/手机号)\t"; cout << "所在城市\t"; cout << "预定参加人数\t" << endl; while (cin >> name1>>contact1>>city1>>n1) { count += n1; if (capacity - count >= 0) { info p0 = info(name1, contact1, city1, n1); audience_info_list.push_back(p0); } else { count -= n1; cout << endl; cout << "对不起,只剩" << capacity - count << "个位置。" << endl; cout << "1.输入u,更新(update)预定信息" << endl; cout << "2.输入q,退出预定" << endl; cin >> obj; cout << "你的选择:" << obj << endl; if (obj == "u") continue; if (obj == "q") break; } } cout << endl; cout << "截至目前,一共有" << count << "位听众预定参加。预定听众信息如下:" << endl; for (int i = 0; i < audience_info_list.size(); i++) { audience_info_list.at(i).print(); cout << endl;
info.hpp
#include<stdio.h> #include<iostream> #include<string> #include<iomanip> using namespace std; class info { public: info(string name, string con, string ci, int nu) :nickname{ name }, contact{ con }, city{ ci }, n{ nu }{} void print() { cout << std::left << setw(15) <<"昵称:"<<nickname<<endl; cout << std::left << setw(15) << "联系方式:" << contact << endl; cout << std::left << setw(15) << "所在城市:" << city << endl; cout << std::left << setw(15) << "预定人数:" << n << endl; cout << endl; } private: string nickname; string contact; string city; int n; };
结果
task6
#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(); }
textcoder.hpp
#include<iostream> #include<string> #include <algorithm> using namespace std; class TextCoder { public: TextCoder(){} TextCoder(string t0) :text{ t0 } {} string get_ciphertext() { encoder(); return text; } string get_deciphertext() { decoder(); return text; } private: string text; void encoder() { int i; for (i = 0; i < text.length(); i++) { if (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) -= 21; } else if (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) -= 21; } } } void decoder() { int i; for (i = 0; i < text.length(); i++) { if (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) += 21; } else if (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) += 21; } } } };
结果
标签:info,string,text,实验,&&,include,cout From: https://www.cnblogs.com/qiumusu/p/16826801.html