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


Помогите кому не сложно с С++
Дано матрицу размерностью 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;
}
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;
}



Показывай, что написал - поможем, подскажем. А за тебя корячиться никто не будет.
И код лучше на pastebin.com выкладывай, сюда - ссылку.
И код лучше на pastebin.com выкладывай, сюда - ссылку.
Похожие вопросы
- Нужно создать класс треугольник. Задание небольшое. Очень прошу помочь, кому не сложно
- Кому не сложно покритикуйте дизайн =))
- Кому не сложно помогите с С++
- Помогите с помощью однострочных комментариев объясните программу каждую строчку. Кому не сложно :D Заранее спасибо
- зайдите кому не сложно , пожалуйста!!!!
- Господа программисты! Сделайте прогу, кому не сложно!
- Задаю этот вопрос уже 3-й раз. Язык с++. Алгоритм я понимаю но вставить в код не могу ( Кому не сложно скиньте код!
- Всем привет! Кому не сложно, проверьте, пожалуйста, на правильность написание моего когда на алгоритмическом языке
- небольшая задачка по С++, помогите, кому не лень
- помогите, кому не трудно, перевести с языка Pascal на язык СИ код программы