实验任务5
Info.hpp文件源码
#include <iostream> #include <string> #include <iomanip> using namespace std; class Info{ public: Info(string name,string con,string where,int number):nickname{name},contact{con},city{where},n{number}{}; void print(); int get_n(); private: string nickname,contact,city; int n; }; void Info::print(){ cout<<"昵称: "<<nickname<<endl; cout<<"联系方式: "<<contact<<endl; cout<<"所在城市: "<<city<<endl; cout<<"预定人数: "<<n<<endl; cout<<endl; } int Info::get_n(){ return n; }
task6.cpp源码
#include <iostream> #include "Info.hpp" #include <vector> #include <string> #include <iomanip> int main(){ using namespace std; const int capacity=100; vector<Info> audience_info_list; cout<<"录入信息:\n\n"; cout<<"昵称"<<setw(35)<<"联系方式(邮箱/手机号)"<<setw(20)<<"所在城市"<<setw(25)<<"预定参加人数\n"; int sum=0,number,item=0,left=0; string name,con,where; while(sum<=capacity&&getline(cin,name,' ')){ cin>>con; cin>>where; cin>>number; getchar(); Info push(name,con,where,number); left=push.get_n(); audience_info_list.push_back(push); item++; sum+=number; number=0; } if(sum>capacity){ cout<<"对不起,只剩"<<capacity-sum+left<<"个位置\n"; cout<<"1.输入u,更新(update)预定信息"<<endl; cout<<"2.输入q,退出预定" <<endl; cout<<"你的选择:"; char choose; cin>>choose; cout<<endl; cout<<"截至目前,一共有"<<sum-left<<"位听众预定参加。预定听众信息如下:"<<endl; for(int i=0;i<item-1;i++){ audience_info_list.at(i).print(); } } else{ cout<<"截至目前,一共有"<<sum<<"位听众预定参加。预定听众信息如下:"<<endl; for(int i=0;i<item;i++){ audience_info_list.at(i).print(); } } }
实验任务6
TextCoder.hpp
#include <iostream> #include <string> using namespace std; class TextCoder{ public: TextCoder(string tx); string get_ciphertext(); string get_deciphertext(); void ciphertext(); void deciphertext(); private: string text; }; TextCoder::TextCoder(string tx){ text=tx; } void TextCoder::ciphertext(){ for(int i=0;i<=text.size();i++){ if(text[i]>=65&&text[i]<=85){ text[i]+=5; } else if(text[i]>=97&&text[i]<=117){ text[i]+=5; } else if(text[i]>=86&&text[i]<=90){ text[i]-=11; } else if(text[i]>=118&&text[i]<=122){ text[i]-=11; } } } void TextCoder::deciphertext(){ for(int i=0;i<=text.size();i++){ if(text[i]>=70&&text[i]<=90){ text[i]-=5; } else if(text[i]>=102&&text[i]<=122){ text[i]-=5; } else if(text[i]>=65&&text[i]<=69){ text[i]-=11; } else if(text[i]>=97&&text[i]<=101){ text[i]-=11; } } } string TextCoder::get_ciphertext(){ this->ciphertext(); return text; } string TextCoder::get_deciphertext(){ this->deciphertext(); return text; }
task6.cpp
#include "textcoder.hpp" #include <iostream> #include <string> void test(){ using namespace std; string text,encoded_text,decoded_text; cout<<"输入英文文本: "; while(getline(cin,text)){ encoded_text=TextCoder(text).get_ciphertext(); cout<<"加密后英文文本:\t"<<encoded_text<<endl; decoded_text=TextCoder(encoded_text).get_deciphertext(); cout<<"解密后英文文本:\t"<<decoded_text<<endl; cout<<"\n输入英文文本:"; } } int main(){ test(); }
标签:string,int,text,实验,&&,include,TextCoder From: https://www.cnblogs.com/dingxincheng/p/16819349.html