首页 > 其他分享 >实验六

实验六

时间:2022-12-03 15:44:26浏览次数:33  
标签:std int size 实验 include open out

task3_1.cpp

#include<iostream>
#include<fstream>
#include<array>
#define N 5
int main(){
    using namespace std;
    array<int,N> x{97,98,99,100,101};
    ofstream out;
    out.open("data.txt",ios::binary);
    if(!out.is_open()){
        cout<<"fail to open data1.dat\n";
        return 1;
    }
    out.write(reinterpret_cast<char *>(&x),sizeof(x));
    out.close();
} 

task3_2.cpp

#include<iostream>
#include<fstream>
#include<array>
#define N 5
int main(){
    using namespace std;
    array<char,N>x;
    ifstream in;
    in.open("data.dat1",ios::binary);
    if(!in.is_open()){
        cout<<"fail to open data1.dat\n";
        return 1;
    }
    in.read(reinterpret_cast<char *>(&x),sizeof(x));
    in.close();
    for(auto i=0;i<N;i++)
    cout<<x[i]<<",";
    cout<<"\b\b\n";
}

 

 

 task4.cpp

#include<iostream>
#include"vector.h"
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.6;
    
    output(x1);
    
    Vector<int> x2(n,88);
    Vector<int> x3(x2);
    
    output(x2);
    output(x3);
    
    x2.at(0)=66;
    output(x2);
    
    x3[0]=666;
    output(x3);
}
int main(){
    test();
}

vector.hpp

#pragma once
#include<iostream>
using namespace std;
template<typename T>
class Vector{
    public:
        Vector(int n):size{n}{
        value=new T[n];        
        }
        Vector(int n,T v):size{n}{
        value=new T[n];
        for(int i=0;i<n;i++)
        value[i]=v;
        }
        Vector(const Vector<T> &a):size{a.size}{
            value=new T[size];
            for(int i=0;i<size;i++)
            value[i]=a.value[i];
        }
        T &operator[](int i){
            return value[i];
        }
        int get_size() const{
        return size;
        }
        T &at(int index){
            return value[index];
        }
        friend void output(const Vector<T> &a){
        for(int i=0;i<a.size;i++)
        cout<<a.value[i]<<",";
        cout<<"\b\b\n";
        }
    private:
        int size;
        T *value;
};

 

 task5.cpp

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
char password[27][27];

void output(std::ostream &out){
    for(int i=0;i<=26;i++){
        for(int j=0;j<=26;j++){
            if(j==0&&i!=0)
                cout<<left<<setw(2)<<password[i][j]-'0'<<" ";
            else
                cout<<left<<setw(2)<<password[i][j]<<" ";
        }
            cout<<endl;
    }
    for(int i=0;i<=26;i++){
        for(int j=0;j<=26;j++){
            if(j==0&&i!=0)
                out<<left<<setw(4)<<password[i][j]-'0'<<" ";
            else
                out<<left<<setw(4)<<password[i][j]<<"  ";
        }
            out<<endl;
    }
}
int main(){
    ofstream out;
    
    password[0][0]=' ';
    for(int i=0,j=1;j<=26;j++)
        password[i][j]='a'+j-1;
    for(int i=1,j=0;i<=26;i++)
        password[i][j]=i+'0';
    for(int i=1;i<=26;i++){
        for(int j=1;i+j<=26;j++)
            password[i][j]='A'+i+j-1;
    }
    for(int i=26;i>=1;i--)
        for(int j=26;i+j>26&&j>=1;j--)
            password[i][j]='A'+i+j-27;
    out.open("cipher_key.txt", ios::binary);
    if(!out.is_open()) {
        cout << "fail to open cipher_key.txt\n";
        return 1;
    }
    output(out);
    system("pause");
}

 

 

标签:std,int,size,实验,include,open,out
From: https://www.cnblogs.com/yzhag/p/16948164.html

相关文章

  • oop 实验6 模板类和文件I/O
    task3程序源码task3_1.cpp1#define_CRT_SECURE_NO_WARNINGS12#include<iostream>3#include<fstream>4#include<array>5#defineN56usingnames......
  • python实验报告(第13章)
    一、实验目的1.掌握Pygame的基础知识。二、实验环境python版本:3.10(64-bit)三、实验内容1.实例1  实验结果:  四、实验分析:1.掌握了Pygame的基础知识。......
  • 2022/12/3 Python实验报告
      实验报告1、实验目的和要求了解并掌握Pygame的基本应用2、实验环境笔记本与Python书本3、实验过程实例01制作一个跳跃的小球游戏创建一个游戏......
  • 实验6
    实验6.3task3.11#include<iostream>2#include<fstream>3#include<array>4#defineN556intmain(){7usingnamespacestd;89arr......
  • Python实验报告
    实验13:Pygame游戏编程一、实验目的和要求学会Pygame的基本应用二、Pygame的优点及应用  使用Python进行游戏开发的首选模块就是Pygame,专为电子游戏设计(包括图像、......
  • 基于yolo进行目标检测的实验和研究【BLOG】
          根据我接触到的项目经验来看,需要我们进行检测的不是自然场景下的任意物体,而是特定场景下一类物体。典型的就是钢管识别,这些照片一般都是在厂区里面拍的、......
  • Python实验报告——第13章 Pygame游戏编程
    实验报告实例01:制作一个跳跃的小球游戏代码如下:importsysimportpygamepygame.init()size=width,height=640,480screem=pygame.display.set_mode(size)c......
  • 3.2动态分析基础实验(2)--《恶意代码分析实战》
    实验三Lab03-03.exe1.当使用ProcessExplorer工具进行监视的时候,注意到了什么?2.可以找出内存修改的行为吗?3.这个恶意代码在主机上的感染迹象特征是什么?4.这个恶意代码......
  • Python实验报告(第13章)
    实验13:Pygame游戏编程一、实验目的和要求学会Pygame的基本应用二、实验环境软件版本:Python3.1064_bit三、实验过程1、实例1:制作一个跳跃的小游戏(1)代码如下:1......
  • 2.1 实验:反病毒引擎扫描、编译时间、查壳、导入表查看、字符串查看--《恶意代码分析
    实验内容:1、将文件上传到http://www.VirusTotal.com进行分析并查看报告。文件匹配到了已有的反病毒软件特征吗?(国内用https://www.virscan.org/替代)2、这些文件是什么时候......