#include"music.hpp"
#include<iostream>
#include<vector>
#include<string>
int main()
{
using namespace std;
const int capacity = 100;
int n=0;
int num;
vector<info>audience_info_list;
string cnick, ccon,cct;
string choice;
cout << "录入信息:" << endl;
cout << "称呼/昵称,联系方式(邮箱/手机号码),所在城市,预定参加人数" << endl;
while(cin>>cnick)
{
cin >> ccon >> cct >> num;
if ( n+num <= capacity )
{
info member(cnick, ccon, cct, num);
audience_info_list.push_back(member);
n = n + num;
}
else
{
cout << "对不起,只剩" << (capacity - n) << "个座位" << endl;
cout << "输入u以更新预定信息" << endl;
cout << "输入q以退出预订" << endl;
cout << "你的选择:";
cin >> choice;
if (choice == "q")
break;
if (choice == "u")
{
cout << "正在更新信息" << endl;
continue;
}
}
}
cout << "截至目前,共有" << n<< "位听众已预定。预定信息如下:" << endl;
for (int i=0;i<audience_info_list.size();i++)
{
audience_info_list[i].print();
}
}
#ifndef __info_HPP__
#define __info_HPP__
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class info
{
public:
info(string nick, string con, string ct, int p);
~info() = default;
void print();
private:
string nickname;
string contact;
string city;
int n;
};
info::info(string nick, string con, string ct, int p)
{
nickname = nick;
contact = con;
city = ct;
n = p;
}
void info::print()
{
cout << setw(10) << "称呼:" << nickname << endl;
cout << setw(10) << "联系方式:" << contact << endl;
cout << setw(10) << "所在城市:" << city << endl;
cout << setw(10) << "预定人数:" << n << endl;
}
#endif // !__info_HPP__
![]()
![]()
![]()
#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输入英文文本: ";
}
}
#ifndef __textcoder_HPP__
#define __textcoder_HPP__
#include<iostream>
#include<string>
using namespace std;
class TextCoder
{
public:
TextCoder() {};
TextCoder(string a);
~TextCoder() = default;
string encoder();
string decoder();
private:
string text;
};
TextCoder::TextCoder(string a):text(a){}
string TextCoder::encoder()
{
int i,m;
m=text.size();
for (i = 0; i < m; i++)
{
text[i] = text[i] + 5;
}
return text;
}
string TextCoder::decoder()
{
int i, m;
m = text.size();
for (i = 0; i < m; i++)
{
text[i] = text[i] - 5;
}
return text;
}
#endif // !__textcoder_HPP__
![]()