#include "info.hpp" #include <iostream> #include<vector> #include<cstring> int main() { int count=0; const int capacity=100; vector<Info>audience_info_list; cout << "录入信息:" << endl << endl; cout << "昵称 " << "联系方式(邮箱/手机号) " << "所在城市 " << "预定参加人数 " << endl; string x,y,z; int k; string s; while(cin>>x) { cin>>y>>z>>k; Info info(x,y,z,k); audience_info_list.push_back(info); count+=k; if(count>capacity) { count=count-k; audience_info_list.pop_back(); cout<<"对不起,只剩"<<capacity-count<<"个位子。"<<endl; cout<<"1.输入u,更新(update)预定信息。"<<endl; cout<<"2.输入q,退出预定。" <<endl; cout << "你的选择 :"; cin>>s; if(s=="u") continue; if(s=="q") break; } if(count==capacity) break; } cout <<endl<< "截止目前,一共有" << count << "位听众预定参加。预定听众信息如下:" << endl; for (auto &item : audience_info_list) { item.print(); } return 0; }
#include<iostream> #include<cstring> using namespace std; class Info { public: Info(string x,string y,string z,int k):nickname{x},contact{y},city{z},n{k}{} void print(); private: string nickname,contact,city; int n; }; void Info::print() { cout<<"昵称:"<<nickname <<endl; cout<<"联系方式:"<<contact <<endl; cout<<"所在城市:"<<city <<endl; cout<<"预定人数:"<<n <<endl; }
task2:
#pragma once #include <iostream> #include <string> using namespace std; class TextCoder { private: string text; public: TextCoder(string x):text{x}{} string get_ciphertext(); string get_deciphertext(); private: void encoder(string &s) { for (auto &i : s) { if (isalpha(i)) { i += 5; if (i > 'z'||i<'a'&&i>'Z') i -= 26; } } } void decoder(string &s) { for (auto &i : s) { if (isalpha(i)) { i -= 5; if (i < 'A'||i>'Z'&&i<'a') i += 26; } } } }; string TextCoder::get_ciphertext() { encoder(text); return text; } string TextCoder::get_deciphertext() { decoder(text); return text; }
标签:count,info,string,int,实验,include,cout From: https://www.cnblogs.com/202183290359gyk/p/16826249.html