Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- class VECTOR {
- private:
- int v[3];
- public:
- // контруктор по умочанию
- VECTOR();
- // контруктор с тремя аргументами
- VECTOR(int a, int b, int c);
- void read();
- void print();
- VECTOR mult(int s) const ;
- VECTOR operator+(const VECTOR& other);
- VECTOR operator-(const VECTOR& other);
- VECTOR& operator--();
- };
- VECTOR::VECTOR() {
- v[0] = v[1] = v[2] = 0;
- }
- VECTOR::VECTOR(int a, int b, int c) {
- v[0] = a;
- v[1] = b;
- v[2] = c;
- }
- void VECTOR::read() {
- std::cin >> v[0] >> v[1] >> v[2];
- }
- void VECTOR::print() {
- std::cout << "("
- << v[0] << ", "
- << v[1] << ", "
- << v[2] << ")" << std::endl;
- }
- VECTOR VECTOR::operator+(const VECTOR& other) {
- return VECTOR(v[0] + other.v[0], v[1] + other.v[1], v[2] + other.v[2]);
- }
- VECTOR VECTOR::operator-(const VECTOR& other) {
- return *this + other.mult(-1);
- }
- VECTOR& VECTOR::operator--() {
- v[0]--;
- v[1]--;
- v[2]--;
- return *this;
- }
- VECTOR VECTOR::mult(int s) const {
- return VECTOR(v[0] * s, v[1] * s, v[2] * s);
- }
- int main()
- {
- VECTOR vec;
- vec.read();
- std::cout << "vec = ";
- vec.print();
- std::cout << "vec2 = vec * 2 = ";
- VECTOR vec2 = vec.mult(2);
- vec2.print();
- std::cout << "vec + vec2 = : ";
- (vec + vec2).print();
- std::cout << "vec + vec2 = : ";
- (vec - vec2).print();
- std::cout << "--vec = ";
- (--vec).print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement