实验5
#pragma once #include<iostream> #include<string> #include<iomanip> using namespace std; class info { public: info(string nickname0,string contact0,string city0,int n0): nickname{nickname0},contact{contact0},city{city0},n{n0} {} void print(); private: string nickname, contact, city; int n; }; void info::print() { cout << left << setw(15) << "昵称:"<<nickname<< endl; cout << left << setw(15) << "联系方式:" << contact << endl; cout << left << setw(15) << "所在城市:" << city << endl; cout << left << setw(15) << "预定人数:" << n << endl; cout << endl; }
#include<iostream> #include"info.h" #include<vector> #include<string> using namespace std; using namespace std; int main() { const int capacity = 100; int number = 0; string nickname, contact, city; int n; cout << "录入信息:" << endl<< endl; cout << left << setw(15) << "昵称" << setw(30) << "联系方式(邮箱/手机号)" << setw(15) << "所在城市" << setw(15) << "预定参加人数" << endl; vector<info> audience_info_list; while (cin>>nickname&&number<=100) { cin >> contact >> city >> n; info p = info(nickname, contact, city, n); audience_info_list.push_back(p); number += n; if (number > 100) { audience_info_list.pop_back(); number = number - n; cout << "对不起,只剩"<<number<<"个位置." << endl; cout << "1.输入u,更新(update)预定信息" << endl; cout << "2.输入q,退出预定" << endl; cout << "你的选择:"; string choice; cin >> choice; if (choice == "q") { break; } } } cout << "截至目前,一共有" << number << "位听众预定参加。预定听众信息如下:" << endl; for (auto i = 0; i < audience_info_list.size(); i++) { audience_info_list[i].print(); } }
实验6
#pragma once #include<iostream> #include<string> using namespace std; class TextCoder { private: string text; private: void encoder(string &s) { for (auto &item:s) { if (isalpha(item)) { item += 5; if (item > 'z' || item > 'Z' && item < 'a') { item -= 26; } } } } void decoder(string& s) { for (auto& item : s) { if (isalpha(item)) { item -= 5; if (item < 'A' || item > 'Z' && item < 'a') { item += 26; } } } } public: TextCoder(string text0):text{text0}{} string get_ciphertext(); string get_deciphertext(); }; string TextCoder::get_ciphertext() { encoder(text); return text; } string TextCoder::get_deciphertext() { decoder(text); return text; }
#include "textcoder.h" #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,int,text,C++,item,数组,include,指针 From: https://www.cnblogs.com/lyjlyjlyj/p/16810864.html