实验五
info.hpp
#pragma once #include<iostream> #include<string> using namespace std; class info { public: info(string ni0, string co0, string ci0, int n0) : nickname(ni0), contact{ co0 }, city{ ci0 }, n{ n0 } {} void print(); private: string nickname; string contact; string city; int n; }; void info::print() { cout << "昵称: " << nickname << endl; cout << "联系方式: " << contact << endl; cout << "所在城市: " << city << endl; cout << "预定人数: " << n << endl << endl;; }
tesk5.cpp
#include"info.hpp" #include<iostream> #include<string> #include<vector> int main() { const int capacity = 100; vector<info> audience_info_list; cout << "录入信息:\n" << endl; cout << "昵称 " << "联系方式(邮箱/手机号) "<< "所在城市 "<< "预定参加人数" << endl; string name, con, ci, chance = "u"; int count = 0; int add = 0, sum; while (chance == "u" && cin >> name && add<capacity) { cin >> con >> ci >> count; sum = add; add = add + count; info in = info(name, con, ci, count); audience_info_list.push_back(in); if (add > capacity) { audience_info_list.pop_back(); add = sum; cout << "对不起,只剩" << capacity - sum << "个位置." << endl; cout << "1.输入u,更新(update)预定信息\n2.输入q,退出预定.\n你的选择:"; cin >> chance; } } cout << "截至目前,一共有" << add << "位听众预定参加。预定听众信息如下:" << endl; for (int i = 0; i < audience_info_list.size(); i++) audience_info_list.at(i).print(); }
实验六
TestCoder.hpp
#include <iostream> #include <string> #include <cctype> using namespace std; class TextCoder { public: TextCoder(string str):text(str) {} string get_ciphertext(); string get_deciphertext(); private: string text; void encoder(); void decoder(); }; void TextCoder::encoder() { for(auto &c: text) { if(c <= 'u' && c >= 'a' || c <= 'U' && c >= 'A') { c = c + 5; } else if(c > 'u' && c <= 'z' || c > 'U' && c <= 'Z') { c = c - 21; } } } void TextCoder::decoder() { for(auto &c: text) { if(c <= 'z' && c >= 'f' || c <= 'Z' && c >= 'F') { c = c - 5; } else if(c >= 'a' && c < 'f' || c >= 'A' && c < 'F') { c = c + 21; } } } string TextCoder::get_ciphertext() { encoder(); return text; } string TextCoder::get_deciphertext() { decoder(); return text; }
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,string,text,void,add,实验,include From: https://www.cnblogs.com/yzhag/p/16816072.html