1 #include<iostream> 2 #include<string> 3 #include<iomanip> 4 #include<vector> 5 using namespace std; 6 class info{ 7 public: 8 info(string nickname0,string contact0,string city0,int n0); 9 void print(); 10 private: 11 string nickname; 12 string contact; 13 string city; 14 int n; 15 }; 16 info::info(string nickname0,string contact0,string city0,int n0):nickname(nickname0),contact(contact0),city(city0),n(n0){}; 17 void info::print(){ 18 cout<<setw(15)<<left<<"称呼:"<< nickname <<endl; 19 cout<<setw(15)<<left<<"联系方式:"<< contact <<endl; 20 cout<<setw(15)<<left<<"所在城市:"<< city <<endl; 21 cout<<setw(15)<<left<<"预订人数:"<< n <<endl; 22 } 23 24 int main(){ 25 char a; 26 vector<info>audience_info_list; 27 const int capacity = 100; 28 string nickname,contact,city; 29 int n; 30 int sum = 0; 31 cout<<"录入信息:"<<endl; 32 cout<<endl; 33 cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl; 34 while(cin>>nickname>>contact>>city>>n){ 35 sum+=n; 36 if(capacity>=sum){ 37 info massage(nickname,contact,city,n); 38 audience_info_list.push_back(massage) ; 39 40 } 41 else{ 42 int b; 43 b=sum-capacity; 44 cout<<"对不起,只剩"<< n-b <<"个位置"<<endl; 45 cout<<"1.输入u,更新(update)预订信息"<<endl; 46 cout<<"2.输入q,退出;预定"<<endl; 47 cout<<"你的选择是:" ; 48 cin>>a; 49 if(a=='q'){ 50 break; 51 } 52 else if(a=='u'){ 53 continue; 54 } 55 cout<<endl; 56 } 57 } 58 cout<<endl; 59 cout<<"截至目前,一共有"<<sum-n<<"位听众预定参加。预定听众信息如下:"<<endl; 60 cout<<endl; 61 for(auto it = audience_info_list.begin();it!=audience_info_list.end();it++){ 62 it->print(); 63 } 64 }
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 class TextCoder 5 { 6 public: 7 TextCoder(string temp):text(temp){} 8 ~TextCoder()=default;\ 9 string encoder() 10 { 11 for(int i=0;i<text.size();i++) 12 { 13 if(text[i]<='u'&&text[i]>='a') 14 { 15 text[i]+=5; 16 continue; 17 } 18 if(text[i]<='z'&&text[i]>='v') 19 { 20 text[i]='a'+(static_cast<int>(text[i]-'z')+4); 21 continue; 22 } 23 if(text[i]<='U'&&text[i]>='A') 24 { 25 text[i]+=5; 26 continue; 27 } 28 if(text[i]<='Z'&&text[i]>='V') 29 { 30 text[i]='A'+(static_cast<int>(text[i]-'Z'+4)); 31 continue; 32 } 33 } 34 return text; 35 } 36 string decoder() 37 { 38 for(int i=0;i<=text.size();i++) 39 { 40 if(text[i]<='z'&&text[i]>='f') 41 { 42 text[i]-=5; 43 continue; 44 } 45 if(text[i]<='e'&&text[i]>='a') 46 { 47 text[i]='z'-(4-static_cast<int>(text[i]-'a')); 48 continue; 49 } 50 if(text[i]<='Z'&&text[i]>='F') 51 { 52 text[i]-=5; 53 continue; 54 } 55 if(text[i]<='E'&&text[i]>='A') 56 { 57 text[i]='Z'-(4-static_cast<int>(text[i]-'A')); 58 continue; 59 } 60 } 61 return text; 62 } 63 private: 64 string text; 65 }; 66 67 68 69 70 int main() 71 { 72 using namespace std; 73 string text,encoded_text,decoded_text; 74 cout<<"输入英文文本:"; 75 while(getline(cin,text)) 76 { 77 encoded_text=TextCoder(text).encoder(); 78 cout<<"加密后英文文本:\t"<<encoded_text<<endl; 79 decoded_text=TextCoder(text).decoder(); 80 cout<<"解密后的英文文本:\t"<<decoded_text<<endl; 81 cout<<"输入英文文本:"; 82 } 83 }