Другие языки программирования и технологии

Помогите кому не сложно с С++

Дано матрицу размерностью MxN (M строк, N столбцов) . Необходимо заполнить ее значениями и написать функцию, которая осуществляет циклический сдвиг строк и / или столбцов массива на указанное количество раз и в указанную сторону.
С подсветкой:
http://snipt.org/uhige2

#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

template <class>
void cycle_right_shift(T* a, int size, int offset) {
int offs = ((offset % size) + size) % size; // We want positive offset smaller than 'size'
T temp[offs]; // For saving the 'end' of 'a'
if (size <= 0) return; // Some kind of error input
memcpy(temp, a + (size - offs), offs * sizeof(T));// Save the the 'end' of 'a'
memcpy(a + offs, a, (size - offs)* sizeof(T)); // Shifting the 'beginning' of 'a' to the 'end'
memcpy(a, temp, (offs) * sizeof(T)); // Copy the saved 'end' to beginning
}

template <class>
void shift_rows(T** a, int rows, int columns, int offset) {
cycle_right_shift(a, rows, offset);
}

template <class>
void shift_columns(T** a, int rows, int columns, int offset) {
for(int i = 0; i < rows; i++) {
cycle_right_shift(a, columns, offset);
}
}

template <class>
void shift_rows_and_columns(T** a, int rows, int columns, int offset_rows, int offset_columns) {
shift_rows(a, rows, columns, offset_rows);
shift_columns(a, rows, columns, offset_columns);
}

void println (int **a, int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
cout << a[j] << ' ';
} cout << endl;
} cout << endl;
}

int main() {
int **a, i, j;
int x = 4, y = 7; // Строки/столбцы
a = new int*[x];
for (i = 0; i < x; i++) {
a = new int[y];
for (int j = 0; j < y; j++) {
a[j] = rand() % 100;
}
}

println (a, x, y);
shift_rows_and_columns(a, x, y, 1 /*row shift*/, 2 /*column shift*/);
println (a, x, y);
return 0;
}
Султан Султангазин
Султан Султангазин
1 895
Лучший ответ
Асет Cабыржанов
Асет Cабыржанов
97 810
Показывай, что написал - поможем, подскажем. А за тебя корячиться никто не будет.
И код лучше на pastebin.com выкладывай, сюда - ссылку.
Jason Bourne
Jason Bourne
54 754