首页 > 其他分享 >实验六

实验六

时间:2022-12-01 21:22:40浏览次数:32  
标签:int Vector 实验 x2 output include size

 

任务四、

vector.hpp

#pragma once
#include <iostream>
using namespace std;
template<typename T>
class Vector {
public:
    Vector(int n) :size{ n } { p = new T[n]; }
    ~Vector() { delete[] p; }
    Vector(const Vector<T> & newp);
    Vector(int n, T value) :size{ n } {
   
        p = new T[size];
        for (auto i = 0; i < size; i++)
            p[i] = value;
    }
    int get_size()const {
        return size;
    }
    T& at(int i) { return p[i]; }
    T& operator[](int index)
    {
        return p[index];
    }
private:
    int size;
    T* p;
    template<typename T1>
    friend void output( Vector<T1>& x);
};

template<typename T>
Vector<T>::Vector(const Vector<T>& newp) : size{ newp.size } {
   
    p = new T[size];
    for (auto i = 0; i < size; i++)
        p[i] = newp.p[i];
}
template<typename T1>
void output(Vector<T1>& x) {
    for (auto i = 0; i < x.size; i++)
        cout << x.at(i) << ", ";
    cout << endl;
};

task.cpp

#include<iostream>
#include"vector.hpp"
void test() {
    using namespace std;
    int n;
    cin >> n;
    Vector<double>x1(n);
    for (auto i = 0;i < n;++i)
        x1.at(i) = i * 0.7;
    output(x1);
    Vector<int> x2(n, 42);
    Vector<int> x3(x2);
    output(x2);
    output(x3);
    x2.at(0) = 77;
    output(x2);
    x3[0] = 999;
    output(x3);
}
int main()
{
    test();
}

 

 任务五、

#include<fstream>
#include<iostream>
#include<iomanip>
#define N 27
using namespace std;
char form[N][N];
void output(ostream& out) {
   for(int num=0;num<1;num++)
    for (int i = 0; i < N; i++) {
        if (i == 0) cout << "  ";
        else cout << setw(2) << form[i][0] - '0';
        for (int j = 1; j < N; j++) {
            cout << setw(2) << form[i][j];
        }
        cout << endl;
    }
}
int main() {
    ofstream out;
    out.open("cipher_key.txt");
    if (!out.is_open()) {
        cout << "fail to open the cipher_key.txt\n";
        return 1;
    }
    form[0][0] = ' ';
    for (int i = 1; i < N; i++) {
        form[0][i] = 'a' + i - 1;
        form[i][0] = i + '0';
    }
    int j;
    for (int i = 1; i < N; i++) {
        for (j = 1; j + i < N; j++)
            form[i][j] = form[0][j] - 32 + form[i][0] - '0';
        for (j; j + i >= N && j < N; j++)
            form[i][j] = form[0][j] - 58 + form[i][0] - '0';
    }
    output(out);
}

 

 

标签:int,Vector,实验,x2,output,include,size
From: https://www.cnblogs.com/shmily-cwh/p/16942794.html

相关文章

  • 实验6 模板类和文件I/O
    实验任务3#include<iostream>#include<fstream>#include<array>#defineN5intmain(){usingnamespacestd;array<int,N>x{97,98,99,100,101......
  • Android实验——使用Intent在Activity间传输数据
    一、实验要求和目的理解Activity组件的功能与作用;掌握使用Intent在多个Activity组件间传输数据的方法;掌握在AndroidManifest.xml中配置Activity组件的方法。二、实验......
  • Android实验——事件处理:显示持续触摸时间
    一、实验要求和目的掌握基于监听的事件处理机制,根据需求能够编写相应的事件处理程序。能够熟练应用各种布局管理器和控件进行界面设计。二、实验环境部署有Android......
  • web实验2
    基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用LinuxSocket实现:1.Web服务器的客户端服务器,提交程序运行截图2.实现GET即可,请求,响应要符合HTTP协议规范ubuntu运行截图1.......
  • web实验1-socket
    基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用LinuxSocket实现:1.time服务器的客户端服务器,提交程序运行截图timeserver代码#include<stdio.h>#include<unistd.h>#inc......
  • 实验六
    实验四#include<iostream>#include<cassert>usingstd::cout;usingstd::endl;template<classT>classVector{public:Vector(intn,intm);Vector(i......
  • 实验六
    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. 实验目的和要求理解网络扫描、网络侦察的作用;通过搭建网络渗透测试平台,了解并熟悉常用搜索引擎、扫描工具的应用,通过信息收集为下一步渗......