Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string>
- using namespace std;
- class Array
- {
- private:
- int m_size; // размер массива
- int* content; // указатель на 1 элемент
- public:
- Array (): m_size(0), content(nullptr) {}
- Array (int size): m_size(size), content(new int[size]) {} //конструктор
- ~ Array() // деструктор
- {
- delete[] content;
- }
- int& operator[](int i)
- {
- return content[i];
- }
- void print()
- {
- for(int i = 0; i < size(); i++)
- {
- cout << content[i] << ", ";
- }
- cout << endl;
- }
- void printPadded ()
- {
- for (int i = 0; i < size(); i = i + 4)
- {
- for (int j = 0; j < 4; j++)
- {
- cout << content[i + j] << " ";
- }
- cout << endl;
- }
- }
- void input ()
- {
- for (int i = 0; i < size(); i++)
- {
- cin >> content[i];
- }
- }
- int size () const //getter размера
- {
- return m_size;
- }
- void generate () // генератор элементов
- {
- for(int i = 0; i < size(); i++)
- {
- content[i] = rand() % 101 + (-100);
- }
- }
- void decartMult (Array& A, Array& B, Array& C, Array& D)
- {
- for (int a = 0; a < A.size(); a++){
- for (int b = 0; b < B.size(); b++){
- for (int c = 0; c < C.size(); c++){
- for (int d = 0; d < D.size(); d++){
- (*this)[(((a * B.size() + b) * C.size() + c) * D.size() + d) * 4 + 0] = A[a];
- (*this)[(((a * B.size() + b) * C.size() + c) * D.size() + d) * 4 + 1] = B[b];
- (*this)[(((a * B.size() + b) * C.size() + c) * D.size() + d) * 4 + 2] = C[c];
- (*this)[(((a * B.size() + b) * C.size() + c) * D.size() + d) * 4 + 3] = D[d];
- }
- }
- }
- }
- }
- };
- // anastasiya3161@gmail.com - почта Насти по сратчу
- int main() {
- int i, j, k, m;
- cout << "Enter size of A" << endl;
- cin >> i;
- Array A(i);
- cout << "Enter size of B" << endl;
- cin >> j;
- Array B(j);
- cout << "Enter size of C" << endl;
- cin >> k;
- Array C(k);
- cout << "Enter size of D" << endl;
- cin >> m;
- Array D(m);
- cout << "Enter " << i << " elements of A" << endl;
- A.input();
- cout << "Enter " << j << " elements of B" << endl;
- B.input();
- cout << "Enter " << k << " elements of C" << endl;
- C.input();
- cout << "Enter " << m << " elements of D" << endl;
- D.input();
- Array Res(A.size() * B.size() * C.size() * D.size() * 4);
- Res.decartMult(A, B, C, D);
- cout << "Result of this shit:" << endl;
- Res.printPadded();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement