info.h
#pragma once #include<iostream> #include<string> using namespace std; class info { public: info(string _nickname, string _contact, string _city, int _n) { nickname =_nickname; contact = _contact; city = _city; n = _n; } void print() { cout << "昵称: " << nickname << endl; cout << "联系方式: " << contact << endl; cout << "所在城市: " << city << endl; cout << "预定人数: " << n <<endl<<endl; } private: string nickname; string contact; string city; int n; };
test.cpp
#include<iostream> #include<string> #include<vector> #include"info.h" using namespace std; int main() { const int capacity = 100; vector<info> audience_info_list; cout << "录入信息:" << endl << endl; cout << "昵称 " << "联系方式(邮箱/手机号) " << "所在城市 " << "预定参加人数" << endl; int num = 0,_n,flag=0; string _nickname, _contact, _city; while (cin >> _nickname >> _contact >> _city >> _n) { while (_n + num > 100) { char choice; cout << "对不起,只剩" << capacity - num << "个位置" << endl; cout << "1. 输入u,更新预定信息" << endl; cout << "2.输入q,退出预定" << endl; cout << "你的选择:"; cin >> choice; if (choice == 'q') { flag = 1; break; } else { cin >> _nickname >> _contact >> _city >> _n; } } if (flag == 1) break; num += _n; info temp(_nickname, _contact, _city, _n); audience_info_list.push_back(temp); } cout << "截至目前,一共有" << num << "位听众预定参加,预定的观众信息如下:" << endl; for (auto e : audience_info_list) { e.print(); } return 0; }
textcoder.h
#pragma once #include<iostream> #include<string> using namespace std; class TextCoder { public: TextCoder(const string& obj = ""); string get_ciphertext(); string get_deciphertext(); private: void encoder(); void decoder(); string text; };
textcoder.cpp
#include"textcoder.h" string encode1 = "fghijklmnopqrstuvwxyzabcde"; string encode2 = "FGHIJKLMNOPQRSTUVWXYZABCDE"; string decode1 = "vwxyzabcdefghijklmnopqrstu"; string decode2 = "VWXYZABCDEFGHIJKLMNOPQRSTU"; TextCoder::TextCoder(const string& _text) { text = _text; } void TextCoder::encoder() { for (auto& e :text) { if (e >= 'a' && e <= 'z') e = encode1[e - 'a']; else if (e >= 'A' && e <= 'Z') e = encode2[e - 'A']; } } void TextCoder::decoder() { for (auto& e : text) { if (e >= 'a' && e <= 'z') e = decode1[e - 'a']; else if (e >= 'A' && e <= 'Z') e = decode2[e - 'A']; } } string TextCoder::get_ciphertext() { encoder(); return text; } string TextCoder::get_deciphertext() { decoder(); return text; }
text6.cpp
#include <iostream> #include <string> #include "textcoder.h" using namespace std; extern string encode1; extern string encode2; extern string decode1; extern string decode2; void test() { 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(); return 0; }
标签:info,city,string,text,实验,include,nickname From: https://www.cnblogs.com/xelfin/p/16807703.html