Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <locale>
- using namespace std;
- /*Создать класс, private-элемент которого двумерный массив.
- Класс будет содержать два метода: один заполнит массив значениями,
- второй произведет замену значений строк на значения столбцов.
- Преобразовать строки двумерного массива в столбцы*/
- class ReplaceRowOfCol
- {
- private:
- int **dynMas;
- void createMas(int row, int col){
- dynMas = new int*[row];
- for(int i = 0; i < row; i++){
- dynMas[i] = new int[col];
- }
- }
- public:
- void enterArray(int row, int col){
- createMas(row, col);
- cout << " Enter Array: " << endl;
- for(int i = 0; i < row; i++){
- cout << endl;
- for(int j = 0; j < col; j++){
- cout << "[" << i << "][" << j << "]: ";
- cin >> dynMas[i][j];
- }
- }
- }
- void print(int row, int col){
- for(int i = 0; i < row; i++){
- for(int j = 0; j < col; j++){
- cout << dynMas[i][j] << " ";
- }
- cout << endl;
- }
- }
- void replace(int row, int col){
- int** buf = new int*[col];
- for(int i = 0; i < col; i++){
- buf[i] = new int[row];
- }
- for(int i = 0; i < col; i++){
- for(int j = 0; j < row; j++){
- buf[i][j] = dynMas[j][i];
- }
- }
- for (int i = 0; i < col; i++)
- {
- delete [] dynMas[i];
- }
- delete[] dynMas;
- createMas(col, row);
- memcpy(dynMas, buf, row*col);
- /*
- for (int i = 0; i < row; i++)
- {
- delete [] buf[i];
- }
- delete[] buf;*/
- }
- };
- int main(){
- setlocale(LC_ALL, "Russian");
- ReplaceRowOfCol arr = ReplaceRowOfCol();
- arr.enterArray(5,5);
- arr.print(5,5);
- arr.replace(5,5);
- arr.print(5,5);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement