首页 > 编程语言 >数组,指针与现代c++标准

数组,指针与现代c++标准

时间:2022-10-23 00:55:19浏览次数:42  
标签:Info city string text cout c++ 数组 include 指针

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

class Info
{

public:
    Info(string nickname, string contact, string city, int n)
        : nickname{nickname}, contact{contact}, city{city}, n{n} { cnt += n; }

    void print()
    {
        cout << "昵称: " << nickname << endl
             << "联系方式: " << contact << endl
             << "所在城市: " << city << endl
             << "预定人数: " << n << endl
             << endl;
    }

    static int getResult()
    {
        return cnt;
    }

    static const int capacity;
    

private:
    string nickname;
    string contact;
    string city;
    int n;
    static int cnt;
};

int Info::cnt = 0;
const int Info::capacity = 100;

  

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include "Info.hpp"

using namespace std;

vector<Info> audience_info_list;
string nickname;
string contact;
string city;
int n;

int main()
{

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

    while (cin >> nickname)
    {
        cin >> contact >> city >> n;
        bool flag = true;

        while (n + Info::getResult() > Info::capacity)
        {
            cout << "对不起,只剩" << Info::capacity - Info::getResult() << "个位置" << endl;
            cout << "1.输入u,更新(updata)预订信息" << endl;
            cout << "2.输入q,退出预定" << endl;
            cout << "你的选择:";

            char str;
            cin >> str;

            if (str == 'q')
            {
                flag = false;
                break;
            }
            else
            {
                cout << "更新预定人数:";
                cin >> n;
            }
        }

        if (flag)
        {
            audience_info_list.push_back(Info(nickname, contact, city, n));
            cout << "预定成功 ~ " << endl;
        }
    }

    cout << "截止目前,一共有" << Info::getResult() << "位听众预定参加。预定听众信息如下:" << endl;

    for (auto &now : audience_info_list)
    {
        now.print();
    }

    return 0;
}

  

#include <bits/stdc++.h>

using namespace std;

class TextCoder
{

public:
    TextCoder(string a = "") : text{a} {}

    string get_ciphertext()
    {
        encoder_kaisa();
        return text;
    }

    string get_deciphertext()
    {
        decoder_kaisa();
        return text;
    }

private:
    string text;

    void encoder_kaisa(int position = 5)
    {
        for (auto &ch : text)
        {
            char str;
            if ('a' <= ch && ch <= 'z')
                str = 'a';
            else if ('A' <= ch && ch <= 'Z')
                str = 'A';
            else
                continue;
            ch = str + (ch - str + position + 52) % 26;
        }
    }

    void decoder_kaisa()
    {
        encoder_kaisa(-5);
    }
};

  

#include "textcoder.hpp"
#include <iostream>
#include <string>
void test()
{
    using namespace std;
    string text, encoded_text, decoded_text;
    cout << "输入英文文本: ";
    while (getline(cin, text))
    {
        encoded_text = TextCoder(text).get_ciphertext(); // 这里使用的是临时无名对象
        cout << "加密后英文文本:\t" << encoded_text << endl;
        decoded_text = TextCoder(encoded_text).get_deciphertext(); // 这里使用的是临时无名对象
        cout << "解密后英文文本:\t" << decoded_text << endl;
        cout << "\n输入英文文本: ";
    }
}
int main()
{
    test();
}

  

 

标签:Info,city,string,text,cout,c++,数组,include,指针
From: https://www.cnblogs.com/cflxl/p/16817723.html

相关文章

  • 后台管理系统 数组去重 避免踩坑!
    不要把数组push放进循环中,后果很严重!!!findIndexfiltersome......
  • 4. 寻找两个正序数组的中位数
    给定两个大小分别为m和n的正序(从小到大)数组 nums1和 nums2。请你找出并返回这两个正序数组的中位数。算法的时间复杂度应该为O(log(m+n))。示例1:输入:nums1......
  • 数组访问越界
    一、是什么如果定义了一个有n个元素的数组,那么,对这n个元素(下标为0到n-1的元素)的访问都合法,而对这n个元素之外的空间进行访问,就是非法的,称为“越界“。二、如何避免1)检查传......
  • 容器是否能代替数组
    在.net中,很多开发者都喜欢使用List来代替数组进行使用。容器不仅封装了数组几乎所有的基本操作,而且还可以动态扩容,在开发过程中十分的方便。以下的场景更加建议使用数组:容器......
  • 【leetcode_C++_哈希表_day5】242. 有效的字母异位词&&349. 两个数组的交集&&202.快乐
    C++知识补充:(不完全,仅针对本题用的知识点)1.C++类&对象关键字public确定了类成员的访问属性。在类对象作用域内,公共成员在类的外部是可访问的。您也可以指定类的成......
  • 进阶指针2
    函数指针使用方法(转移表)ntadd(intx,inty){returnx+y;}intsub(intx,inty){returnx-y;}intmul(intx,inty){returnx*y;}intdiv(intx,inty){r......
  • 数组初步认识和使用
    1.作用:可以同时储存多个数据(就是数据的组合)2.数组的特点a.可以储存多个数据,且只能储存相同类型的数据,有我们定义b.数组中储存的个数是固定的,有我们自己定义。3.如何声明一个......
  • 【C语言进阶】二.指针(上)
    前言:指针的主题,我们在【C语言有这个就够了】学习中已经接触过了,我们知道了指针的概念:1.指针就是个变量,用来存放地址,地址唯一标识一块内存空间2.指针的大小是固定的4/8个字......
  • 数据结构:数组
    一、是什么数组是一种线性表结构。它用一组连续的内存空间,来存储一组具有相同类型的数据。首先我们需要理解一下这句话,以便于我们更好地理解数组。1.1线性表线性表是n个具......
  • C++模板编程学习-using-declaration中的依赖型名称
    《C++Templates》9.3.4using-declaration中的依赖型名称学无止境,看到C++模板的第九章中的使用声明从两个位置(类和名字空间)引入名称,当引入名字空间不会涉及上下文问题......