首页 > 其他分享 >实验六

实验六

时间:2022-11-30 13:34:30浏览次数:33  
标签:int out Vector 实验 include data size

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

void test() {
    ofstream out;
    out.open("cipher_ke.txt");
    if (!out.is_open()) {
        cout << "fail to open cipher_key.txt to write" << endl;
        return;
    }
    out << "  ";
    cout << "  ";
    for (int i = 0, j = 97; i < 26; i++ ,j++) {
        char x = j;
        cout << setw(2) << setfill(' ') << x;
        out << setw(2) << setfill(' ') << x;
    }
    out << endl;
    cout << endl;

    //密码表
    for (int k = 1; k <= 26; k++) {
        cout << setw(2) << setfill(' ') << k;
        out << setw(2) << setfill(' ') << k;

        static int i = 66;
        int j, a;
        j = i;
        int m;
        for (a = i; a <= 90; a++) {
            char x1 = a;
            cout << setw(2) << setfill(' ') << x1;
            out << setw(2) << setfill(' ') << x1;
        }
        for (m = 65; m < j; m++) {
            char x2 = m;
            cout << setw(2) << setfill(' ') << x2;
            out << setw(2) << setfill(' ') << x2;
        }
        i++;
        cout << endl;
        out << endl;
    }
}

int main() {
    test();
}

 

 

#pragma once
#pragma once
#include<iostream>
#define MAXSIZE 10000
using namespace std;

template<typename T>

class Vector {
public:
    //构造函数与析构函数
    Vector(int n) {
        data = new T[n];
        size = n;
    }

    Vector(int n, T value) {
        data = new int[n];
        size = n;
        for (int i = 0; i < size; i++) {
            data[i] = value;
        }
    }

    Vector(const Vector<T>& x) {
        size = x.size;
        data = new int[size];

        for (int i = 0; i < size; i++) {
            data[i] = x.data[i];
        }

    }

    ~Vector<T>() {
        delete[] data;
    }

    //成员函数
    T& at(int i) { return data[i]; }
    T& operator[](int i) { return data[i]; }
    int get_size() { return size; }

private:
    T* data;
    int size;

    friend void output(const Vector& x) {
        for (int i = 0; i < x.size; i++) {
            cout << x.data[i] << " ";
        }
        cout << endl;
    }
};

 

标签:int,out,Vector,实验,include,data,size
From: https://www.cnblogs.com/jat2003725w/p/16938122.html

相关文章

  • 实验五
    task4:task4.cpp#include<iostream>#include"pets.hpp"voidplay(MachinePets&obj){std::cout<<obj.get_nickname()<<"says"<<obj.talk()<<std::e......
  • 实验五
    task4:源代码:1#include<iostream>2#include<cstring>3usingnamespacestd;4classMachinePets{5private:6stringnickname;7pub......
  • 实验5
    task4:pet.hpp#pragmaonce#include<iostream>usingnamespacestd;classMachinePets{ public: MachinePets(conststrings){ nickname=s; } virtualstri......
  • 实验5
    task4:pets.hpp:#pragmaonce#include<iostream>#include<string>usingnamespacestd;classMachinePets{public:MachinePets(){}MachinePets(consts......
  • 实验五
    #pragmaonce#include<iostream>#include<string>usingnamespacestd;classMachinePets{private:stringnickname;public:MachinePets(conststring&s......
  • 实验五
    Task4pets.hpp#pragmaonce#include<iostream>#include<string>usingnamespacestd;classMachinePets{public:MachinePets(conststrings):nickname(s)......
  • 【Java】Task07实验4第5题解析
    //TODO1:添加一个字段percent,用以表示百分秒privateintpercent;按照类的封装性要求,字段一般定义为私有的 //TODO2:添加一个只读属性getPercen......
  • 实验五
    实验任务四task4.cpp#include<iostream>#include"pets.hpp"voidplay(MachinePets&obj){std::cout<<obj.get_nickname()<<"says"<<obj.talk()<<st......
  • 实验五
    实验任务4#include<iostream>#include"pets.hpp"voidplay(MachinePets&obj){std::cout<<obj.get_nickname()<<"says"<<obj.talk()<<std::endl;......
  • 实验5
    实验4pets.hpp#pragmaonce#include<iostream>#include<string>usingnamespacestd;classMachinePets{public:MachinePets(conststrings){......