From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp | 344 +++++++++++++++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp (limited to 'Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp') diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp new file mode 100644 index 0000000..16e3f67 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp @@ -0,0 +1,344 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3 +// Author: Sven Eisenhauer +// Date: 17.01.2005 +// File: int40.cpp +// Description: Implementation of class Integer40 + +#include "int40.h" +#include +#include +#include +#include + +using std::cout; +using std::endl; +using std::cin; +using std::ostream; +using std::istream; + + + +ostream& operator<<(ostream &out, Integer40 &right) +{ + right.write(); + + return out; +} + +istream& operator>> (istream &in, Integer40 &right) +{ + right.read(); + + return in; +} + +Integer40& operator+ (const Integer40& left, const Integer40& right) +{ + static Integer40 temp; + + int sum=0; + int carry=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + sum=(left.int40[i]+right.int40[i]+carry); + if (sum >= 10) + { + temp.int40[i]=sum%10; + carry=1; + } + else + { + temp.int40[i]=sum; + carry=0; + } + } + + return temp; + +} +Integer40& operator- (const Integer40& left, const Integer40& right) +{ + static Integer40 temp; + + int diff=0; + int carry=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + if (right.int40[i] > left.int40[i]) + { + temp.int40[i]=(left.int40[i]+10)-right.int40[i]-carry; + carry=1; + } + else + { + temp.int40[i]=left.int40[i]-right.int40[i]-carry; + carry=0; + } + + } + + return temp; +} + +Integer40::Integer40() +{ + int40=new int[ARRAYSIZE]; + for (int n=0;n=0;n--) + { + temp[n]=0; + } + i=strlen(input)-1; + for (n=ARRAYSIZE-1;n>=ARRAYSIZE-strlen(input);n--) + { + int40[n]=input[i]-48; + i--; + } + return *this; +} + +const Integer40& Integer40::write() +{ + cout << endl; + for (int n=0;n=0;i--) + { + sum=(int40[i]+toAdd.int40[i]+carry); + int40[i]=sum%10; + if (sum >= 10) + carry=1; + else + carry=0; + } + return *this; +} + +/*const Integer40& Integer40::operator+(const Integer40 &toAdd) +{ + add(toAdd); + + return *this; +} +*/ +const Integer40& Integer40::operator+=(const Integer40 &toAdd) +{ + add(toAdd); + + return *this; +} + +const Integer40& Integer40::substract(const Integer40 &toSub) +{ + int temp=0; + + for (int i=ARRAYSIZE-1;i>=0;i--) + { + if (toSub.int40[i] > int40[i]) + { + int40[i]=((int40[i])+10)-toSub.int40[i]; + (int40[i-1])--; + } + else + int40[i]=((int40[i]))-toSub.int40[i]; + + } + return *this; +} + +/*const Integer40& Integer40::operator-(const Integer40 &toSub) +{ + substract(toSub); + + return *this; +}*/ + +const Integer40& Integer40::operator-=(const Integer40 &toSub) +{ + substract(toSub); + + return *this; +} + +const Integer40& Integer40::operator =(const Integer40 &right) +{ + if(&right!=this) + { + for (int n=0;n=(const Integer40 &toCompare) const +{ + return isGreaterOrEqual(toCompare); +} + +bool Integer40::isSmallerOrEqual(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i toCompare.int40[i]) + { + retval=false; + } + return retval; +} + +bool Integer40::operator<=(const Integer40 &toCompare) const +{ + return isSmallerOrEqual(toCompare); +} + + +bool Integer40::isGreaterThan(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i(const Integer40 &toCompare) const +{ + return isGreaterThan(toCompare); +} + +bool Integer40::isSmallerThan(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((i= toCompare.int40[i]) + { + retval=false; + } + return retval; +} + +bool Integer40::operator<(const Integer40 &toCompare) const +{ + return isSmallerThan(toCompare);; +} + +bool Integer40::isEqual(const Integer40 &toCompare) const +{ + int i=0; + bool retval=true; + + while ((iint40[i]!=0) + { + retval=false; + break; + } + i++; + } + + return retval; +} \ No newline at end of file -- cgit v1.2.3