首页 > 其他分享 >实验六

实验六

时间:2022-12-06 19:55:22浏览次数:31  
标签:27 int ++ Vector 实验 include size

复制代码

#pragma once
#include<iostream>
using std::cout;
using std::endl;
template<typename T>
class Vector
{
public:
    Vector(T n) :size(n) { p = new T[n]; }
    Vector(T n, T value) :size(n)
    {
        p = new T[n];
        for (int i = 0; i < n; i++)
            p[i] = value;
    }
    Vector(const Vector& V):size{V.size}
    {
        p = new T[V.size];
        for (int i = 0; i < V.size; i++)
            p[i] = V.p[i];
    }
    ~Vector() { delete[]p; }
    T get_size()
    {
        return size;
    }
    T &at(int i)
    {
        return p[i];
    }
    T& operator[](int i)
    {
        return p[i];
    }
    friend void output(Vector& V)
    {
        for (int i = 0; i < V.size; i++)
        {
            cout << V.p[i]<<" ";
        }
        cout << endl;
    }
private:
    T size;
    T* p;
};
复制代码

 

 

 

 

修改数据后

 

 

 

 

 

复制代码
#include<iostream>
#include <fstream>
#include<string>
#include<iomanip>
using namespace std;
void output(std::ostream& out)
{
    string a[27][27] = { " " };
    int n = 0;
    for (int i = 1; i < 27; i++)
    {
        a[i][0] = to_string(i);
        a[0][i] = 97 + n;
        n++;
    }
    for (int i = 1; i < 27; i++)
    {
        n = i;
        for (int j = 1; j < 27; j++)
        {
            if (65 + n > 90)
            {
                a[i][j] = 65 + n - 26;
            }
            else
            {
                a[i][j] = 65 + n;
            }
            n++;
        }
    }
    for (int i = 0; i < 27; i++) {
        for (int j = 0; j < 27; j++) {
            out <<right<< setw(2) << a[i][j] << " ";
        }
        out << endl;
    }
}

int main()
{
    ofstream out;
    out.open("cipher_key.txt", ios::out);
        if (!out.is_open())
        {
            cout << "fail to open file\n";
            return 1;
        }
        output(out);
        output(cout);
        out.close();
}
复制代码

 

 

标签:27,int,++,Vector,实验,include,size
From: https://www.cnblogs.com/030227rzxx/p/16960332.html

相关文章

  • 实验6 模板类和文件IO
    task3_1.cpp#include<iostream>#include<fstream>#include<array>#defineN5intmain(){ usingnamespacestd; array<int,N>x{97,98,99,100,101}; ofstr......
  • 实验六
    3.1.cpp#include<iostream>#include<fstream>#include<array>#defineN5intmain(){usingnamespacestd;array<int,N>x{97,98,99,100,101}......
  • 实验六 模板类和文件IO
    1.1Vector.hpp:#include<iostream>#include<string>#include<iomanip>usingnamespacestd;template<classT>classVector{public:Vector(intn):s......
  • 实验6
    实验四vector.hpp#pragmaonce#include<iostream>usingnamespacestd;template<typenameT>classVector{public:Vector(intn):size{n}{p=newT[n......
  • 实验六 模板和文件IO
    task3_11#include<iostream>2#include<fstream>3#include<array>4#defineN556intmain(){7usingnamespacestd;89array<int,......
  • 云计算——实验3:AWS实验-EC2操作
    本次实验属于验证型实验,通过本次实验学生将掌握以下内容:1、EC2免费实例创建方法;2、EC2实例SSH连接以及命令使用。我使用阿里云进行注册和远程连接,aws需要使用信用卡,国......
  • 一点关于深度学习实验的思考:重复实验
    前言最近做深度学习实验,时常会感叹深度学习就像炼丹一样,效果好坏似乎就像上帝在掷骰子。后面反思了一下自己的实验方法,再反思了一下做实验的目的。什么时候我们可以自信......
  • 51单片机之继电器实验
    一、继电器(relay)的工作原理和特性   当输入量(如电压、电流、温度等)达到规定值时,使被控制的输出电路导通或断开的电器。可分为电气量(如电流、电压、频率、功率等)继......
  • Android实验十——使用SQLite数据库存储数据
    一、实验要求和目的掌握SQLite数据库的操作方法;掌握SQLiteOpenHelper类的使用。掌握Lsitview的使用。二、实验环境部署有AndroidStudio和AndroidSDK的主机;建议......
  • 本科课程【数字图像处理】实验1 - 腐蚀与膨胀
    大家好,我是【1+1=王】,热爱java的计算机(人工智能)渣硕研究生在读。如果你也对java、人工智能等技术感兴趣,欢迎关注,抱团交流进大厂!!!Goodbetterbest,neverletitrest,un......