Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SejuCs.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <malloc.h>
- #include <Windows.h>
- class Matrix {
- private:
- float **tab;
- int N;
- int M;
- public:
- Matrix(int _N, int _M) {
- N = _N;
- M = _M;
- tab = (float **)malloc(N * sizeof(float*));
- for (int i = 0; i < N; i++)
- tab[i] = (float *)malloc(M * sizeof(float));
- for (int i = 0; i < N; i++)
- for (int j = 0; j < M; j++)
- tab[i][j] = 0;
- }
- ~Matrix() {
- free(tab);
- }
- Matrix(const Matrix& matrix) {
- tab = (float **)malloc(N * sizeof(float*));
- for (int i = 0; i < N; i++)
- tab[i] = (float *)malloc(M * sizeof(float));
- if (tab != NULL) {
- for (int i = 0; i < N; i++)
- for (int j = 0; j < M; j++)
- tab[i][j] = matrix.tab[i][j];
- }
- }
- void Display() {
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++)
- printf("%lf", tab[i][j]);
- printf("\n");
- }
- }
- Matrix& operator = (const Matrix& matrix) {
- tab = (float **)malloc(N * sizeof(float*));
- for (int i = 0; i < N; i++)
- tab[i] = (float *)malloc(M * sizeof(float));
- if (tab != NULL) {
- for (int i = 0; i < N; i++)
- for (int j = 0; j < M; j++)
- tab[i][j] = matrix.tab[i][j];
- }
- return *this;
- }
- const double operator () (int i, int j) const{
- return tab[i][j];
- }
- Matrix& operator = (const Matrix& matrix) {
- tab = (float **)malloc(N * sizeof(float*));
- for (int i = 0; i < N; i++)
- tab[i] = (float *)malloc(M * sizeof(float));
- if (tab != NULL)
- {
- for (int i = 0; i < N; i++)
- for (int j = 0; j < M; j++)
- tab[i][j] = matrix.tab[i][j];
- }
- return *this;
- }
- };
- int main()
- {
- Matrix matrix(2, 5);
- matrix.Display();
- matrix.~Matrix();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement