Нужно, чтобы было 6 файлов. Причем, когда я все классы объединяю в один файл, все реализации - в другой файл, весь код работает
При делении на 6 файлов вылетают такие ошибки. В чем проблема?
jk.jpg
main.cpp
Код:
#include <iostream>
#include "Fraction.h"
#include "FazzyNumber.h"
int main() {
Fraction R1(8, 3);
Fraction R2(5, 4);
Fraction Answer;
R1.Addition(R2, Answer);
std::cout << "R1 + R2 = " << Answer << std::endl;
R1.Subtraction(R2, Answer);
std::cout << "R1 - R2 = " << Answer << std::endl;
R1.Multiplication(R2, Answer);
std::cout << "R1 * R2 = " << Answer << std::endl;
R1.Division(R2, Answer);
std::cout << "R1 / R2 = " << Answer << std::endl;
std::cout << "Equel:" << R1.Equel(R2) << std::endl;
std::cout << "Greate:" << R1.Greate(R2) << std::endl;
std::cout << "Less:" << R1.Less(R2) << std::endl;
std::cout << "__________________________________________________________\n" << std::endl;
FazzyNumber FN1(2, 10, 2);
FazzyNumber FN2(1, 5, 1);
FazzyNumber ANSWER;
FN1.Addition(FN2, ANSWER);
std::cout << "FN1 + FN2 = " << ANSWER << std::endl;
FN1.Subtraction(FN2, ANSWER);
std::cout << "FN1 - FN2 = " << ANSWER << std::endl;
FN1.Multiplication(FN2, ANSWER);
std::cout << "FN1 * FN2 = " << ANSWER << std::endl;
FN1.Division(FN2, ANSWER);
std::cout << "FN1 / FN2 = " << ANSWER << std::endl;
FN1.ReverseNumber(FN2, ANSWER);
std::cout << "Reverse number = " << ANSWER << std::endl;
}
Pair.h
Код:
#include <memory>
#include <iostream>
#include <functional>
class Pair {
public:
double X;
double Y;
void SetX(double);
void SetY(double);
double GetX() const;
double GetY() const;
Pair();
Pair(double, double);
Pair(const Pair& other);
virtual void Addition(const Pair&, Pair&) = 0;
virtual void Subtraction(const Pair&, Pair&) = 0;
virtual void Multiplication(const Pair&, Pair&) = 0;
virtual void Division(const Pair&, Pair&) = 0;
virtual bool Equel(Pair&);
virtual bool Greate(Pair&);
virtual bool Less(Pair&);
friend std::ostream& operator<<(std::ostream&, Pair&);
friend std::istream& operator>>(std::istream&, Pair&);
};
Pair.cpp
Код:
#include "Pair.h"
#include <iostream>
#include <cmath>
Pair::Pair() : X{ 0 }, Y{ 0 }{};
Pair::Pair(double X, double Y) : X{ X }, Y{ Y } {};
Pair::Pair(const Pair& other) : X{ other.X }, Y{ other.Y } {};
void Pair::SetX(double X) { X = X; }
void Pair::SetY(double Y) { Y = Y; }
double Pair::GetX() const { return X; }
double Pair::GetY() const { return Y; }
bool Pair::Equel(Pair&) { return X == Y; }
bool Pair::Greate(Pair&) { return (X > Y); }
bool Pair::Less(Pair&) { return (X < Y); }
std::ostream& operator<<(std::ostream& out, Pair& P) {
out << P.X << P.Y;
return out;
}
std::istream& operator>>(std::istream& in, Pair& P) {
in >> P.X >> P.Y;
return in;
}
Fractio.h
Код:
#include "Pair.h"
class Fraction : public Pair {
public:
Fraction();
Fraction(double X, double Y);
Fraction(const Fraction& other);
void Addition(const Pair&, Pair&) override;
void Subtraction(const Pair&, Pair&) override;
void Multiplication(const Pair&, Pair&) override;
void Division(const Pair&, Pair&) override;
bool Equel(Pair&) override;
bool Greate(Pair&) override;
bool Less(Pair&) override;
friend std::ostream& operator << (std::ostream& out, const Fraction& F);
};
Fractio.cpp
Код:
#include "Fraction.h"
Fraction::Fraction() : Pair() {};
Fraction::Fraction(double X, double Y) : Pair(X, Y) {};
Fraction::Fraction(const Fraction& other) : Pair(other) {};
void Fraction::Addition(const Pair& other, Pair& answer) {
answer.X = (X * other.Y) + (other.X * Y);
answer.Y = Y * other.Y;
}
void Fraction::Subtraction(const Pair& other, Pair& answer) {
answer.X = (X * other.Y) - (other.X * Y);
answer.Y = Y * other.Y;
}
void Fraction::Multiplication(const Pair& other, Pair& answer) {
answer.X = X * other.X;
answer.Y = Y * other.Y;
}
void Fraction::Division(const Pair& other, Pair& answer) {
answer.X = X * other.Y;
answer.Y = Y * other.X;
}
bool Fraction::Equel(Pair& other) { return X == other.X && Y == other.Y; }
bool Fraction::Greate(Pair& other) { return (X * other.Y > Y * other.X); }
bool Fraction::Less(Pair& other) { return (X * other.Y < Y* other.X); }
std::ostream& operator<<(std::ostream& out, const Fraction& F) {
out << F.X / F.Y;
return out;
}
FazzyNumber.h
Код:
#include "Pair.h"
class FazzyNumber : public Pair {
double A;
public:
FazzyNumber();
FazzyNumber(double e1, double A, double e2);
FazzyNumber(const FazzyNumber& other);
void Addition(const Pair&, Pair&) override;
void Subtraction(const Pair&, Pair&) override;
void Multiplication(const Pair&, Pair&) override;
void Division(const Pair&, Pair&) override;
void ReverseNumber(const Pair&, Pair&);
friend std::ostream& operator << (std::ostream& out, const FazzyNumber& FN);
friend std::istream& operator>>(std::istream& in, FazzyNumber& FN);
};
FazzyNumber.cpp
Код:
#include "FazzyNumber.h"
FazzyNumber::FazzyNumber() : Pair() {};
FazzyNumber::FazzyNumber(double e1, double A, double e2) : Pair(e1, e2), A(A) {}
FazzyNumber::FazzyNumber(const FazzyNumber& other) : Pair(other) {};
void FazzyNumber::Addition(const Pair& other, Pair& answer) {
const FazzyNumber& other2 = dynamic_cast<const FazzyNumber&>(other);
FazzyNumber& answer2 = dynamic_cast<FazzyNumber&>(answer);
answer2.A = A + other2.A;
answer.X = A + other2.A - X - other.X;
answer.Y = A + other2.A + Y + other.Y;
}
void FazzyNumber::Subtraction(const Pair& other, Pair& answer) {
const FazzyNumber& other2 = dynamic_cast<const FazzyNumber&>(other);
FazzyNumber& answer2 = dynamic_cast<FazzyNumber&>(answer);
answer2.A = A - other2.A;
answer.X = A - other2.A - X - other.X;
answer.Y = A - other2.A + Y + other.Y;
}
void FazzyNumber::Multiplication(const Pair& other, Pair& answer) {
const FazzyNumber& other2 = dynamic_cast<const FazzyNumber&>(other);
FazzyNumber& answer2 = dynamic_cast<FazzyNumber&>(answer);
answer2.A = A * other2.A;
answer.X = A * other2.A - other2.A * X - A * other2.X + X * other.X;
answer.Y = A * other2.A + other2.A * X + A * other2.X + X * other.X;
}
void FazzyNumber::Division(const Pair& other, Pair& answer) {
const FazzyNumber& other2 = dynamic_cast<const FazzyNumber&>(other);
FazzyNumber& answer2 = dynamic_cast<FazzyNumber&>(answer);
answer2.A = A / other2.A;
answer.X = (A - X) / (other2.A + other.Y);
answer.Y = (A + other.X) / (other2.A - X);
}
void FazzyNumber::ReverseNumber(const Pair& other, Pair& answer) {
const FazzyNumber& other2 = dynamic_cast<const FazzyNumber&>(other);
FazzyNumber& answer2 = dynamic_cast<FazzyNumber&>(answer);
answer2.A = 1 / A;
answer.X = 1 / (A + other.Y);
answer.Y = (A - X);
}
std::ostream& operator<<(std::ostream& out, const FazzyNumber& FN) {
out << FN.X << ", " << FN.A << ", " << FN.Y;
return out;
}
std::istream& operator>>(std::istream& in, FazzyNumber& FN) {
int TMP;
in >> TMP >> FN.A;
FN.X = FN.A - TMP;
in >> TMP;
FN.Y = FN.A - TMP;
return in;
}