Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- duota n 3x3 matricų. rasti determinantų sumą ir vidurkį
- elementus iš klaviatūros
- 1) butina klase
- 2) destruktoriai all that shit
- 3) rodykles ir dinamine atmintis
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Determinantas
- {
- private:
- int x1, x2, x3, y1, y2, y3, z1, z2, z3;
- double determinantas;
- public:
- Determinantas() : x1(0), x2(0), x3(0), y1(0), y2(0), y3(0), z1(0), z2(0), z3(0) {}
- Determinantas (int a, int b, int c, int d, int e, int f, int g, int h, int i) : x1(a), x2(b), x3(c), y1(d), y2(e), y3(f), z1(g), z2(h), z3(f){}
- ~Determinantas(){}
- //
- void Ivedimas()
- {
- cout << "Iveskite matricos elementus: \n";
- cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> x3 >> y3 >> z3;
- }
- void showData()
- {
- cout << "Matrica atrodo taip: \n";
- cout << x1 << " " << y1 << " " << z1 << " \n";
- cout << x2 << " " << y2 << " " << z2 << " \n"
- cout << x3 << " " << y3 << " " << z3 << " \n"
- }
- int Skaiciavimas()
- {
- determinantas = (x1*y2*z3)+(y1*z2*x3)+(z1*x2*y3)-(z1*y2*x3)-(y1*x2*z3)-(x1*z2*y3);
- return determinantas;
- }
- };
- int maint ()
- {
- int n, suma=0;
- double vidurkis=0;
- cout << "Iveskite matricu skaiciu: \n";
- cin >> n
- Determinantas *matrix = new Determinantas[n]; // *matrix - rodykle // new Determinans[n] // sukuriama dinamine atmintis
- for (int i = 0; i++; i<n)
- {
- matrix[i].Ivedimas();
- matrix[i].showData();
- matrix[i].Skaiciavimas();
- suma = suma + matrix[i].skaiciavimas();
- }
- vidurkis = suma / n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement