实验二
#ifndef info_HPP #define info_HPP #include<iostream> #include<string> using namespace std; class info{ private:string nickname,contact,city; int n; public:info(){} info(string ni,string co,string ci,int n2):nickname(ni),contact(co),city(ci),n(n2) {} ~info(){} string get_nick() { return nickname;} string get_con() { return contact;} string get_ci() { return city;} int get_n() { return n;} void print(){ cout<<"称呼: "<<nickname<<endl <<"联系方式: "<<contact<<endl <<"所在城市: "<<city<<endl <<"预订人数: "<<n<<endl; } }; #endif #include<iostream> #include<string> #include<vector> #include"info.hpp" using namespace std; const int capacity = 100; int main() { vector<info> audience_info_list; string nick, con, ci; int m, mid = 0, sum = 0, i; cout << "录入信息: " << endl << endl << "称呼/昵称, 联系方式(邮箱/手机号), 所在城市, 预定参加人数" << endl; while (cin >> nick >> con >> ci >> m) { if (sum + m > capacity) { cout << "对不起,只剩" << capacity - sum << "个位置"<<endl << "1.输入u,更新(update)预定信息" << endl << "2.输入q,退出预定" << endl << "你的选择: "<<endl; char choose; cin >> choose; if(choose=='q') break; else continue; } else { info info1(nick, con, ci, m); audience_info_list.push_back(info1); mid++; sum += m; } } cout << "截至目前,一共有" << sum << "位听众预定参加预定听众信息如下:" << endl; for (i = 0; i < mid; i++) audience_info_list[i].print(); } }
#ifndef textcoder_HPP
#define textcoder_HPP
#include<iostream>
#include<string>
using namespace std;
class TextCoder {
private:string text;
public:TextCoder() {}
TextCoder(string text1) :text(text1) {}
~TextCoder() {}
string encoder() {
int n = text.size(), i;
for (i = 0; i < n; i++)
{
if (('v' <= text[i] && text[i] <= 'z') || ('V' <= text[i] && text[i] <= 'Z')) text[i] = text[i] - 21;
else if (('a'<=text[i]&&text[i]<='u')||('A'<=text[i]&&text[i]<='Z')) text[i] = text[i] + 5;
}
return text;
}
string decoder() {
int n = text.size(), i;
for (i = 0; i < n; i++)
{
if (('a' <= text[i] && text[i] <= 'e') || ('A' <= text[i] && text[i] <= 'E')) text[i] = text[i] + 21;
else if (('f'<=text[i]&&text[i]<='z')||('F'<=text[i]&&text[i]<='Z'))text[i] = text[i] - 5;
}
return text;
}
};
#endif
#include "textcoder.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号