<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      類與數組,指針

      #pragma once
      
      #include <iostream>
      #include <algorithm>
      
      using namespace std;
      
      class vectorInt {
      public:
          vectorInt(int len)
              : length{len} {
                  cout << "constructor 1 called" << endl;
                  p = new int[length];
              }
          vectorInt(int len,int val)
              : length{len} {
                  cout << "constructor 2 called" << endl;
                  p = new int[length];
                  for(int i=0;i<length;i++) {
                      *(p+i) = val;
                  }
              }
          vectorInt(const vectorInt& v)
              : length{v.length} {
                  cout << "copy constructor called" << endl;
                  p = new int[length];
                  for(int i=0;i<length;i++) {
                      *(p+i) = v.at(i);
                  }
              }
          ~vectorInt() {
              cout << "destructor called" << endl;
              delete[] p;
          }
          int &at(int i) const{
              return *(p+i);
          }
          int get_size() const {
              return length;
          }
          friend void output(const vectorInt& v) {
              for(int i=0;i<v.length;i++) {
                  cout << *(v.p+i) << ", ";
              }
              cout << endl;
          }
      private:
          int *p;
          int length;
      };
      

        

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

        

      #pragma once
      
      #include <iostream>
      
      using std::cout;
      using std::endl;
      
      class Matrix {
      public:
          Matrix(int n)
              : lines{n},cols{n} {
                  p = new double[n*n];
              }                  
          Matrix(int n, int m)
              : lines{n},cols{m} {
                  p = new double[n*m];
              }      
          Matrix(const Matrix &X)
              : lines{X.lines},cols{X.cols} {
                  p = new double[lines*cols];
                  for(int i=0;i<lines*cols;i++) {
                      p[i] = X.p[i];
                  }
              }           
          ~Matrix() {
              delete[] p;
          }                     
      
          void set(const double *pvalue) {
              for(int i=0;i<lines*cols;i++) {
                  p[i] = pvalue[i];
              }
          } 
          void set(int i, int j, int value) {
              p[i*cols+j] = value;
          }
          double &at(int i, int j){
              return p[i*cols+j];
          }        
          double at(int i, int j) const {
              return p[i*cols+j];
          }
          int get_lines() const {
              return lines;
          }           
          int get_cols() const {
              return cols;
          }              
          void print() const {
              for(int i=0;i<lines;i++) {
                  for(int j=0;j<cols;j++) {
                      cout << p[i*cols+j] << ", ";
                  }
                  cout << endl;
              }
          }                
      
      private:
          int lines; 
          int cols;  
          double *p;
      };
      

        

      #include <iostream>
      #include "matrix.hpp"
      
      void test() {
          using namespace std;
      
          double x[] = {1, 2, 3, 4, 5, 6};
      
          Matrix m1(3, 2);    
          m1.set(x);        
          m1.print();      
          cout << "the first line is: " << endl;
          cout << m1.at(0, 0) << " " << m1.at(0, 1) << endl;  
          cout << endl;
      
          Matrix m2(2, 3);
          m2.set(x);
          m2.print();
          cout << "the first line is: " << endl;
          cout << m2.at(0, 0) << " " << m2.at(0, 1) << " " << m2.at(0, 2) << endl;
          cout << endl;
      
          Matrix m3(m2);    
          m3.set(0, 0, 111);  
          m3.print();
      }
      
      int main() {
          test();
      }
      

        

      實驗總結:

      聲明指針變量時,必須指定指針所指向變量的類型,因為不同的變量類型占用不同的存儲空間。一些指針操作需要知道操作對象的大小。另外,程序必須知道儲存在指定地址上的數據類型。實參和形參指向同一個地址,他們只是指向相同,指針變量自身的地址卻不相同.也就是說當形參新指向了一塊新內存時它不能為實參也同樣帶回一塊內存地址。

      posted on 2022-11-04 09:03  cflxl  閱讀(33)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 日本不卡码一区二区三区| 伊人成色综合人夜夜久久| 亚洲熟女乱综合一区二区三区| 亚洲丰满熟女一区二区蜜桃| 人妻丰满熟妇AV无码区乱| 亚洲一级特黄大片在线观看| 亚洲av无码片在线播放| 99热成人精品热久久66 | 国产毛片精品av一区二区 | 91精品国产免费人成网站| 国产精品户外野外| 国产精品福利一区二区三区| 亚洲国产日韩a在线播放| 人妻体内射精一区二区三四| 99久久无码私人网站| 377p欧洲日本亚洲大胆| 午夜福利国产区在线观看| 久久中文字幕一区二区| 乱色精品无码一区二区国产盗| 国产蜜臀久久av一区二区| 亚洲精品麻豆一二三区| 林口县| 亚洲国产区男人本色| 成人精品天堂一区二区三区| 久热这里只有精品12| 国产精品视频第一第二区| 成全世界免费高清观看| 国产在线中文字幕精品| 成人做受120秒试看试看视频| 亚洲一区二区三区蜜桃臀| 精品日韩亚洲av无码| 国内精品久久人妻无码妲| 中文字幕人妻精品在线| Y111111国产精品久久久| 国产精品美女久久久久久麻豆| 日韩精品中文字幕有码| 长汀县| 高中女无套中出17p| 亚洲国产午夜福利精品| 无套内射视频囯产| 国产熟女一区二区五月婷|