首页 > 其他分享 >实验3

实验3

时间:2022-10-25 20:44:55浏览次数:34  
标签:count info string int 实验 include cout

#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

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBox或......
  • 实验7:基于REST API的SDN北向应用实践
    实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。实验要求(一)基本要求编写Python程序,调用OpenDayl......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的1.能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;2.能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境1.下载虚拟机软件OracleVisua......
  • 决策树算法实验
     【实验目的】理解决策树算法原理,掌握决策树算法框架;理解决策树学习算法的特征选择、树的生成和树的剪枝;能根据不同的数据类型,选择不同的决策树算法;针对特定应用场......
  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i)......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......
  • 实验3
    一、实验目的知道什么是类模板,会正确定义和使用简单的类模板能够描述数组的特性,会使用C++语法正确定义和访问内置数组,知道其局限性能够解释指针变量的特性,会使用C++语......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验环境下载虚拟机软件OracleVisualBo......