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