summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Prakt5/Aufg1/main.cpp
blob: 07e2b939973244f7e70d047c766d6d80fed62db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
}