task5:
info.hpp
#pragma once
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class info
{
public:
info(string nickname,string contack,string city,int n):
nickname{nickname},contack{contack},city{city},n{n}{}
void print();
private:
string nickname,contack,city;
int n;
};
void info::print()
{
cout<<"昵称:\t\t"<<nickname<<endl;
cout<<"联系方式:\t"<<contack<<endl;
cout<<"所在城市:\t"<<city<<endl;
cout<<"预订人数:\t"<<n<<endl;
}
task5.cpp
#include"info.hpp"
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
const int capacity=100;
int n,count=0;
string nickname,contack,city;
vector<info>audience_info_list;
cout<<"录入信息:"<<endl;
cout<<"昵称\t\t"<<"联系方式(邮箱/手机号)\t"<<"所在城市\t"<<"预定参加人数\t"<<endl;
while(cin>>nickname)
{
cin>>contack>>city>>n;
count+=n;
if(capacity-count>=0)
{
info p=info(nickname,contack,city,n);
audience_info_list.push_back(p);
}
else
{
string choice;
count-=n;
cout<<"对不起,只剩"<<capacity-count<<"个位置"<<endl;
cout<<"1.输入u,更新(update)预定信息"<<endl;
cout<<"2.输入q,退出预定"<<endl;
cout<<"你的选择:" ;
cin>>choice;
if(choice=="q")
break;
else if(choice=="u")
{
cout<<"录入信息:"<<endl;
continue;
}
}
}
cout<<"截至目前,一共有"<<count<<"位听众预定参加。预定听众信息如下:"<<endl;
for(int i=0;i<audience_info_list.size();i++)
{
audience_info_list.at(i).print();
cout<<endl;
}
}
task6:
#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();
}
#pragma once
#include<iostream>
#include<string>
class TextCoder()
{
public:
TextCoder(string text):text{text}{}
string get_ciphertext();
string get_deciphertext();
private:
string text;
void encoder();
void decoder();
};
string TextCoder::get_ciphertext()
{
encoder();
return text;
}
string TextCoder::get_deciphertext()
{
encoder();
return text;
}
void TextCoder::encoder()
{
for(auto &i:text)
{
if(i>='a'&&i<='u')
{
i+=5;
}
else if(i>='v'&&i<='z')
{
i-=21;
}
else if(i>='A'&&i<='U')
{
i+=5;
}
else if(i>='V'&&i<='Z')
{
i-=21;
}
}
}
void TextCoder::decoder()
{
for(auto &i:text)
{
if(i>='f'&&i<='z')
{
i-=5;
}
else if(i>='a'&&i<='e')
{
i+=21;
}
else if(i>='F'&&i<='Z')
{
i-=5;
}
else if(i>='A'&&i<='E')
{
i+=21;
}
}
}
标签:info,cout,text,实验,&&,include,string From: https://www.cnblogs.com/CYYyyds030711/p/16810898.html