Здравствуйте.
Ваш конкретно случай:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
srand(unsigned(time(0)));
unsigned n, m;
cout << "Enter NxM:\n";
cout << "N: "; cin >> n;
cout << "M: "; cin >> m;
int** array = new int* [n];
for (unsigned f = 0; f < n; f++)
{
array[f] = new int[m + 1];
}
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << "Enter array[" << g << "][" << f << "]: ";
cin >> array[g][f];
}
}
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
cout << endl << endl;
unsigned add = m;
unsigned r = m - 1, w = m;
for (unsigned f = 0; f < n; f++)
{
for (auto l = 0; l < (m - add); l++)
{
swap(array[f][r--], array[f][w--]);
}
r = m - 1; w = m;
}
cout << "Enter odds column:\n";
for (unsigned g = 0; g < n; g++)
{
cout << "Array [" << g + 1 << "][" << add << "]: ";
cin >> array[g][add];
}
cout << endl << endl;
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m + 1; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
for (auto x = 0; x < n; x++)
{
delete[]array[x];
}
delete[] array; array = nullptr;
return 0;
}
Общий случай:
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
template<class type>
class Formatted_Entrance
{
private:
type** array = nullptr;
unsigned n, m, add; bool pos;
int reptiloid() // защищенный ввод
{
string h; cin >> h;
try
{
return stoi(h);
}
catch (exception& u)
{
cerr << u.what() << endl;
exit(-1);
}
}
void initialize()
{
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << "Enter array[" << g << "][" << f << "]: ";
cin >> array[g][f];
}
}
}
void adder()
{
cout << "Enter the number to place: ";
add = reptiloid();
if (pos == 0)
{
unsigned r = n - 1, w = n;
for (unsigned f = 0; f < m; f++)
{
for (auto l = 0; l < (n - add); l++)
{
swap(array[r--][f], array[w--][f]);
}
r = n - 1; w = n;
}
cout << "Enter odds row:\n";
for (unsigned g = 0; g < m; g++)
{
cout << "Array [" << add << "][" << g << "]: ";
cin >> array[add][g];
}
}
if (pos == 1)
{
unsigned r = m - 1, w = m;
for (unsigned f = 0; f < n; f++)
{
for (auto l = 0; l < (m - add); l++)
{
swap(array[f][r--], array[f][w--]);
}
r = m - 1; w = m;
}
cout << "Enter odds column:\n";
for (unsigned g = 0; g < n; g++)
{
cout << "Array [" << g << "][" << add << "]: ";
cin >> array[g][add];
}
}
}
void display(unsigned extra)
{
unsigned r1, r2;
if (pos == 0)
{
r1 = extra; r2 = m;
}
if (pos == 1)
{
r1 = n; r2 = extra;
}
for (unsigned g = 0; g < r1; g++)
{
for (unsigned f = 0; f < r2; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
}
void lay(unsigned r)
{
initialize(); //заполение первоначальной матрицы
display(r - 1);// вывод ее на экран
cout << endl << endl;
adder(); // добавление строки или столбца
cout << endl << endl;
display(r);// вывод обновленной матрицы
}
public:
Formatted_Entrance()
{
cout << "Enter NxM:\n"; string choice;
cout << "N: ";
n = reptiloid();
cout << "M: ";
m = reptiloid();
cout << "What would you like to be extra - row or column?\n";
cin >> choice;
if (choice == "row")
{
pos = 0;
array = new type * [n + 1];
for (unsigned f = 0; f < n + 1; f++)
{
array[f] = new type[m];
}
lay(n + 1);
}
else if (choice == "column")
{
pos = 1;
array = new type * [n];
for (unsigned f = 0; f < n; f++)
{
array[f] = new type[m + 1];
}
lay(m + 1);
}
else
{
cout << "unexpected err";
exit(-1);
}
}
~Formatted_Entrance()
{
unsigned p1;
if (pos == 0)
{
p1 = n + 1;//после вставки строки
}
if (pos == 1)
{
p1 = n;//после вставки колонки
}
for (auto x = 0; x < p1; x++)
{
delete[] array[x];
}
delete[] array; array = nullptr;
}
};
int main()
{
srand(unsigned(time(0)));
Formatted_Entrance<string> obj;
return 0;
}