实验五
hpp
1 #pragma once 2 3 #include<iostream> 4 #include <iomanip> 5 using namespace std; 6 class info 7 { 8 9 public: 10 info(string nickname =" ", string contact = " ", string city = " ", int n = 0); 11 void set(string nickname, string contact, string city, int n); 12 void print(); 13 private: 14 string nickname; 15 string contact; 16 string city; 17 int n; 18 }; 19 info :: info(string nickname,string contact,string city,int n) 20 { 21 22 this->nickname = nickname; 23 this->contact = contact; 24 this->city = city; 25 this->n = n; 26 } 27 void info::set(string nickname, string contact, string city, int n) 28 { 29 this->nickname = nickname; 30 this->contact = contact; 31 this->city = city; 32 this->n = n; 33 } 34 void info::print() 35 { 36 cout << left << setw(10) << "昵称" << nickname<<endl 37 << setw(10) << "联系方式" << contact<<endl 38 << setw(10) << "所在城市" << city<<endl 39 << setw(10) << "预定人数" << n << endl; 40 }
cpp
1 #include"info.hpp" 2 #include<iostream> 3 #include<vector> 4 #include <iomanip> 5 using namespace std; 6 int main() 7 { 8 9 const int capacity=100; 10 string a, b, c; 11 int n; 12 int sum = 0; 13 int count = 0; 14 vector<info> audience_info_list(100); 15 int i = 0; 16 flag: 17 cout << left << setw(10) << "昵称" << setw(10) << "联系方式(邮箱/手机号)" << setw(10) << "所在城市" 18 << setw(10) << "预定参加人数" << endl; 19 while (cin>>a>>b>>c>>n) 20 { 21 sum += n; 22 if (sum <= capacity) 23 { 24 audience_info_list[count].set(a, b, c, n); 25 count++; 26 } 27 else 28 { 29 sum -= n; 30 int other = capacity - sum; 31 cout << "对不起只剩" << other << "个座位" << endl; 32 string choice; 33 cout << "1.输入u,更新(update)预定信息。" << endl; 34 cout << "2.输入q,退出预定。" << endl; 35 cin >> choice; 36 cout << "你的选择:" << choice << endl; 37 if (choice == "q") 38 { 39 40 cout << "已退出预定!"; 41 return 0; 42 } 43 else 44 { 45 cout << "重新开始预定:" << endl; 46 goto flag; 47 } 48 } 49 } 50 cout << "截至目前,一共有" << sum << "位听众预定参加。预定听众信息如下:" << endl; 51 while (i < count) 52 { 53 audience_info_list[i].print(); 54 i++; 55 } 56 57 58 }
实验六
hpp
#pragma once #include<iostream> using namespace std; class TextCoder { public: TextCoder(string text) { this->text = text; } string get_ciphertext(); string get_deciphertext(); private: string text; void encoder(); void decoder(); }; void TextCoder::encoder() { for (int i = 0;text[i] != '\0';i++) { if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z')) { text[i] += 5; if (text[i] > 122 || (text[i] > 90) && text[i] <= 95) { text[i] -= 26; } } } } void TextCoder::decoder() { for (int i = 0;text[i] != '\0';i++) { if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z')) { text[i] -= 5; if (text[i] < 65 || (text[i]>=92&&text[i] < 97)) { text[i] += 26; } } } } string TextCoder::get_ciphertext() { encoder(); return text; } string TextCoder::get_deciphertext() { decoder(); return text; }
cpp
1 #include "textcoder.hpp" 2 #include <iostream> 3 #include <string> 4 5 void test() { 6 using namespace std; 7 8 string text, encoded_text, decoded_text; 9 10 cout << "输入英文文本: "; 11 while (getline(cin, text)) { 12 encoded_text = TextCoder(text).get_ciphertext(); // 这里使用的是临时无名对象 13 cout << "加密后英文文本:\t" << encoded_text << endl; 14 15 decoded_text = TextCoder(encoded_text).get_deciphertext(); // 这里使用的是临时无名对象 16 cout << "解密后英文文本:\t" << decoded_text << endl; 17 cout << "\n输入英文文本: "; 18 } 19 } 20 21 int main() { 22 test(); 23 }
标签:city,第三次,int,text,实验,include,nickname,string From: https://www.cnblogs.com/pdywsf/p/16823295.html