diff --git a/OOP/OOP/.vs/OOP/FileContentIndex/3ccdad26-1564-46e6-ac3a-a48108d69299.vsidx b/OOP/OOP/.vs/OOP/FileContentIndex/3ccdad26-1564-46e6-ac3a-a48108d69299.vsidx deleted file mode 100644 index c9f9e6e..0000000 Binary files a/OOP/OOP/.vs/OOP/FileContentIndex/3ccdad26-1564-46e6-ac3a-a48108d69299.vsidx and /dev/null differ diff --git a/OOP/OOP/.vs/OOP/FileContentIndex/a774fd2e-b19f-4404-b569-d71d6dfe4a83.vsidx b/OOP/OOP/.vs/OOP/FileContentIndex/a774fd2e-b19f-4404-b569-d71d6dfe4a83.vsidx deleted file mode 100644 index da150ee..0000000 Binary files a/OOP/OOP/.vs/OOP/FileContentIndex/a774fd2e-b19f-4404-b569-d71d6dfe4a83.vsidx and /dev/null differ diff --git a/OOP/OOP/.vs/OOP/FileContentIndex/c21e94e9-0151-4b0c-bd5f-387aed2464b8.vsidx b/OOP/OOP/.vs/OOP/FileContentIndex/c21e94e9-0151-4b0c-bd5f-387aed2464b8.vsidx deleted file mode 100644 index 4618696..0000000 Binary files a/OOP/OOP/.vs/OOP/FileContentIndex/c21e94e9-0151-4b0c-bd5f-387aed2464b8.vsidx and /dev/null differ diff --git a/OOP/OOP/.vs/OOP/FileContentIndex/d92e3f5c-08f8-41c5-ac4b-95a57b1c025e.vsidx b/OOP/OOP/.vs/OOP/FileContentIndex/d92e3f5c-08f8-41c5-ac4b-95a57b1c025e.vsidx deleted file mode 100644 index b272e91..0000000 Binary files a/OOP/OOP/.vs/OOP/FileContentIndex/d92e3f5c-08f8-41c5-ac4b-95a57b1c025e.vsidx and /dev/null differ diff --git a/OOP/OOP/.vs/OOP/v17/.suo b/OOP/OOP/.vs/OOP/v17/.suo index 5ef1f4a..0eb3e3e 100644 Binary files a/OOP/OOP/.vs/OOP/v17/.suo and b/OOP/OOP/.vs/OOP/v17/.suo differ diff --git a/OOP/OOP/.vs/OOP/v17/Browse.VC.db b/OOP/OOP/.vs/OOP/v17/Browse.VC.db index d29796f..f37d9ee 100644 Binary files a/OOP/OOP/.vs/OOP/v17/Browse.VC.db and b/OOP/OOP/.vs/OOP/v17/Browse.VC.db differ diff --git a/OOP/OOP/.vs/OOP/v17/ipch/AutoPCH/1d6575618227d69e/MAIN.ipch b/OOP/OOP/.vs/OOP/v17/ipch/AutoPCH/1d6575618227d69e/MAIN.ipch index 9992138..2c7306a 100644 Binary files a/OOP/OOP/.vs/OOP/v17/ipch/AutoPCH/1d6575618227d69e/MAIN.ipch and b/OOP/OOP/.vs/OOP/v17/ipch/AutoPCH/1d6575618227d69e/MAIN.ipch differ diff --git a/OOP/OOP/OOP.sln b/OOP/OOP/OOP.sln index 19e33cf..da2de01 100644 --- a/OOP/OOP/OOP.sln +++ b/OOP/OOP/OOP.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ctime", "ctime\ctime.vcxproj", "{0B3A8A1D-38BF-4358-9381-D772FEA522DB}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cfraction", "cfraction\cfraction.vcxproj", "{1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {0B3A8A1D-38BF-4358-9381-D772FEA522DB}.Release|x64.Build.0 = Release|x64 {0B3A8A1D-38BF-4358-9381-D772FEA522DB}.Release|x86.ActiveCfg = Release|Win32 {0B3A8A1D-38BF-4358-9381-D772FEA522DB}.Release|x86.Build.0 = Release|Win32 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Debug|x64.ActiveCfg = Debug|x64 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Debug|x64.Build.0 = Debug|x64 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Debug|x86.ActiveCfg = Debug|Win32 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Debug|x86.Build.0 = Debug|Win32 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Release|x64.ActiveCfg = Release|x64 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Release|x64.Build.0 = Release|x64 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Release|x86.ActiveCfg = Release|Win32 + {1421E9DC-0E7E-4B05-A71B-7E7E0262B4C0}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OOP/OOP/cfraction/cfraction.vcxproj b/OOP/OOP/cfraction/cfraction.vcxproj new file mode 100644 index 0000000..a5514b3 --- /dev/null +++ b/OOP/OOP/cfraction/cfraction.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {1421e9dc-0e7e-4b05-a71b-7e7e0262b4c0} + cfraction + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/OOP/OOP/cfraction/cfraction.vcxproj.filters b/OOP/OOP/cfraction/cfraction.vcxproj.filters new file mode 100644 index 0000000..e8deb3d --- /dev/null +++ b/OOP/OOP/cfraction/cfraction.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/OOP/OOP/cfraction/cfraction.vcxproj.user b/OOP/OOP/cfraction/cfraction.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/OOP/OOP/cfraction/cfraction.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/OOP/OOP/cfraction/main.cpp b/OOP/OOP/cfraction/main.cpp new file mode 100644 index 0000000..8fa77ec --- /dev/null +++ b/OOP/OOP/cfraction/main.cpp @@ -0,0 +1,251 @@ +#include +#include + +class Fraction { +private: + int numerator; // + int denominator; // + +public: + // + Fraction() : numerator(0), denominator(1) {} + Fraction(int num, int denom) : numerator(num), denominator(denom) {} + Fraction(const Fraction& other) : numerator(other.numerator), denominator(other.denominator) {} + Fraction(const std::string& fractionStr); + + + ~Fraction() {} + + + Fraction& operator=(const Fraction& other); + + + bool operator==(int value) const; + bool operator!=(int value) const; + bool operator>(int value) const; + bool operator<(int value) const; + bool operator>=(int value) const; + bool operator<=(int value) const; + + bool operator==(const Fraction& other) const; + bool operator!=(const Fraction& other) const; + bool operator>(const Fraction& other) const; + bool operator<(const Fraction& other) const; + bool operator>=(const Fraction& other) const; + bool operator<=(const Fraction& other) const; + + + Fraction operator+(int value) const; + Fraction operator-(int value) const; + Fraction operator*(int value) const; + Fraction operator/(int value) const; + + Fraction operator+(const Fraction& other) const; + Fraction operator-(const Fraction& other) const; + Fraction operator*(const Fraction& other) const; + Fraction operator/(const Fraction& other) const; + + Fraction& operator+=(int value); + Fraction& operator-=(int value); + Fraction& operator*=(int value); + Fraction& operator/=(int value); + + Fraction& operator+=(const Fraction& other); + Fraction& operator-=(const Fraction& other); + Fraction& operator*=(const Fraction& other); + Fraction& operator/=(const Fraction& other); + + friend std::ostream& operator<<(std::ostream& os, const Fraction& fraction); + friend std::istream& operator>>(std::istream& is, Fraction& fraction); + + + void simplify(); + +private: + + int gcd(int a, int b) const; +}; + +Fraction::Fraction(const std::string& fractionStr) { + // +} + +Fraction& Fraction::operator=(const Fraction& other) { + if (this != &other) { + numerator = other.numerator; + denominator = other.denominator; + } + return *this; +} + +bool Fraction::operator==(int value) const { + return numerator == value * denominator; +} + +bool Fraction::operator!=(int value) const { + return !(*this == value); +} + +bool Fraction::operator>(int value) const { + return numerator > value * denominator; +} + +bool Fraction::operator<(int value) const { + return numerator < value * denominator; +} + +bool Fraction::operator>=(int value) const { + return numerator >= value * denominator; +} + +bool Fraction::operator<=(int value) const { + return numerator <= value * denominator; +} + +bool Fraction::operator==(const Fraction& other) const { + return numerator * other.denominator == other.numerator * denominator; +} + +bool Fraction::operator!=(const Fraction& other) const { + return !(*this == other); +} + +bool Fraction::operator>(const Fraction& other) const { + return numerator * other.denominator > other.numerator * denominator; +} + +bool Fraction::operator<(const Fraction& other) const { + return numerator * other.denominator < other.numerator * denominator; +} + +bool Fraction::operator>=(const Fraction& other) const { + return numerator * other.denominator >= other.numerator * denominator; +} + +bool Fraction::operator<=(const Fraction& other) const { + return numerator * other.denominator <= other.numerator * denominator; +} + +Fraction Fraction::operator+(int value) const { + return Fraction(numerator + value * denominator, denominator); +} + +Fraction Fraction::operator-(int value) const { + return Fraction(numerator - value * denominator, denominator); +} + +Fraction Fraction::operator*(int value) const { + return Fraction(numerator * value, denominator); +} + +Fraction Fraction::operator/(int value) const { + if (value == 0) { + throw std::invalid_argument("Division by zero"); + } + return Fraction(numerator, denominator * value); +} + +Fraction Fraction::operator+(const Fraction& other) const { + return Fraction(numerator * other.denominator + other.numerator * denominator, denominator * other.denominator); +} + +Fraction Fraction::operator-(const Fraction& other) const { + return Fraction(numerator * other.denominator - other.numerator * denominator, denominator * other.denominator); +} + +Fraction Fraction::operator*(const Fraction& other) const { + return Fraction(numerator * other.numerator, denominator * other.denominator); +} + +Fraction Fraction::operator/(const Fraction& other) const { + if (other.numerator == 0) { + throw std::invalid_argument("Division by zero"); + } + return Fraction(numerator * other.denominator, denominator * other.numerator); +} + +Fraction& Fraction::operator+=(int value) { + *this = *this + value; + return *this; +} + +Fraction& Fraction::operator-=(int value) { + *this = *this - value; + return *this; +} + +Fraction& Fraction::operator*=(int value) { + *this = *this * value; + return *this; +} + +Fraction& Fraction::operator/=(int value) { + *this = *this / value; + return *this; +} + +Fraction& Fraction::operator+=(const Fraction& other) { + *this = *this + other; + return *this; +} + +Fraction& Fraction::operator-=(const Fraction& other) { + *this = *this - other; + return *this; +} + +Fraction& Fraction::operator*=(const Fraction& other) { + *this = *this * other; + return *this; +} + +Fraction& Fraction::operator/=(const Fraction& other) { + *this = *this / other; + return *this; +} + +std::ostream& operator<<(std::ostream& os, const Fraction& fraction) { + os << fraction.numerator << "/" << fraction.denominator; + return os; +} + +std::istream& operator>>(std::istream& is, Fraction& fraction) { + is >> fraction.numerator; + is.ignore(1); // "/" + is >> fraction.denominator; + return is; +} + +void Fraction::simplify() { + int divisor = gcd(abs(numerator), abs(denominator)); + numerator /= divisor; + denominator /= divisor; +} + +int Fraction::gcd(int a, int b) const { + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; +} + +int main() { + + Fraction fraction1(3, 4); + Fraction fraction2(1, 2); + Fraction fraction3 = fraction1 + fraction2; + Fraction fraction4 = fraction1 - fraction2; + Fraction fraction5 = fraction1 * fraction2; + Fraction fraction6 = fraction1 / fraction2; + + std::cout << "Fraction 1: " << fraction1 << std::endl; + std::cout << "Fraction 2: " << fraction2 << std::endl; + std::cout << "Fraction 1 + Fraction 2: " << fraction3 << std::endl; + std::cout << "Fraction 1 - Fraction 2: " << fraction4 << std::endl; + std::cout << "Fraction 1 * Fraction 2: " << fraction5 << std::endl; + std::cout << "Fraction 1 / Fraction 2: " << fraction6 << std::endl; + + return 0; +} \ No newline at end of file