Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct vect {
- double x;
- double y;
- double z;
- };
- void show(vect, int = 4);
- vect summ(vect, vect);
- vect sub(vect, vect);
- vect multi(vect, double);
- vect multi(double, vect);
- vect multi(vect, vect);
- int main(int count, char *args[]) {
- vect a{};
- a.x = 1;
- a.y = 2;
- a.z = 3;
- vect b{};
- b.x = 4;
- b.y = -5;
- b.z = 6;
- auto c = multi(a, b);
- show(c, 2);
- }
- vect summ(vect a, vect b) {
- vect c{};
- c.x = a.x + b.x;
- c.y = a.y + b.y;
- c.z = a.z + b.z;
- return c;
- }
- vect sub(vect a, vect b) {
- vect c{};
- c.x = a.x - b.x;
- c.y = a.y - b.y;
- c.z = a.z - b.z;
- return c;
- }
- vect multi(vect in, double num) {
- vect res{};
- res.x = in.x * num;
- res.y = in.y * num;
- res.z = in.z * num;
- return res;
- }
- vect multi(double num, vect in) {
- return multi(in, num);
- }
- vect multi(vect a, vect b) {
- vect res{};
- res.x = a.y * b.z - b.y * a.z;
- res.y = a.z * b.x - b.z * a.x;
- res.z = a.x * b.y - b.x * a.y;
- return res;
- }
- void show(vect shown, int size) {
- cout << "(" << setw(size) << shown.x << ";" << setw(size) << shown.y << ";" << setw(size) << shown.z << ")" << endl;
- }
Add Comment
Please, Sign In to add comment