summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Prakt5/Aufg1/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Prog2/Prakt5/Aufg1/main.cpp')
-rw-r--r--Bachelor/Prog2/Prakt5/Aufg1/main.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Prakt5/Aufg1/main.cpp b/Bachelor/Prog2/Prakt5/Aufg1/main.cpp
new file mode 100644
index 0000000..07e2b93
--- /dev/null
+++ b/Bachelor/Prog2/Prakt5/Aufg1/main.cpp
@@ -0,0 +1,101 @@
+// Tree with string objects
+// Author: Sven Eisenhauer
+// Date: 20.06.05
+
+#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;
+using std::getline;
+
+#include <string>
+using std::string;
+
+#include <iomanip>
+using std::setw;
+#include <map>
+#include <ctime>
+
+#include <cstdlib>
+#include <new>
+
+typedef std::map< string,string,std::less< string > > wordpairs;
+
+int main()
+{
+ wordpairs en_de,de_en;
+ wordpairs *pairPtr;
+
+ string word;
+ string en;
+ string de;
+ int pos;
+ int end;
+
+ ifstream inFile( "Words.txt", ios::in );
+
+ if( !inFile ) {
+ cerr << "Input-Datei konnte nicht geoeffnet werden." << endl;
+ exit( 1 );
+ }
+
+ while( getline(inFile,word)) {
+ //cout << word << endl;
+ pos=word.find_first_of(',');
+ end=word.size();
+ en.assign(word,0,pos);
+ de.assign(word,pos+1,end);
+
+// cout << de << "\t " << en << endl;
+ en_de.insert(wordpairs::value_type(en,de));
+ de_en.insert(wordpairs::value_type(de,en));
+ }
+ inFile.close();
+ cout << "Englisch - Deutsch" << endl << endl;
+ for (wordpairs::const_iterator it=en_de.begin(); it!=en_de.end();
+ it++)
+ {
+ cout<< setw(30) << it->first << "\t "<<it->second<< endl;
+ }
+ cout << endl << endl<< "Deutsch - Englisch"<<endl << endl;
+ for (wordpairs::const_iterator it2=de_en.begin(); it2!=de_en.end();
+ it2++)
+ {
+ cout<< setw(30) << it2->first << "\t "<<it2->second<< endl;
+ }
+
+ srand(time(0));
+ int lang=(rand()%2);
+ if (lang==0)
+ pairPtr=(&en_de);
+ else
+ pairPtr=(&de_en);
+ int posi=(rand()%(pairPtr->size()));
+ wordpairs::const_iterator it3=(pairPtr->begin());
+ int counter=0;
+ int stop=0;
+ cout << endl << endl;
+ string eingabe;
+ while ( it3!=(pairPtr->end()) && stop==0)
+ {
+ it3++;
+ counter++;
+ if(posi==counter)
+ {
+ cout << it3->first << endl;
+ cout <<"Ihre Uebersetzung: ";
+ cin>>eingabe;
+ cout << "Ihre Eingabe: " << eingabe << endl;
+ cout << "Richtig ist:" << it3->second << endl;
+ stop=1;
+ }
+ }
+
+ return 0;
+}