实验2 数组、指针与C++标准库

//info.hpp
#include<iostream>
#include<string>
using namespace std;

class info{
   public:
   void enter(string a,string b,string c,int d):nickname(a),contact(b),city(c),n(d);
   void printf(){
   cout<<nickname<<contact<<city<<n<<endl;
}
   private:
   string nickename;
   string contact;
   string city;
   int n;
   };

//task5.cpp
#include"info.hpp"
#include<iostream>
#include<string>
#include<vector>
int main()
{    using namespace std;

    cout << "录入信息:" << endl;
    cout << "" << endl;
    cout << "称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl;

    vector<Info>audience_info_list;
    const int Capacity = 100;
    int i = 0,j=0 , k;    char h;
    string e, f, g;  int m;  
    while ((cin >> e),(cin >> f),(cin >> g),(cin >> m))
    {
        audience_info_list.push_back(Info(e, f, g, m));

        k = Capacity - i - m;
        if (k < 0) {
            cout << "对不起,只剩" << Capacity - i << "个位置." << endl;
            cout << "1.输入u,更新(update)预订信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            cout << "你的选择:";
            cin >> h;
            cout << "" << endl;

            if (h == ' u') {
                cout << "称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" << endl;
                cin >> e >> f >> g >> m;
                Info update(e, f, g, m);
                
                audience_info_list.pop_back();

                continue;
            }
            if (h == 'q')break;

        }
        i = i + m;
        j++;
    }
    cout << "截至目前,一共有" << i << "位听众预定参加。预定听众信息如下:" << endl;
    for (int z = 0; z < j; z++) {
        audience_info_list[z].print();
    }
    return 0;
}

 

#ifndef _TEXTCODER_HPP
#define _TEXTCODER_HPP
#include<iostream>

class TextCoder {
public:
    TextCoder(std::string a):text(a){} //A65 a97
    std::string encoder();
    std::string decoder();
private:
    std::string text;
};

std::string TextCoder::encoder()
{
    for (int i = 0; i < text.length(); i++) {
        if (text.at(i) >= 'a' && text.at(i) <= 'u' || text.at(i) >= 'A' && text.at(i) <= 'U')
            text.at(i) += 5;
        else if (text.at(i) >= 'v' && text.at(i) <= 'z' || text.at(i) >= 'V' && text.at(i) <= 'Z')
            text.at(i) = text.at(i) + 5 - 26;
    }
    return text;
    
}
std::string TextCoder::decoder() {
    for (int i = 0; i < text.length(); i++) {
        if (text.at(i) >= 'f' && text.at(i) <= 'z' || text.at(i) >= 'F' && text.at(i) <= 'Z')
            text.at(i) -= 5;
        else if (text.at(i) >= 'a' && text.at(i) <= 'e' || text.at(i) >= 'A' && text.at(i) <= 'E')
            text.at(i) = text.at(i) + 26 - 5;
    }
    return text;
}
    
#endif

 

 

posted @ 2021-11-01 23:40  此生不想敲代码  阅读(20)  评论(3)    收藏  举报