#include<string>
#include<iostream>
using namespace std;
class info
{
public:
    info(string nickname,string contact,string city,int n);
    info();
    void print() const;
private:
    string nickname,contact,city;
    int n;
};
info::info(string nickname,string contact,string city,int n){
    this->nickname=nickname;
    this->contact=contact;
    this->city=city;
    this->n=n;
}

void info::print() const
{
    cout<<"称呼:\t\t"<<this->nickname<<endl;
    cout<<"联系方式:\t"<<this->contact<<endl;
    cout<<"所在城市:\t"<<this->city<<endl;
    cout<<"预定人数:\t"<<this->n<<endl;
}
#include<vector>
#include<string>
#include"info.hpp"
#include<iostream>
int main()
{
    using namespace std;
    vector<info>audience_info_list;
    int const capacity=100;
    string nickname,contact,city;
    int n,t=0;
    cout<<"录入信息:"<<endl;
    cout<<endl;
    cout<<"称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数"<<endl;
    while(cin>>nickname>>contact>>city>>n)
    {
    t+=n;
    if(t>capacity)
    {
        t-=n;
        char s;
        cout<<"对不起,只剩"<<100-t<<"个位置."<<endl;
        cout<<"1.输入u,更新(update)预定信息"<<endl;
        cout<<"2.输入q,退出预定"<<endl;
        cout<<"你的选择";
        cin>>s;
        if(s=='q')
            break;
        else
            continue;
    }
    info info(nickname,contact,city,n);
    audience_info_list.push_back(info);
    }
    cout<<"截至目前,一共有"<<t<<"位听众预定参加。预定听众信息如下:"<<endl;
    for(vector<info>::iterator it=audience_info_list.begin();it!=audience_info_list.end();it++)
    {
        it->print();
    }
}

实验二_其他实验二_ios_02

 

#include<string>
#include<iostream>
using namespace std;
class textcoder
{
public:
    textcoder(string text);
    textcoder();
    string encoder();
    string decoder();
private:
    string text;
};
textcoder::textcoder(string text)
{
    this->text=text;
}
string textcoder::encoder()
{
    int n,i;
    char c;
    const char*p=text.data();
    n=strlen(p);
    char a[100];
    for(i=0;i<n;i++)
    {
        c=*p;
        if(c>='a'&&c<'v')
            c+=5;
        else if(c=='v')
            c='a';
        else if(c=='w')
            c='b';
        else if(c=='x')
            c='c';
        else if(c=='y')
            c='d';
        else if(c=='z')
            c='e';
        else if(c>='A'&&c<'V')
            c+=5;
        else if(c=='V')
            c='A';
        else if(c=='W')
            c='B';
        else if(c=='X')
            c='C';
        else if(c=='Y')
            c='D';
        else if(c=='Z')
            c='E';
        a[i]=c;
        *p++;
    }
    a[n]='\0';
    text=a;
    return this->text;
}

string textcoder::decoder()
{
    int n,i;
    char c;
    const char*p=text.data();
    n=strlen(p);
    char a[100];
    for(i=0;i<n;i++)
    {
        c=*p;
        if(c>='f'&&c<='z')
            c-=5;
        else if(c=='a')
            c='v';
        else if(c=='b')
            c='w';
        else if(c=='c')
            c='x';
        else if(c=='d')
            c='y';
        else if(c=='e')
            c='z';
        else if(c>='F'&&c<='Z')
            c-=5;
        else if(c=='A')
            c='V';
        else if(c=='B')
            c='W';
        else if(c=='C')
            c='X';
        else if(c=='D')
            c='Y';
        else if(c=='E')
            c='Z';
        a[i]=c;
        *p++;
    }
    a[n]='\0';
    text=a;
    return this->text;
}
#include"textcoder.hpp"
#include<iostream>
#include<string>
int main()
{
    using namespace std;
    string text,encoded_text,decoded_text;
    cout<<"输入英文文本:";
    while(getline(cin, text))
    {
        encoded_text=textcoder(text).encoder();
        cout<<"加密后英文文本:"<<encoded_text<<endl;
        decoded_text=textcoder(encoded_text).decoder();
        cout<<"解密后英文文本:"<<decoded_text<<endl;
        cout<<"\n输入英文文本:";
    }
}

实验二_其他_03