TASK 5:
info.hpp
#pragma once #include<iostream> #include<string> #include<iomanip> #include<vector> using namespace std; class info{ public: info(string Name,string Contact,string City,int num):name{Name},contact{Contact},city{City},n{num}{} void print(){ cout<<"昵称: "<<name<<endl; cout<<"联系方式: "<<contact<<endl; cout<<"所在城市: "<<city<<endl; cout<<"预定人数: "<<n<<endl; } private: string name,contact,city; int n; };
task5.cpp
#include"info.hpp" #include<iostream> #include<string> #include<iomanip> #include<vector> using namespace std; int main(){ const int capacity=100 ; vector<info>audience_info_list; cout<<"录入信息:"<<endl; cout<<setw(20)<<left<<"昵称"; cout<<setw(20)<<left<<"联系方式(邮箱/手机号)"; cout<<setw(20)<<left<<"所在城市"; cout<<setw(20)<<left<<"预定参加人数"<<endl; string na,con,ci,choice="u"; int cnt,add; while(choice=="u"&&cin>>na){ cin>>con>>ci>>add; if(cnt+add>capacity){ cout<<"对不起,只剩"<<capacity-cnt<<"个位置"<<endl; cout<<"1.输入u,更新(update)预定信息"<<endl<<"输入q,退出预定。"<<endl<<"你的选择:"; cin>>choice; if(choice=="q"){ break; }else{ cin>>na>>con>>ci>>add; cnt+=add; info in=info(na,con,ci,add); audience_info_list.push_back(in); break; } } cnt+=add; info in=info(na,con,ci,add); audience_info_list.push_back(in); if(cnt==capacity){ break; } } cout << "截至目前,一共有" <<cnt<< "位听众预定参加。预定听众信息如下:" <<endl; for (int i=0;i<audience_info_list.size();i++){ audience_info_list.at(i).print(); } return 0; }
测试样例:
TASK 6:
textcoder.hpp
#pragma once #include<iostream> #include<string> using namespace std; class TextCoder{ public: TextCoder(string t):text{t}{} TextCoder(TextCoder &p):text{p.text}{} string get_ciphertext(){ encoder(); return text; } string get_deciphertext(){ decoder(); return text; }; private: string text; void encoder(){ for(int i=0;i<text.size();i++){ if(isupper(text.at(i))){ text.at(i)=(text.at(i)-60)%26+65; }else{ if(islower(text.at(i))){ text.at(i)=(text.at(i)-92)%26+97; } } } }; void decoder(){ for(int i=0;i<text.size();i++){ if(isupper(text.at(i))){ text.at(i)=(text.at(i)-44)%26+65; }else{ if(islower(text.at(i))){ text.at(i)=(text.at(i)-76)%26+97; } } } }; };
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(); }
测试截图:
标签:info,string,text,add,实验,include,cout From: https://www.cnblogs.com/MaskerQwQ/p/16826148.html