Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream.h>
- #include <stdlib.h>
- #include <time.h>
- #include <iomanip.h>
- class Matr
- {
- public:
- int* matr;
- int* matrI;
- int Mrow;
- int Mcol;
- int Mlast;
- Matr(int r, int c);
- ~Matr();
- void Init(void);
- void Print(void);
- void Del(int el);
- void Add(int ee);
- };
- ///////////////////////////////////////
- Matr::Matr(int r, int c)
- {
- Mrow= r; Mcol= c; Mlast= Mrow*Mcol;
- matr= new int [Mrow*Mcol];
- matrI= new int [Mrow*Mcol];
- }
- ///////////////////////////////////////
- Matr::~Matr()
- {
- delete [] matr;
- delete [] matrI;
- }
- ///////////////////////////////////////
- void Matr::Del(int el)
- {
- Mlast= Mrow*Mcol-el;
- delete [] matrI;
- matrI= new int[Mlast];
- for (int q=0; q< Mlast; q++)
- { matrI[q]= matr[q]; }
- delete [] matr;
- matr= new int[Mlast];
- for (int q=0; q< Mlast; q++)
- { matr[q]= matrI[q]; }
- }
- ///////////////////////////////////////
- void Matr::Add(int ee)
- {
- delete [] matrI;
- matrI= new int[Mlast+ee];
- for (int q=0; q< Mlast; q++)
- { matrI[q+ee]= matr[q]; }
- for (int q=0; q<ee; q++)
- { matrI[q]= '0'; }
- delete [] matr;
- Mlast= Mlast+ee;
- matr= new int[Mlast];
- for (int q=0; q< Mlast; q++)
- { matr[q]= matrI[q]; }
- }
- ///////////////////////////////////////
- void Matr::Init(void)
- {
- randomize();
- for (int q=0; q< Mrow*Mcol; q++)
- { matr[q]= rand()%100; }
- }
- ///////////////////////////////////////
- void Matr::Print(void)
- {
- int clmn=0;
- for (int q=0; q< Mlast; q++)
- {
- cout<<setw(3)<<matr[q]; clmn++;
- if (clmn==Mcol) { clmn=0; cout<<endl; }
- }
- }
- ///////////////////////////////////////
- int main (void)
- {
- int row; int col;
- cout<<"Input ROW= "; cin>>row;
- cout<<"Input COL= "; cin>>col;
- cout<<endl<<endl;
- cout<<"Matrix is burn"<<endl<<endl;
- Matr Matr0(row, col);
- Matr0.Init();
- Matr0.Print();
- cout<<endl<<endl<<"Deleting Matrix"<<endl<<endl;
- Matr0.Del(5);
- Matr0.Print();
- cout<<endl<<endl<<"Adding Matrix"<<endl<<endl;
- Matr0.Add(3);
- Matr0.Print();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment