实验二
------------恢复内容开始------------
线上预约登记
头文件.hpp
#ifndef INFO_HPP #define INFO_HPP #include<iostream> #include<string> using namespace std; class Order { private: string nickname, contact, city; int number; public: Order(string nickname0 = "Daisy", string contact0 = "13855279601", string city0 = "Wuxi", int n = 1) :nickname{ nickname0 }, contact{ contact0 }, city{ city0 }, number{ n } { nickname = nickname0; contact = contact0; city = city0; number = n; } void print()const; }; void Order::print()const { cout << "姓名:" << nickname << "\t"; cout << "联系方式:" << contact << "\t"; cout << "城市:" << city << "\t"; cout << "人数:" << number << "\t"; cout << endl; } #endif
主函数
#include "info.hpp" #include<iostream> #include<string> #include<vector> using namespace std; int main() { cout << "录入信息:" << endl; cout << "姓名 " << " 联系方式 " << " 城市 " << " 人数" << endl; vector<Order> audience_info_list; const int capacity = 100;//最大容量,const不可改变 string name, c, l; int number, n = 0; while (cin >> name >> c >> l >> number)//实现重复录入 { Order order(name, c, l, number); if (n + number < capacity) { audience_info_list.push_back(order); n += number; } else { char a; cout << "There is no enough seats!" << endl; cout << "the number of vacant seats:" << capacity - n << endl; cout << "Input u, update order" << endl; cout << "Input q,end order" << endl; cout << "your choice is:"; cin >> a; if (a == 'u') cout << "请继续输入:" << endl;
continue; else if (a == 'q') break; else { cout << "ERROR!!!" << endl; } } } cout << "截至目前,一共有" << n << "位观众" << "具体信息如下:" << endl; for (auto i : audience_info_list) { i.print();// cout << endl; } }
运行结果

文本加密解密
头文件
#ifndef textcoder_hpp #define textcoder_hpp #include<iostream> #include<string> #include<vector> using namespace std; class TextCoder { private: string text; public: TextCoder(string text1) :text(text1) { } string encoder(); string decoder(); }; string TextCoder::encoder() { string s; vector<string>::iterator i; for (auto i = text.begin(); i != text.end(); ++i) { if ((*i >= 'a' && *i <= 'u') || (*i >= 'A' && *i <= 'U')) { *i = *i + 5; } else if ((*i >= 'v' && *i <= 'z') || (*i >= 'V' && *i <= 'Z')) { *i = *i - 21; } else *i = *i; } return text; } string TextCoder::decoder() { string s; vector<string>::iterator i; for (auto i=text.begin();i!=text.end();++i) { if ((*i>= 'f' && *i <= 'z') || (*i >= 'F' && *i <= 'Z')) { *i = *i - 5; } else if((*i >= 'a' && *i <= 'e') || (*i >= 'A' && *i <= 'E')) { *i = *i + 21; } else *i = *i; } return text; } #endif
主函数
#include "head.hpp" #include <iostream> #include <string> int main() { using namespace std; string text, encoded_text, decoded_text; cout << "输入英文文本: "; while (getline(cin, text)) { encoded_text = TextCoder(text).encoder(); // 这里使用的是临时无名对象 cout << "加密后英文文本:\t" << encoded_text << endl; decoded_text = TextCoder(encoded_text).decoder(); // 这里使用的是临时无名对象 cout << "解密后英文文本:\t" << decoded_text << endl; cout << "\n输入英文文本: "; } }

------------恢复内容结束------------

浙公网安备 33010602011771号