Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <tuple>
- #include <set>
- #include <unordered_map>
- #include <vector>
- #include <string>
- class Complex {
- private:
- double re;
- double im;
- public:
- explicit Complex(double re_ = 0., double im_ = 0.) : re(re_), im(im_) {
- std::cout << re<<".....";
- std::cout << im;
- }
- double get_re() const {
- return re;
- }
- double get_im() const {
- return im;
- }
- double &Re() {
- return re;
- }
- double &Im() {
- return im;
- }
- Complex operator-() const;
- Complex operator+() const;
- };
- Complex operator+(const Complex &first, const Complex &second) {
- return Complex(first.get_re() + second.get_re(), first.get_im() + second.get_im());
- }
- Complex operator-(const Complex &first, const Complex &second) {
- return Complex(first.get_re() - second.get_re(), first.get_im() - second.get_im());
- }
- Complex operator*(const Complex &first, const Complex &second) {
- auto a1 = first.get_re();
- auto a2 = second.get_re();
- auto b1 = first.get_im();
- auto b2 = second.get_im();
- return Complex(a1 * a2 - b1 * b2, a1 * b2 + b1 * a2);
- }
- Complex operator/(const Complex &first, const Complex &second) {
- auto a1 = first.get_re();
- auto a2 = second.get_re();
- auto b1 = first.get_im();
- auto b2 = second.get_im();
- auto _ = (a2 * b1 - a1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2));
- (void) _;
- return Complex((a1 * a2 + b1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2)),
- (a2 * b1 - a1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2)));
- }
- Complex Complex::operator-() const {
- return Complex(-re, -im);
- }
- Complex Complex::operator+() const {
- return Complex(re, im);
- }
- double Abs(const Complex &curr) {
- return std::pow(curr.get_re(), 2) + std::pow(curr.get_im(), 2);
- }
- bool operator==(const Complex &first, const Complex &second) {
- return (first.get_re() == second.get_re() && first.get_im() == second.get_im());
- }
- bool operator!=(const Complex &first, const Complex &second) {
- return (first.get_re() != second.get_re() || first.get_im() != second.get_im());
- }
- int main() {
- std::fstream fout("output.txt");
- Complex first(10,0);
- Complex second(5,0);
- fout << (first / second).get_im() << "......" << (first/second).get_re();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement