#include <iostream>
using namespace std;
class Matrix
{
int ** matrixInClass;
public:
void setMatrix(int rowAmount, int colAmount);
void changeRowAndColumn(int rowAmount, int colAmount);
};
//==============================================================
void Matrix::setMatrix(int rowAmount, int colAmount) // заполнение массива данными
{
matrixInClass = new int*[rowAmount]; // выделяем память для матрицы
for (int i = 0; i < rowAmount; i++)
{
matrixInClass[i] = new int[colAmount];
}
for (int i = 0; i < rowAmount; i++) // записываем значения в массив
{
cout << " | ";
for (int j = 0; j < colAmount; j++)
{
matrixInClass[i][j] = i + j;
cout << matrixInClass[i][j] << " ";
}
cout << " | " << endl;
}
}
//==============================================================
void Matrix::changeRowAndColumn(int rowAmount, int colAmount)
{
int** tempMatrix = new int*[colAmount]; // выделяем память для временной матрицы
for (int i = 0; i < colAmount; i++)
{
tempMatrix[i] = new int[rowAmount];
}
for (int i = 0; i < colAmount; i++) // копируем столбцы в строки, а строки в столбцы
{
for (int j = 0; j < rowAmount; j++)
{
tempMatrix[i][j] = matrixInClass[j][i];
}
cout << endl;
}
for (int i = 0; i < rowAmount; i++) // Освобождаем память перед выделением новой
{
delete[] matrixInClass[i];
}
delete[] matrixInClass;
matrixInClass = new int*[colAmount]; // выделяем новую память
for (int i = 0; i < colAmount; i++)
{
matrixInClass[i] = new int[rowAmount];
}
for (int i = 0; i < colAmount; i++) // копируем из временной матрицы
{
cout << "|";
for (int j = 0; j < rowAmount; j++)
{
matrixInClass[i][j] = tempMatrix[i][j];
cout << matrixInClass[i][j] << " ";
}
cout << "|" << endl;
}
for (int i = 0; i < colAmount; i++) // Освобождаем память временной матрицы
{
delete[] tempMatrix[i];
}
delete[] tempMatrix;
}
int main()
{
setlocale(LC_ALL, "rus");
int rowAmount;
int colAmount;
cout << "Введите количество строк двумерного массива: ";
cin >> rowAmount;
cout << "Введите количество столбцов двумерного массива: ";
cin >> colAmount;
Matrix Object;
Object.setMatrix(rowAmount, colAmount);
cout << "\nЗамена значений строк на значения столбцов: ";
Object.changeRowAndColumn(rowAmount, colAmount);
return 0;
}
#include
#include
using namespace std;
class Point {
public:
void setArray(int** arr, int Row, int Col) {
for (int i = 0; i < Row; i ) {
arr[i] = new int[Col];
for (int g = 0; g < Col; g++) {
arr[i][g] = rand() % 50;
}
}
}
void swap(int **arr,int **arr1,int Col,int Row) {
for (int g = 0; g < Col; g++) {
arr1[g] = new int[Row];
for (int i = 0; i < Row; i ) {
arr1[g][i] = arr[i][g];
}
}
}
};
void main() {
int Row = 4, Col = 2;
srand(time(NULL));
Point a;
int** arr;
int** arr1;
arr1 = new int* [Col];
arr = new int* [Row];
a.setArray(arr, Row, Col);
for (int i = 0; i < Row; i ) {
for (int g = 0; g < Col; g++) {
cout << arr[i][g] << "\t";
}
cout << endl;
}
a.swap(arr, arr1, Col, Row);
cout << endl << endl;
for (int g = 0; g < Col; g++) {
for (int i= 0; i < Row; i ) {
cout << arr1[g][i] << "\t";
}
cout << endl;
}
}
3 room
Pflfxf #2
#include
#include
void sp() {
std::cout << '\n';
}
class Children {
private:
std::string firstName;
std::string lastName;
int age{};
public:
void enterInformation() {
std::cout <> firstName;
std::cout <> lastName;
std::cout <> age;
sp();
}
void printInformation() {
std::cout << "Name: " << firstName;
sp();
std::cout << "Last name: " << lastName;
sp();
std::cout << "Age: " << age;
}
};
int main()
{
Children a;
a.enterInformation();
a.printInformation();
return 0;
}
Complete the class, including the verification method
on the parity of integer values of tree nodes.
Odd values must be increased to
the nearest pair, and duplicates
should not be created
”Please help me very much”
Complete the class, including the verification method
on the parity of integer values of tree nodes.
Odd values must be increased to
the nearest pair, and duplicates
should not be created
#include
using namespace std;
class Matrica
{
public:
void vvod()
{
cin >> ctroka;
cin >> stolbcy;
int** mass = new int* [ctroka];
int** mass2 = new int* [stolbcy];
Mass(mass, mass2);
zamena(mass, mass2);
vyvod(mass, mass2);
}
private:
int ctroka, stolbcy;
void Mass(int** mass, int** mass2)
{
for (int i = 0; i < stolbcy; i )
mass[i] = new int[stolbcy];
for (int i = 0; i < stolbcy; i )
for (int j = 0; j > mass[i][j];
system(“cls”);
for (int i = 0; i < stolbcy; i )
{
for (int j = 0; j < ctroka; j )
cout << mass[i][j] << " ";
cout << endl;
}
for (int i = 0; i < ctroka; i )
mass2[i] = new int[ctroka];
}
void zamena(int** mass, int** mass2)
{
for (int i = 0; i < ctroka; i )
for (int j = 0; j < stolbcy; j )
mass2[i][j] = mass[j][i];
}
void vyvod(int** mass, int** mass2)
{
for (int i = 0; i < ctroka; i )
{
for (int j = 0; j < stolbcy; j )
cout << mass2[i][j];
cout << " " << endl;
}
}
};
void main()
{
Matrix A;
A.vvod();
}
Create a class, which includes the results of testing students in a group in three subjects,and then get a function to input and output data.
Include the members of the following function.
1. The surname of the student is produced,who did not pass at least one class
2. Academic quality,that is, the percentage of students,who scored more 75 points.
3. Name of the course with the highest percentage of achievement
4. List in descending order of student achievement
#include <iostream> using namespace std; class Matrix { private: int** arr; int** arr2; int rows, cols; public: void Fill_array(int rows_value, int cols_value) { rows = rows_value; cols = cols_value; arr = new int* [rows]; for (int i = 0; i < rows; i ) { arr[i] = new int[cols]; } for (int i = 0; i < rows; i ) { for (int j = 0; j < cols; j ) { arr[i][j] = 10 + rand()% + 50; cout << arr[i][j]<< "\t"; } cout << endl; } } void Change_rows_with_cols() { arr2 = new int* [cols]; for (int i = 0; i < cols; i ) { arr2[i] = new int[rows]; } cout << endl << endl; for (int i = 0; i < cols; i ) { for (int j = 0; j < rows; j ) { arr2[i][j] = arr[j][i]; cout << arr2[i][j] << "\t"; } cout << endl; } } ~ Matrix() { for (int i = 0; i < cols; i ) { delete[]arr2[i]; } cout << "Destructor for second matrix" << endl; delete[]arr2; for (int i = 0; i < rows; i ) { delete[]arr[i]; } cout << "Destructor for first matrix" << endl; delete[]arr; } }; int main() { Matrix first; first.Fill_array(2, 4); first.Change_rows_with_cols(); }