#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;
}
I did on Garcia 2 task
#include
#include”windows.h”
#include
using namespace std;
class Children{
private:
string name;
string fleam;
float vik;
public:
Children(): bay(0)
{ }
Children(string r1,string w2,float w3): name(r1),fleam(W2),bay(w3)
{ }
void foma();
void dota();
};
void Children::foma(){
cout<<"Добрий день "<<endl<<"Ведіть імя фімілію і рік"<>bay;
// cout<<"Імя "<<name<<endl<<"Фамілія "<<fleam<<endl<<"Рік"<<bay<<endl;
}
void Children::dota(){
cout<<"Імя "<<name<<endl<<"Фамілія "<<fleam<<endl<<"Рік "<<bay<<endl;
}
int main(){
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
cout<<"Привіт !1!";
Children ee1;
ee1.foma();
ee1.dota();
return 0;
}
Sasha, not necessary here, in comments, write this garbage – your code!
I have a question, dear experts!
In the example of the third problem solutions, we have created a temporary matrix tempMatrix new configuration, copied into it one by one all the elements, then freed memory, occupied matrix matrixInClass, identified new memory matrixInClass, alternately copied all the elements and freed memory, occupied temporary matrix.
I went a little bit different way, shorter. Everything works without error, but I want to know, can I missing something(knowingly cut). Your code flooded on codepad –> http://codepad.org/vAuUf5pO
I am doing so:
Create a temporary matrix tempMatrix new configuration, I copied into it from the elements of the matrix matrixInClass, freed memory, occupied matrixInClass.
everything exactly up to this point as well.
And now I just assign a value to a pointer matrixInClass tempMatrix so:
matrixInClass = tempMatrix;
tempMatrix = 0;
Then matrixInClass started to point to a memory portion, occupied tempMatrix. So now we do not need perevydelyat memory matrixInClass, as in the example, then copy the element by element array and free memory.
Question I have the following: It may be a reason you did so, how did, I suppose somewhere in a memory leak??? Thanks in advance for your reply!
Help solve the problem!
The challenge for the interaction among the classes. Razrabotat Systems 'depot'. Manager distributes applications for flights between the driver and assigns for this Car. The driver can make a request for repair. Manager may remove the driver from the work. The driver makes a note of the flight and the condition of the car.
My second task of data entry for the second child passes to enter a name, right to the name. Why? Exactly the same code, but instead “char” – “string”.
Too samoe..Hotya I use char..
in string 39 cin.get();
I wrote it?
This is done, to clear the input buffer output from the keyboard. Sometimes in this buffer may remain some data.
in string 39
I wrote it?
This is done, to clear the input buffer output from the keyboard. Sometimes in this buffer may remain some data.
The third task in a row 25 array incorrectly filled
I was his task to fill the array like this
In string 25 – This designer matrix, which is filled by any of its rules.
A 11, 22, 33 … in the condition shown both “for example”.
A task – on the transposition of a matrix. Perhaps, it was not written in the best way, but all show – correctly.
help to solve the problem:
Describe the class of "USE".
Each entry contains the form number, surname and initials of the student, Completion year, name items and evaluation.
Provide for the possibility of formation: list from the keyboard and from file, Print the entire list; list of documents, where the average score below the CSE (higher) secondary; list of documents, The maximum score for a given discipline
I really liked the job 3. interesting!!
Goal number 2
#include
#include
using namespace std;
class MyClass
{
char name[32];
char sourcename[32];
int age;
public:
void Set_MyClass()
{
cout <> this->name;
cout <> this->sourcename;
cout <> this->age;
}
void Get_MyClass()
{
cout << "Name " << name << endl;
cout << "Source " << sourcename << endl;
cout << "Age " << age << endl;
}
};
int main()
{
setlocale(LC_ALL, "Ukrainian");
system("color A");
MyClass first;
MyClass second;
cout << "Enter your date" << endl;
first.Set_MyClass();
second.Set_MyClass();
cout << "\tYour date" << endl;
first.Get_MyClass();
second.Get_MyClass();
_getch();
return 0;
}
There must be a method. Somehow, when some threw garbage reflected
void Set_MyClass()
{
cout <> this->name;
cout <> this->sourcename;
cout <> this->age;
}