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/Prog2/Prakt5/Aufg1/main.cpp | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Bachelor/Prog2/Prakt5/Aufg1/main.cpp (limited to 'Bachelor/Prog2/Prakt5/Aufg1/main.cpp') 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 +using std::cout; +using std::cerr; +using std::cin; +using std::endl; + +#include +using std::ofstream; +using std::ifstream; +using std::ios; +using std::getline; + +#include +using std::string; + +#include +using std::setw; +#include +#include + +#include +#include + +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 "<second<< endl; + } + cout << endl << endl<< "Deutsch - Englisch"<first << "\t "<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; +} -- cgit v1.2.3