C++ List orientation

Hi, my name is Karl and working on a sort of "translater program". I am using a swedish word input from the user and a english word input and there after will the program test the user. In windows form.

I'm stuck at the list orientation.
I'm only using one list "glosa" as the input for the swedish and the english words.

I want to send only the swedish words to a textbox and there after let the user to answer the correct putin english word.

The words need to be randomized and there is the problem. How do I randomize the string list without losing the following correct english word which is i+1.

My code:
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#pragma once
#include <list>
#include <ctime>
#include <algorithm>


namespace Glossi {
    using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Collections::Generic;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	private: List<String^>^ glosa;
	private: List<bool>^ flag;
	private: bool inmatningKlar;
	private: bool tbxSvInmatad;
	private: System::Windows::Forms::RichTextBox^  txtResultat;
	private: bool tbxEngInmatad;
	private: System::Windows::Forms::Button^  btn_Next;
	private: int i;
	private: int i1;



	public:
		Form1(void)
		{
			InitializeComponent();
			i = 1;
			i1= 0;
			glosa = gcnew List<String^>();
			flag = gcnew List<bool>();

		}

	protected:
		int counter;
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
		
				delete components;

			}
		}
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::GroupBox^  gtbtest;

	private: System::Windows::Forms::GroupBox^  gtbResultat;
	private: System::Windows::Forms::Button^  btn_add;

	private: System::Windows::Forms::TextBox^  tbx_addEng;




	private: System::Windows::Forms::TextBox^  tbx_addSv;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  btn_Svara;
	private: System::Windows::Forms::TextBox^  tbx_SvarEng;
	private: System::Windows::Forms::TextBox^  tbx_SvarSv;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Button^  btn_Start;
	private: System::Windows::Forms::Button^  btn_New;
	private: System::Windows::Forms::Label^  label5;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::EventHandler(this, &Form1::txtResultat_TextChanged);

		}
#pragma endregion
	private: System::Void btn_add_Click(System::Object^  sender, System::EventArgs^  e) {
			if (tbx_addSv->Text == "" || tbx_addEng->Text == ""){
			btn_add->Enabled=false;
			}
			else{
			String^ Svensktord = tbx_addSv->Text;
			glosa->Add(Svensktord);
			tbx_addSv->Text = "";
			String^ Engelsktord = tbx_addEng->Text;
			glosa->Add(Engelsktord);
			tbx_addEng->Text = "";
			if (txtResultat->Text==""){
				txtResultat->Text="Tillagda glosor: " + "\n" + Svensktord;
			}
			 else{
				txtResultat->Text=txtResultat->Text + "\n" + Svensktord;
			 }
			
			}

			 }

private: System::Void tbx_addSv_TextChanged(System::Object^  sender, System::EventArgs^  e) {
if (tbx_addSv->Text->Length != 0)
{
	tbxSvInmatad = true; 
	 if(tbxEngInmatad == true && tbxSvInmatad == true)
			{
				btn_add->Enabled=true;
			}
}	
		 }
private: System::Void tbx_addEng_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 if (tbx_addEng->Text->Length != 0)
{
	tbxEngInmatad = true; 

}	 if(tbxEngInmatad == true && tbxSvInmatad == true)
			{
				btn_add->Enabled=true;
			}
		 }	
		
private: System::Void txtResultat_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 
		 }

		 // Svara Glossi
private: System::Void btn_Svara_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (tbx_SvarEng->Text == glosa[i+1]) {
				 txtResultat->Text ="Rätt svar!" + "\n" + glosa[i] + " = " + glosa[i+1] ;
			 //glosa->RemoveAt(i);
			 
			 }
			 else{
				 MessageBox::Show("Fel svar försök igen!");
				 
			 }
		 }

		 // Starta Glossi minst 20 glosor
private: System::Void btn_Start_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(glosa->Count >= 4 ){
			 txtResultat->Text = "";
			 gtbtest->Enabled=true;
			 btn_New->Enabled=true;
			 i1 = glosa->Count; 
			 srand (time(NULL));
			 if(i1%2 != 0)
				 i1 += 1;
			 if( i1 = 0)
			 i1= rand()% glosa->Count;
				 i = i1;
			 tbx_SvarSv->AppendText(glosa[i]);
			 }
			 else{
		 MessageBox::Show("Mata in minst 20 glosor!");
		 }
		 }

		 // Nya Glosor
private: System::Void btn_New_Click(System::Object^  sender, System::EventArgs^  e) {
if (glosa->Count >= 2 ){
	txtResultat->Text = "";
	glosa->Clear();
	gtbtest->Enabled=false;
	tbx_SvarSv->Text = "";
	tbx_SvarEng->Text = "";
}
		 }

		 // Nästa ord
private: System::Void btn_Next_Click(System::Object^  sender, System::EventArgs^  e) {
			 tbx_SvarSv->Text = "";
			 tbx_SvarEng->Text = "";
			 tbx_SvarSv->AppendText(glosa[i]);
		 }

		 // Ifall tbx_SvarEng är tom är "Nästa" inaktiverad 
private: System::Void tbx_SvarEng_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 if (tbx_SvarEng->Text == ""){
			 btn_Next->Enabled=false;
			 }
			 else
				 btn_Next->Enabled=true;

		 }
};
}

Last edited on
I would suggest to use a struct for the word combination. Then you may randomize the list without the loss of relation.

Or you randomize the indexes instead of the list. This would require a parallel array for the indexes.
How would you go and write that code. It would be better for me to use the randomize of the indexes. How would you use that method?

BIG thanks!
1
2
3
4
5
6
7
struct Word
{
  String^ English;
  String^ Swedish;
}
typedef List<Word> WordList;
WordList^ glosa;


Now you can easily shuffle the list and get random words.
Topic archived. No new replies allowed.