Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "header.h"
- using namespace std;
- Complex::~Complex() {
- delete x;
- delete y;
- x = 0;
- y = 0;
- }
- Complex::Complex() {
- x = new int;
- y = new int;
- this->x[0] = 0;
- this->y[0] = 0;
- }
- Complex::Complex(int real, const char* im) {
- x = new int;
- y = new int;
- this->x[0] = real;
- char imag[16];
- strcpy(imag, im);
- imag[strlen(imag) - 1] = '\0';
- this->y[0] = atoi(imag);
- }
- Complex::Complex(int real) {
- x = new int;
- y = new int;
- this->x[0] = real;
- this->y[0] = 0;
- }
- Complex::Complex(const char* im) {
- this->x = new int;
- this->y = new int;
- char imag[16];
- strcpy(imag, im);
- imag[strlen(imag) - 1] = '\0';
- this->x[0] = 0;
- this->y[0] = atoi(imag);
- }
- /** Constructor de copiere */
- Complex::Complex(const Complex &c) {
- x = new int;
- y = new int;
- this->x[0] = c.x[0];// getX();
- this->y[0] = c.y[0];// getY();
- }
- /** Adunarea a doua numere complexe */
- Complex Complex::add(Complex b) {
- Complex c;
- c.x[0] = this->x[0] + b.x[0];
- c.y[0] = this->y[0] + b.y[0];
- return c;
- }
- /** Aduna la partea reala */
- Complex Complex::add(int var) {
- Complex c;
- c.x[0] = this->x[0] + var;
- c.y[0] = this->y[0];
- return c;
- }
- /** Scaderea a doua numere complexe */
- Complex Complex::minus(Complex b) {
- Complex c;
- c.x[0] = this->x[0] - b.x[0];
- c.y[0] = this->y[0] - b.y[0];
- return c;
- }
- /** Inmultirea a doua numere complexe */
- Complex Complex::mul(Complex b) {
- Complex c;
- c.x[0] = (this->x[0] * b.x[0]) - (this->y[0] * b.y[0]); // x = x1 * y1 - x2 * y2
- c.y[0] = (this->x[0] * b.y[0]) + (b.x[0] * this->y[0]); // y = x1 * y2 + x2 * y1
- return c;
- }
- /** Impartirea a doua numere complexe */
- Complex Complex::div(Complex b) {
- Complex c;
- c.x[0] = (this->x[0] * b.x[0] + this->y[0] * b.y[0]) / (this->y[0] * this->y[0] + b.y[0] * b.y[0]); // (a1a2 + b1b2 ) / (a2a2 + b2b2)
- c.y[0] = (this->y[0] * b.x[0] - this->x[0] * b.y[0]) / (this->y[0] * this->y[0] + b.y[0] * b.y[0]); // (a2b1 - a1b2) / (a2a2 + b2b2)
- return c;
- }
- void Complex::print() {
- cout << this->x[0] << " + " << this->y[0] << "i\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement