首页 > 编程语言 >实验三 数组、指针与现代c++标准库

实验三 数组、指针与现代c++标准库

时间:2022-10-23 10:55:30浏览次数:35  
标签:string Show int text void c++ 数组 include 指针

task5

#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

class Info {
    public:
    Info(string nickname0, string contact0, string city0, int n0);
    void print();
    string nickname, contact, city;
    int n;
};

Info::Info(string nickname0, string contact0, string city0, int n0) :nickname{nickname0}, contact{contact0}, city{city0}, n{n0} {}

void Info::print(){
    cout << "昵称:     " << left << setw(10) << nickname << endl;
    cout << "联系方式: " << left << setw(10) << contact << endl;
    cout << "所在城市: " << left << setw(10) << city << endl;
    cout << "预订人数: " << left << setw(10) << n << "\n" << endl; 
}
#include "实验三task5_info.hpp"
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>

using namespace std;

class Show{
    public:
        void Show_get();
        void Show_put();
        const int capacity = 100;
        int k;
        vector<Info> audience_info_list;
        
};

void Show::Show_get() {
    string name,con,city;
    int num;
    k = 0;
    while (cin >> name)
    {
        cin >> con >> city >> num;
        k += num;
        if(k > capacity)
        {
            k -= num;
            cout << "对不起,只剩" << capacity - k << "个位置。" << endl;
            cout << "1.输入u,更新(update)预定信息\n" << "2.输入q,退出预定\n"  << "你的选择:";
            char a;
            cin >> a;
            if(a == 'q')
            break;
            else if(a == 'u')
            continue;
        } 
        Info info(name, con, city, num);
        audience_info_list.push_back(info); 
    }
}

void Show::Show_put() {
    for(auto information:audience_info_list)
    information.print();
}

int main()
{
    Show s;
    cout << "录入信息: " << endl;
    cout << endl;
    cout << left << setw(15) << "昵称" << right << setw(15) << "联系方式(邮箱、手机号)" << setw(15) << "所在城市" << setw(15) << "预定参加人数" << endl;
    s.Show_get();
    cout << "截至目前,一共有" <<  s.k << "位听众预定参加。预定听众信息如下:" << endl; 
    s.Show_put() ;
}

 

 

 

 task6

#pragma once

#include <iostream>
#include <string>

using namespace std;
 
class TextCoder {
    public:
        TextCoder(string t): text{t} {};
        string get_ciphertext() { 
        encoder();
        return text; };
        string get_deciphertext() { 
        decoder();
        return text; };
        
    private:
        string text;
        void encoder();
        void decoder();
};

void TextCoder::encoder(){
     for(auto i = 0; i < text.size(); ++i)
     {
             if(text[i] >= 'v' && text[i] <= 'z' || text[i] >= 'V' && text[i] <= 'Z')
                text[i] = char(text[i] - 21);
             else if(text[i] >='A' && text[i] <= 'z')
                text[i] = char(text[i] + 5);  
     }
}

void TextCoder::decoder(){
     for(auto i = 0; i < text.size(); ++i)
     {
             if(text[i] >= 'a' && text[i] <= 'e' || text[i] >= 'A' && text[i] <= 'Z')
                text[i] = char(text[i] + 21);
             else if(text[i] >='A' && text[i] <= 'z')
                text[i] = char(text[i] - 5 );  
     }
}
#include "实验三test6_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 << "加密后英文文本:" << encoded_text << endl;
        
        decoded_text = TextCoder(encoded_text).get_deciphertex

 

 

        cout << "解密后英文文本:" << decoded_text << endl;
        cout << "\n输入英文文本: ";
    } 
}

int main() {
    test();
}

 

标签:string,Show,int,text,void,c++,数组,include,指针
From: https://www.cnblogs.com/djynb/p/16818100.html

相关文章

  • PHP array_multisort 多维数组排序的理解
    array_multisort(array1,sortingorder,sortingtype,array2,array3...) 1.数组从前往后,依次排序;前一组数中值相同时,才考虑后一个数组中的值排序;2.任一数组排序变......
  • 数组与结构体
    前言先考虑这样的问题:当你被要求定义十个变量时,你会怎么办?可以像a1,a2,a3···这样一个一个的定义出来。但是,当你被要求定义一千个,一万个变量的时候呢?肯定就不能一个一......
  • 数组,指针与现代c++标准
    #include<iostream>#include<algorithm>#include<math.h>#include<string>usingnamespacestd;classInfo{public:Info(stringnickname,stringcon......
  • 后台管理系统 数组去重 避免踩坑!
    不要把数组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.如何声明一个......