实验二
2021/11/2 6:09:53
本文主要是介绍实验二,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#ifndef Info_HPP #define Info_HPP #include <iostream> #include <string> using namespace std; class Info { private: string nickname,contact,city; int n; public: Info(string x,string y,string z,int a) {nickname=x;contact=y;city=z;n=a;} void print(); }; void Info::print() { cout<<"称呼: "<<nickname<<endl; cout<<"联系方式: "<<contact<<endl; cout<<"所在城市: "<<city<<endl; cout<<"预定人数: "<<n<<endl; } #endif
#include "Info.hpp" #include <iostream> #include <string> #include <vector> using namespace std; int main() { vector<Info>audience_info_list; const int capacity=100; string x,y,z; int count=0,n; char choice; cout<<"录入信息:"<<endl<<endl; cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" <<endl; while(cin>>x) { cin>>y; cin>>z; cin>>n; if(n+count>capacity) { cout<<"对不起,只剩"<<(capacity-count)<<"个位置。"<<endl; cout<<"1.输入u,更新(update)预订信息"<<endl; cout<<"2.输入q,退出预定"<<endl; cout<<"你的选择:"; cin>>choice; if(choice=='u') { cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl; continue; } else break; } else { count+=n; audience_info_list.push_back(Info(x,y,z,n)); } } cout<<"截止目前,一共有"<<count<<"位听众参与预定。预定听众信息如下:"<<endl; for (int i=0;i<audience_info_list.size();i++) audience_info_list[i].print(); return 0; }
#ifndef TextCoder_HPP #define TextCoder_HPP #include<iostream> #include<String> using namespace std; class TextCoder { private: string text; public: TextCoder(string x){text=x;} string encoder(); string decoder(); }; string TextCoder::encoder() { for(int i=0;i<text.length();i++) { if((text[i]>='A'&&text[i]<='U')||(text[i]>='a'&&text[i]<='u')) { text[i]=text[i]+5; } else if((text[i]>='V'&&text[i]<='Z')||(text[i]>='v'&&text[i]<='z')) { text[i]=text[i]-21; } } return text; } string TextCoder::decoder() { for(int i=0;i<text.length();i++) { if((text[i]>='F'&&text[i]<='Z')||(text[i]>='f'&&text[i]<='z')) { text[i]=text[i]-5; } else if((text[i]>='A'&&text[i]<='E')||(text[i]>='a'&&text[i]<='e')) { text[i]=text[i]+21; } } 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输入英文文本: "; } }
这篇关于实验二的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-06小米11i印度快充版ROM合集:极致体验,超越期待
- 2024-10-06【ROM下载】小米11i 5G 印度版系统, 疾速跃迁,定义新速度
- 2024-10-06【ROM下载】小米 11 青春活力版,青春无极限,活力全开
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求