task5:
info.hpp:
#include<iostream> #include<vector> #include<string> #include<iomanip> using namespace std; class info{ private: string nickname; string contact; string city; int n; public: info(){} info(string name,string cont,string city,int n): nickname(name),contact(cont),city(city),n(n){} ~info(){} void print() const; }; void info::print() const { cout << "昵称: \t\t" << nickname << endl; cout << "联系方式:\t\t" << contact << endl; cout << "所在城市:\t\t" << city << endl; cout << "预定人数:\t\t" << n << endl; cout << endl; }
task5.cpp:
#include <iostream> #include<vector> #include"info.hpp" #include<iomanip> using namespace std; int main() { const int capacity = 100; string name,cont,city; int n,sum; int count = 0; vector<info> audience_info_list; cout << "录入信息: " << endl; cout << endl; cout << "昵称\t\t" << "联系方式(邮箱/手机号)\t\t" << "所在城市\t\t" << "预定参加人数 " << endl; while(cin >> name){ cin >> cont >> city >> n; count = count + n; sum = capacity - count; if(sum > 0||sum == 0){ info io = info(name,cont,city,n); audience_info_list.push_back(io); } else{ string wise; count = count -n; sum = capacity - count; cout << "对不起,只剩" << sum << "个位置." << endl; cout << "1.输入u,更新(update)预定信息" << endl; cout << "2.输入q,退出预定" << endl; cout << "你的选择:"; cout << endl; cin >> wise; if(wise == "q") break; else if(wise == "u"){ cout << "录入信息:" << endl; continue; } } if (sum == capacity) break; } cout << "截至目前,一共有" << count << "位听众预定参加。预定听众信息如下:" << endl; for(int i = 0;i < audience_info_list.size();i++) audience_info_list.at(i).print(); }
task6:
textcoder.hpp:
#pragma once #include<iostream> #include<string> using namespace std; class TextCoder{ public: TextCoder(){} TextCoder(string te) :text{te}{} ~TextCoder(){} string get_ciphertext(){encoder(); return text;} string get_deciphertext(){decoder();return text;} private: string text; void encoder(); void decoder(); }; void TextCoder::encoder(){ for (int i = 0; i < text.length(); i++) { if (text.at(i)>= 'a' && text.at(i)<= 'z') text.at(i)= (text.at(i) - 'a' + 5) % 26 + 'a'; if (text.at(i)>= 'A' && text.at(i) <= 'Z') text.at(i)= (text.at(i) - 'A' + 5) % 26 + 'A'; } } void TextCoder::decoder() { for (int i = 0; i < text.length(); i++) { if (text.at(i)>= 'a' && text.at(i)<= 'z') text.at(i)= (text.at(i) - 'a' +21) % 26 + 'a'; if (text.at(i)>= 'A' && text.at(i)<= 'Z') text.at(i)= (text.at(i) - 'A' +21) % 26 + 'A'; } }
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 << "加密后英文文本:\t" << encoded_text << endl; decoded_text = TextCoder(encoded_text).get_deciphertext(); cout << "解密后英文文本:\t" << decoded_text << endl; cout << "\n输入英文文本: "; } } int main() { test(); }
标签:info,city,string,int,text,实验,include From: https://www.cnblogs.com/1539238856cy/p/16805963.html