diff options
Diffstat (limited to 'Bachelor/Prog1/Prakt6/prg1p6_3')
| -rw-r--r-- | Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h | 55 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt6/prg1p6_3/int40.cpp | 344 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp | 74 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp | 108 | ||||
| -rw-r--r-- | Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw | 29 |
5 files changed, 610 insertions, 0 deletions
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h b/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h new file mode 100644 index 0000000..c4949f3 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/Int40.h @@ -0,0 +1,55 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3
+// Author: Sven Eisenhauer
+// Date: 17.01.2005
+// File: Int40.h
+// Description: class Integer40
+
+#ifndef INT40_1
+#define INT40_1
+
+#include<iostream>
+using std::ostream;
+using std::istream;
+
+
+const static int ARRAYSIZE=40;
+
+class Integer40
+{
+public:
+ Integer40();
+ Integer40(const Integer40&);
+ ~Integer40();
+ const Integer40& read();
+ friend istream& operator>> (istream&, Integer40 &);
+ const Integer40& write();
+ friend ostream& operator<< (ostream&, const Integer40&);
+ friend Integer40& operator+ (const Integer40&, const Integer40&);
+ friend Integer40& operator- (const Integer40&, const Integer40&);
+ const Integer40& add(const Integer40&);
+ const Integer40& operator+=(const Integer40&);
+ const Integer40& substract(const Integer40&);
+ const Integer40& operator-=(const Integer40&);
+ const Integer40& operator=(const Integer40&);
+ bool isEqual(const Integer40&) const;
+ bool operator==(const Integer40&) const;
+ bool isNotEqual(const Integer40&) const;
+ bool operator!=(const Integer40&) const;
+ bool isGreaterThan(const Integer40&) const;
+ bool operator>(const Integer40&) const;
+ bool isSmallerThan(const Integer40&) const;
+ bool operator<(const Integer40&) const;
+ bool isGreaterOrEqual(const Integer40&) const;
+ bool operator>=(const Integer40&) const;
+ bool isSmallerOrEqual(const Integer40&) const;
+ bool operator<=(const Integer40&) const;
+ bool isZero();
+ //const Integer40& operator-(const Integer40&);
+ //const Integer40& operator+(const Integer40&);
+
+private:
+ int *int40;
+ //static int nrInt40;
+};
+
+#endif
\ No newline at end of file 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 <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <new>
+
+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<ARRAYSIZE;n++)
+ int40[n]=0;
+// ++nrInt40;
+}
+
+Integer40::Integer40(const Integer40 &toCopy)
+{
+ int40=new int[ARRAYSIZE];
+ for (int n=0;n<ARRAYSIZE;n++)
+ int40[n]=toCopy.int40[n];
+}
+
+Integer40::~Integer40()
+{
+ delete[] int40;
+ //--nrInt40;
+}
+
+const Integer40& Integer40::read()
+{
+ char input[ARRAYSIZE];
+ int i=0;
+ int n=0;
+ int temp[ARRAYSIZE];
+ cout << endl << "Please enter Integer40: ";
+ cin.get(input,ARRAYSIZE);
+ cin.sync();
+ for (n=ARRAYSIZE-strlen(input);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<ARRAYSIZE;n++)
+ cout << int40[n];
+ cout << endl;
+
+ return *this;
+}
+
+const Integer40& Integer40::add(const Integer40 &toAdd)
+{
+ int sum=0;
+ int carry=0;
+
+ for (int i=ARRAYSIZE-1;i>=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<ARRAYSIZE;n++)
+ int40[n]=right.int40[n];
+ }
+
+ return *this;
+}
+
+
+bool Integer40::isGreaterOrEqual(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] < toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator>=(const Integer40 &toCompare) const
+{
+ return isGreaterOrEqual(toCompare);
+}
+
+bool Integer40::isSmallerOrEqual(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[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<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] <= toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+bool Integer40::operator>(const Integer40 &toCompare) const
+{
+ return isGreaterThan(toCompare);
+}
+
+bool Integer40::isSmallerThan(const Integer40 &toCompare) const
+{
+ int i=0;
+ bool retval=true;
+
+ while ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[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 ((i<ARRAYSIZE)&&(int40[i]==toCompare.int40[i]))
+ {
+ i++;
+ }
+ if (int40[i] != toCompare.int40[i])
+ {
+ retval=false;
+ }
+ return retval;
+}
+
+bool Integer40::operator ==(const Integer40 &toCompare) const
+{
+ return isEqual(toCompare);
+}
+
+bool Integer40::isNotEqual(const Integer40 &toCompare) const
+{
+ return !(*this==toCompare);
+}
+
+bool Integer40::operator !=(const Integer40 &toCompare) const
+{
+ return !(*this==toCompare);
+}
+
+bool Integer40::isZero()
+{
+ int i=0;
+ bool retval=true;
+
+ while (i<ARRAYSIZE)
+ {
+ if(this->int40[i]!=0)
+ {
+ retval=false;
+ break;
+ }
+ i++;
+ }
+
+ return retval;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp new file mode 100644 index 0000000..60b73dc --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/main.cpp @@ -0,0 +1,74 @@ +// Programmieren 1, Praktikum 6, Aufgabe 3
+// Author: Sven Eisenhauer
+// Date: 17.01.2005
+// File: main.cpp
+// Description: Application to test class Integer40
+
+#include "Int40.h"
+#include <new>
+#include <iostream>
+using std::cin;
+using std::cout;
+using std::endl;
+
+
+
+ostream& operator<<(ostream &out, Integer40 &right);
+istream& operator>> (istream &in, Integer40 &right);
+Integer40& operator+ (const Integer40&, const Integer40&);
+Integer40& operator- (const Integer40&, const Integer40&);
+
+int main()
+{
+ Integer40 bigint1;
+ Integer40 bigint2;
+
+ //bigint1.read();
+ cin >> bigint1 >> bigint2;
+ //bigint1.write();
+ //cout << bigint1 ;
+
+ //bigint2.read();
+ //cin >> bigint2;
+ //bigint2.write();
+ cout << bigint1 <<bigint2;
+
+ //bigint1->add(bigint2);
+
+ /*bigint1+=bigint2;
+ cout << bigint1;
+ bigint1-=bigint2;
+ cout << bigint1;
+ */
+
+ cout << bigint1 - bigint2;
+ cout << bigint1 + bigint2;
+
+ if(bigint1 >= bigint2)
+ cout << endl << "BigInt1 is greater or equal BigInt2" << endl;
+ if(bigint1 <= bigint2)
+ cout << endl << "BigInt1 is smaller or equal BigInt2" << endl;
+ if(bigint1 > bigint2)
+ cout << endl << "BigInt1 is greater than BigInt2" << endl;
+ if(bigint1 < bigint2)
+ cout << endl << "BigInt1 is smaller than BigInt2" << endl;
+ if(bigint1 == bigint2)
+ cout << endl << "BigInt1 is equal BigInt2" << endl;
+ if(bigint1.isZero())
+ cout << endl << "BigInt1 is zero" << endl;
+
+ if(bigint2 >= bigint1)
+ cout << endl << "BigInt2 is greater or equal BigInt1" << endl;
+ if(bigint2 <= bigint1)
+ cout << endl << "BigInt2 is smaller or equal BigInt1" << endl;
+ if(bigint2 > bigint1)
+ cout << endl << "BigInt2 is greater than BigInt1" << endl;
+ if(bigint2 < bigint1)
+ cout << endl << "BigInt2 is smaller than BigInt1" << endl;
+ if(bigint2 == bigint1)
+ cout << endl << "BigInt2 is equal BigInt1" << endl;
+ if(bigint2.isZero())
+ cout << endl << "BigInt2 is zero" << endl;
+
+ return 0;
+}
\ No newline at end of file diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp new file mode 100644 index 0000000..aec95a9 --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsp @@ -0,0 +1,108 @@ +# Microsoft Developer Studio Project File - Name="prg1p6_3" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=prg1p6_3 - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_3.mak".
+!MESSAGE
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE
+!MESSAGE NMAKE /f "prg1p6_3.mak" CFG="prg1p6_3 - Win32 Debug"
+!MESSAGE
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE
+!MESSAGE "prg1p6_3 - Win32 Release" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE "prg1p6_3 - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "prg1p6_3 - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "prg1p6_3 - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "prg1p6_3 - Win32 Release"
+# Name "prg1p6_3 - Win32 Debug"
+# Begin Group "Quellcodedateien"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\int40.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\main.cpp
+# End Source File
+# End Group
+# Begin Group "Header-Dateien"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\Int40.h
+# End Source File
+# End Group
+# Begin Group "Ressourcendateien"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw new file mode 100644 index 0000000..0f372ae --- /dev/null +++ b/Bachelor/Prog1/Prakt6/prg1p6_3/prg1p6_3.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
+
+###############################################################################
+
+Project: "prg1p6_3"=.\prg1p6_3.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
|
