task5
task5.cpp源码
#include"info.cpp" #include<vector> using namespace std; int main(){ vector<Info> audience_info_list; string name1,contact1,city1; const int capacity=100; int n1,judge,k,change,count=0; cout<<"录入信息:(决定输入信息前需输入当前序号,停止录入即输入0)"<<endl; cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl; while(cin>>judge){ if(judge==0){ cout<<"截至目前,一共有"<<count<<"位听众预定参加。预定听众信息如下"<<endl; for(k=0;k<audience_info_list.size();k++) audience_info_list[k].print(); break; } cin>>name1>>contact1>>city1>>n1; Info user(name1,contact1,city1,n1); audience_info_list.push_back(user); count+=n1; if(count>capacity){ char choice; count=capacity-count+n1; cout<<"对不起,只剩"<<count<<"个位置"<<endl; cout<<"1.输入u,更新(update)预定位置"<<endl; cout<<"2.输入q,退出预定"<<endl; cin>>choice; switch(choice){ case 'u': { cout<<"现预定情况:"<<endl; cout<<"截至目前,一共有"<<100-count<<"位听众预定参加。预定听众信息如下"<<endl; audience_info_list.pop_back(); for(k=0;k<audience_info_list.size();k++) audience_info_list[k].print(); change=1; count=100-count; cout<<"可选择继续录入信息"<<endl; break; } case 'q': { cout<<"截至目前,一共有"<<100-count<<"位听众预定参加。预定听众信息如下"<<endl; audience_info_list.pop_back(); for(k=0;k<audience_info_list.size();k++) audience_info_list[k].print(); change=0; break; } } } if(change==0) break; } }
info.cpp源码
#include<iostream> #include<string> using namespace std; class Info{ private: string name; string contact; string city; int n; public: Info(string name0,string contact0,string city0,int n0):name(name0),contact(contact0),city(city0),n(n0){} void print(){ cout<<"称呼: "; cout<<name<<endl; cout<<"联系方式: "; cout<<contact<<endl; cout<<"所在城市: "; cout<<city<<endl; cout<<"预定人数: "; cout<<n<<endl; cout<<"\n"; } };
实验结果截图:
task6
task6.cpp源码:
#include<iostream> #include<string> #include<ctype.h> using namespace std; class TextCoder{ private: string text; public: TextCoder(string text0):text(text0){} TextCoder(const TextCoder &a){ text=a.text; } string encoder(){ int i; for(i=0;i<text.length();i++){ if(text[i]=='v'||text[i]=='V'){ switch(text[i]){ case 'v' : text[i]='a';break; case 'V' : text[i]='A';break; } } else if(text[i]=='w'||text[i]=='W'){ switch(text[i]){ case 'w' : text[i]='b';break; case 'W' : text[i]='B';break; } } else if(text[i]=='x'||text[i]=='X'){ switch(text[i]){ case 'x' : text[i]='c';break; case 'X' : text[i]='C';break; } } else if(text[i]=='y'||text[i]=='Y'){ switch(text[i]){ case 'y' : text[i]='d';break; case 'Y' : text[i]='D';break; } } else if(text[i]=='z'||text[i]=='Z'){ switch(text[i]){ case 'z' : text[i]='e';break; case 'Z' : text[i]='E';break; } } else{ if(isalpha(text[i])) text[i]=text[i]+5; } } return text; } string decoder(){ int i; for(i=0;i<text.length();i++){ if(text[i]=='a'||text[i]=='A'){ switch(text[i]){ case 'a' : text[i]='v';break; case 'A' : text[i]='V';break; } } else if(text[i]=='b'||text[i]=='B'){ switch(text[i]){ case 'b' : text[i]='w';break; case 'B' : text[i]='W';break; } } else if(text[i]=='c'||text[i]=='C'){ switch(text[i]){ case 'c' : text[i]='x';break; case 'C' : text[i]='X';break; } } else if(text[i]=='d'||text[i]=='D'){ switch(text[i]){ case 'd' : text[i]='y';break; case 'D' : text[i]='Y';break; } } else if(text[i]=='e'||text[i]=='E'){ switch(text[i]){ case 'e' : text[i]='z';break; case 'E' : text[i]='Z';break; } } else{ if(isalpha(text[i])) text[i]=text[i]-5; } } return text; } };
实验结果截图: