首页 > 其他分享 >实验六

实验六

时间:2022-12-01 18:02:50浏览次数:46  
标签:std cout int Vector 实验 include size

实验四

#include<iostream>
#include<cassert>

using std::cout;
using std::endl;
template<class T>
class Vector {
public:
    Vector(int n, int m);
    Vector(int n);
    Vector(const Vector<T>& a);
    ~Vector();
    friend void output(Vector<T>& p1) {
        for (int i = 0; i < p1.size; i++)
        {
            cout << p1.p[i] << ",";
        }
        cout << endl;
    }
    T& at(int index) {
        return p[index];
       
    }
    T& operator[](int i)
    {
        return p[i];
    }
private:
    int size;
    T* p;
};
template<class T>
Vector<T>::Vector(int n) :size(n) {
    cout << "constructor 1 called." << endl;
    p = new T[size];
    int m = 1;
    for (int i = 0; i < size; i++)
    {
        p[i] = m;
    }
};
template<class T>
Vector<T>::Vector(int n, int m) :size(n) {

    p = new T[size];
    for (int i = 0; i < size; i++)
    {
        p[i] = m;
    }
};
template<class T>
Vector<T>::Vector(const Vector<T>& a) :size{ a.size }
{
    cout << "constructor 2 called." << endl;
    cout << "copy constructor called." << endl;
    p = new T[size];
    for (int i = 0; i < size; i++)
    {
        p[i] = a.p[i];
    }
}
template<class T>
Vector<T>::~Vector()
{
    delete[] p;
}

 

 

 

实验五

#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;
void output(std::ostream& out) {
    int j = 26;
    out << "  ";
    for (int i = 97; i < 123; i++) {
        out << setw(2) << char(i);
    }
    out << endl;
    for (int i = 1; i < 27; i++) {
        out << setw(2) << i;
        j++;
           for (int k = j; k < j + 26; k++) {
               int a = k % 26 + 65;
                out << setw(2) << char(a);
        }
            out << endl;
    }
}int main() {
    ofstream out;
    output(cout);
    out.open("cipher_key.txt");
    output(out);
    out.close();
    return 0;

}

 

标签:std,cout,int,Vector,实验,include,size
From: https://www.cnblogs.com/lhf123/p/16942207.html

相关文章

  • 实验六
    TASK3:int:char: char和int的的字节数不一样,int占一个字节数,插入占4个,改为char后,按4个数据写入,则写入了97“ 空格”“空格”“ 空格”“空格”,然后写入98,在写......
  • 实验四 Web服务器1-socket编程
    任务详情基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用LinuxSocket实现:time服务器的客户端服务器,提交程序运行截图echo服务器的客户端服务器,提交程序运行截图,服务器把客......
  • 实验6-模板类和文件
    task3:task3.1.cpp1#include<iostream>2#include<fstream>3#include<array>4#defineN55intmain()6{7usingnamespacestd;8array<int......
  • 网络渗透测试实验_1_网络扫描与网络侦察
    以下内容为课堂上的实验记录1. 实验目的和要求理解网络扫描、网络侦察的作用;通过搭建网络渗透测试平台,了解并熟悉常用搜索引擎、扫描工具的应用,通过信息收集为下一步渗......
  • 实验六
    1#include<iostream>2#include<fstream>3#include<array>4#defineN556intmain(){7usingnamespacestd;8array<char,N>x;91......
  • Python实验报告——第13章 Pygame游戏编程
    实验报告【实验目的】 1.掌握Pygame的基础知识。【实验条件】1.PC机或者远程编程环境。 【实验内容】1.完成第十三章  实例01:篮球自动弹跳。  实例01:创......
  • 实验6 模板类和文件I/O
    #include<iostream>#include<fstream>#include<array>#defineN5intmain(){usingnamespacestd;array<int,N>x{97,98,99,100,101};......
  • 实验四 Web服务器1-socket编程
    实验四Web服务器1-socket编程ipa查询网络状态echo服务器的客户端服务器,提交程序运行截图,服务器把客户端传进来的内容加入“服务器进程pid你的学号姓名echo:”......
  • 实验6 模板类和文件I/O
     实验任务3task3_1.cpp1#include<iostream>2#include<vector>3template<typenameT>4voidoutput(constT&obj){5for(auto&item:obj)6std::......
  • 实验六
    实验任务3task3_1.cpp源码:1#include<iostream>2#include<fstream>3#include<array>4#defineN55intmain(){6usingnamespacestd;7......