diff options
Diffstat (limited to 'Bachelor/Prog2/person-tree/Prs_test.cpp')
| -rw-r--r-- | Bachelor/Prog2/person-tree/Prs_test.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Bachelor/Prog2/person-tree/Prs_test.cpp b/Bachelor/Prog2/person-tree/Prs_test.cpp new file mode 100644 index 0000000..91e6b70 --- /dev/null +++ b/Bachelor/Prog2/person-tree/Prs_test.cpp @@ -0,0 +1,68 @@ +// Tree with Person objects
+// Author: Hans-Peter Weber
+// Date: 08.05.04
+
+#include <iostream>
+using std::cout;
+using std::cerr;
+using std::cin;
+using std::endl;
+
+#include <fstream>
+using std::ofstream;
+using std::ifstream;
+using std::ios;
+
+#include <string>
+using std::string;
+
+#include <cstdlib>
+
+#include "tree.h"
+#include "person.h"
+
+int main()
+{
+ Tree< Person > personTree;
+ int fileOrConsole;
+ string lastName, firstName;
+
+ cout << "Neue Namen eingeben(1) oder vorhandene Datei nutzen(2): ";
+ cin >> fileOrConsole;;
+
+ if( fileOrConsole == 1 ) {
+ cout << "Name, Vorname eingeben" << endl
+ << "(Beenden mit 'Strg z'): ";
+
+ ofstream out( "Daten.txt", ios::app );
+
+ if( !out ) {
+ cerr << "Datei konnte nicht geoeffnet werden." << endl;
+ exit( 1 );
+ }
+
+ while( cin >> lastName >> firstName ) {
+ out << lastName << " " << firstName << endl;
+ personTree.insertNode( *( new Person( lastName, firstName ) ) );
+ cout << "Eingeben: ";
+ }
+ }
+ else {
+ ifstream in( "Daten.txt", ios::in );
+
+ if( !in ) {
+ cerr << "Datei konnte nicht geoeffnet werden." << endl;
+ exit( 1 );
+ }
+
+ while( in >> lastName >> firstName ) {
+ personTree.insertNode( *( new Person( lastName, firstName ) ) );
+ }
+ }
+
+ cout << "\nInorder traversal\n\n";
+ personTree.inOrderTraversal();
+ cout << endl << endl;
+
+ return 0;
+}
\ No newline at end of file |
