數組,指針與現代c++標準
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
class Info
{
public:
Info(string nickname, string contact, string city, int n)
: nickname{nickname}, contact{contact}, city{city}, n{n} { cnt += n; }
void print()
{
cout << "昵稱: " << nickname << endl
<< "聯系方式: " << contact << endl
<< "所在城市: " << city << endl
<< "預定人數: " << n << endl
<< endl;
}
static int getResult()
{
return cnt;
}
static const int capacity;
private:
string nickname;
string contact;
string city;
int n;
static int cnt;
};
int Info::cnt = 0;
const int Info::capacity = 100;
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include "Info.hpp"
using namespace std;
vector<Info> audience_info_list;
string nickname;
string contact;
string city;
int n;
int main()
{
cout << "錄入信息:" << endl;
cout << "昵稱" << " ";
cout << "聯系方式(郵箱/手機號)" << " ";
cout << "所在城市" << " ";
cout << "預定參加人數" << endl;
while (cin >> nickname)
{
cin >> contact >> city >> n;
bool flag = true;
while (n + Info::getResult() > Info::capacity)
{
cout << "對不起,只剩" << Info::capacity - Info::getResult() << "個位置" << endl;
cout << "1.輸入u,更新(updata)預訂信息" << endl;
cout << "2.輸入q,退出預定" << endl;
cout << "你的選擇:";
char str;
cin >> str;
if (str == 'q')
{
flag = false;
break;
}
else
{
cout << "更新預定人數:";
cin >> n;
}
}
if (flag)
{
audience_info_list.push_back(Info(nickname, contact, city, n));
cout << "預定成功 ~ " << endl;
}
}
cout << "截止目前,一共有" << Info::getResult() << "位聽眾預定參加。預定聽眾信息如下:" << endl;
for (auto &now : audience_info_list)
{
now.print();
}
return 0;
}

#include <bits/stdc++.h>
using namespace std;
class TextCoder
{
public:
TextCoder(string a = "") : text{a} {}
string get_ciphertext()
{
encoder_kaisa();
return text;
}
string get_deciphertext()
{
decoder_kaisa();
return text;
}
private:
string text;
void encoder_kaisa(int position = 5)
{
for (auto &ch : text)
{
char str;
if ('a' <= ch && ch <= 'z')
str = 'a';
else if ('A' <= ch && ch <= 'Z')
str = 'A';
else
continue;
ch = str + (ch - str + position + 52) % 26;
}
}
void decoder_kaisa()
{
encoder_kaisa(-5);
}
};
#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();
}

浙公網安備 33010602011771號