栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

 

task5

Info.hpp

#include
#include
using namespace std;

class Info{

public:
    Info(string name = "",string con = "",string ci = "",int nu = 0):nickname{name},contact{con},city{ci},n{nu}{}
    ~Info() = default;
    void print()
    {
        cout << "称呼:    "<< nickname << endl;
        cout << "联系方式:" << contact << endl;
        cout << "所在城市:" << city << endl;
        cout << "预订人数:" << n << endl;
    }
private:
    string nickname;
    string contact;
    string city;
    int n;
};

task5.cpp

#include"Info.hpp"
#include
#include
#include
using namespace std;

int main()
{
    const int capacity = 100;
    int Number = 100,count = 0;
    vector audience_info_list;
    cout << "录入信息" << endl;
    cout << endl;
    cout << "称呼/昵称,联系方式(邮箱/手机号),所在城市,预定参加人数" << endl;
    string s1,s2,s3,s4;
    int n1;
    while(cin >> s1)
    {
        cin >> s2 >> s3 >> n1;
        audience_info_list.push_back(Info(s1,s2,s3,n1));
        if(Number - n1 < 0)
        {
            cout << "对不起,只剩下" << Number << "个位置" << endl;
            cout << "1.输入u,更新(updata)预定信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            char a;
            cin >> a;
            if(a == 'q')
            {
                cout << "你的选择:q" << endl;
                break;
            }
            if(a == 'u')
            {
                audience_info_list.pop_back();
                continue;
            }
        }
        Number -= n1;
    }
    cout << "截至目前,一共有" << Number << "位听众参加预定。预定听众信息如下:" << endl;
     for(auto it=audience_info_list.begin();it!=audience_info_list.end();++it)
        it->print();
    return 0;
}

task 6

textcoder.hpp

#include
#include
using namespace std;

class TextCoder{

public:
    TextCoder(string s = ""):text(s){}
    ~TextCoder() = default;
    string encoder()
    {
        for(int i = 0;i < text.size();i++)
        {
            if(text[i] >= 'a'&&text[i] <= 'u'||text[i] >= 'A'&&text[i] <= 'U')
                text[i] = text[i] + 5;
            else if(text[i] > 'u'&&text[i] <= 'z'||text[i] >'U'&&text[i] <= 'Z') 
                text[i] = text[i] - 26 + 5;
        }
        return text;
    }
    string decoder()
    {
        for(int i = 0;i < text.size();i++)
        {
            if(text[i] >= 'f'&&text[i] <= 'z'||text[i] >= 'F'&&text[i] <= 'Z')
                text[i] = text[i] - 5;
            else if(text[i] >= 'a'&&text[i] < 'f'||text[i] >='A'&&text[i] < 'F') 
                text[i] = text[i] + 26 - 5;
        }
        return text;
    }
private:
    string text;
};

task6.cpp


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/384770.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号