实验四
#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