实验二
#ifndef INFO_HPP #define INFO_HPP #include<string> #include<iostream> using namespace std; class info{ public: info(string na,string co,string ci,int y):nickname(na),contact(co),city(ci),n(y){} void print() const; private: string nickname,contact,city; int n; }; void info::print() const{ cout<<"称呼: "<<nickname<<endl; cout<<"联系方式:"<<contact<<endl; cout<<"所在城市:"<<city<<endl; cout<<"预定人数:"<<n<<endl; } #endif
#include"info.hpp" #include<vector> using namespace std; const int capacity=100; int main(){ string name,con,city; int i,sum=0; char c; vector<info> audience_info_list; cout<<"录入信息:"<<endl; cout<<endl<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预订参加人数"<<endl; while(cin>>name){ cin>>con>>city>>i; if(i+sum>capacity){ cout<<"对不起,只剩"<<capacity-sum<<"个位置."<<endl; cout<<"1.输入u,更新(update)预定信息"<<endl; cout<<"2.输入q,退出预定"<<endl<<"你的选择:"; do{ cin>>c; if(c!='u'&&c!='q') cout<<"请输入q或u :"; }while(c!='u'&&c!='q'); if(c=='q') break; else{ continue; } } else { info k(name,con,city,i); audience_info_list.push_back(k); sum+=i; } } cout << "截止目前,一共有" << sum << "位听众预定参加。预定信息如下:" <<endl; for(auto const &a : audience_info_list) { a.print(); } return 0; }


#ifndef TEXTCODER_HPP #define TEXTCODER_HPP #include<string> #include<iostream> using namespace std; class TextCoder{ public: TextCoder(string t):text(t){} string encoder(); string decoder(); private: string text; }; string TextCoder::encoder(){ for(auto &a:text) { if( ( ( a < 'v') && ( a >= 'a')) || ((a < 'V') && (a >= 'A'))) { a += 5; } else if( ((a >= 'v') && (a <= 'z') ) || ((a >= 'V') && (a <= 'Z'))) { a -= 21; } } return text; } string TextCoder::decoder() { for(auto &a:text) { if( ( ( a <= 'z') && ( a > 'e')) || ((a <= 'Z') && (a > 'E'))) { a -= 5; } else if( ((a >= 'a') && (a <= 'e') ) || ((a >= 'A') && (a <= 'E'))) { a += 21; } } return text; } #endif

浙公网安备 33010602011771号