summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/person-tree/Prs_test.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/person-tree/Prs_test.cpp
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog2/person-tree/Prs_test.cpp')
-rw-r--r--Bachelor/Prog2/person-tree/Prs_test.cpp68
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