Getting fatal error C1190 pt2

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
pragma endregion
	private: System::Void lblseatNumber_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: System::Void lblflightClass_Click(System::Object^  sender, System::EventArgs^  e)
			 {
			 }
		 
	private: System::Void lblEntPassName_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: System::Void txtPassengerName_TextChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
		     }
	private: System::Void btnAddPassenger_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 String^ errMess;
				 String^ passName = txtPassengerName->Text;
				 String^ flightClass = cboFlightClass->Text;
				 String^ seatNum = cboSeatNumber->Text;

				 if (passName == "")
				 {
					 errMess = "Must enter passenger name";
					 MessageBox::Show(errMess, "E R R O R");
					 txtPassengerName->Focus();
					 return;
				 }

				 int i = 0;
				 int seatIdx = 0;

				 for (i = 0; i < SIZE; i++)
					 if (seatNum == seatAr[i])
					 {
						 seatIdx = i;
						 break;
					 }

					 AssignSeat (passName, flightClass, seatIdx);
					 DisplayManifest();
					 PopulateSeatCombo();

			 }
    private: System::Void btnCloseFlight_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				 if (activeFlight)
				 {
					 DisplayManifest();
					 DisplayPassengerList();
					 btnCloseFlight->Text = "Start a New Flight";
					 activeFlight = false;
					 btnCloseFlight->Focus();
					 btnAddPassenger->Enabled = false;
				 }
				 else
				 {
					 btnCloseFlight->Text = "Close Flight";
					 btnAddPassenger->Enabled = true;

					 for (int i = 0; i < SIZE; i++)
						 passNameAr[i] = "";

					 Array::Sort(seatAr);
					 cboSeatNumber->Items->Clear();

					 for (int i = 0; i < 4; i++)
						 cboSeatNumber->Items->Add(seatAr[i]);

					 cboSeatNumber->SelectedIndex = 0;
					 numFirstClass = 0;
					 numBusinessClass = 0;
					 DisplayManifest();
					 activeFlight = true;
					 txtPassengerName->Focus();
				 }
			 }

    private: System::Void cboFlightClass_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
				 int i;
				 cboSeatNumber->Items->Clear();
				 if (cboFlightClass->Text == "First")
				 {
					 for (i = 0; i < 4; i++)
						 if (passNameAr[i] == "")
							 cboSeatNumber->Items->Add(seatAr[i]);
				 }
				 else
				 {
					 for (i = 4; i < SIZE; i++)
						 if (passNameAr[i] == "")
							 cboSeatNumber->Items->Add(seatAr[i]);
				 }
				 if (cboSeatNumber->Items->Count > 0)
					 cboSeatNumber->SelectedIndex = 0;

			 }

    private: System::Void lbPlaneManifest_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
			 }
	private: void DisplayPassengerList()
			 {
				 std::ofstream outFile;

				 outFile.open("PlaneManifest.txt");
				 outFile << "    P L A N E    M A N I F E S T\n";
				 outFile << " Seat           Passenger Name\n";

				 for (int i = 0; i < SIZE; i++)
				 {
					 String ^passS = passNameAr[i]; // convert passNameAr to char*
					 pin_ptr<const wchar_t> wchP = PtrToStringChars(passS); // Pin memory so GC can't move it 
																			// while native function is called
					 size_t convertedCharsP = 0; // convert to char*
					 size_t sizeInBytesP = ((passS->Length + 1) * 2);
					 errno_t errP = 0;
					 char    *pass = (char *)malloc(sizeInBytesP);
					 errP = wcstombs_s(&convertedCharsP, pass, sizeInBytesP, wchP, sizeInBytesP);


					 String ^seatS = seatAr[i]; // convert passNameAr to char*
					 pin_ptr<const wchar_t> wchS = PtrToStringChars(seatS); // Pin memory so GC can't move it 
																			// while native function is called
					 size_t convertedCharsS = 0; // convert to char*
					 size_t sizeInBytesS = ((seatS->Length + 1) * 2);
					 errno_t errS = 0;
					 char    *seat = (char *)malloc(sizeInBytesS);
					 errS = wcstombs_s(&convertedCharsS, seat, sizeInBytesS, wchS, sizeInBytesS);
					 outFile << "  " << seat << "\t\t" << pass << "\n";
					 //outFile << "  " << seatAr[i]->ToCharArray() << "\t\t" << passNameAr[i]->ToCharArray() << "\n";
				 }


				 Array::Sort(passNameAr, seatAr);
				 String^ str = String::Format("     First Class; (0)    Business Class: (1)", numFirstClass, numBusinessClass);
								              //"     First Class: " + numFirstClass + "   Business Class: " + numBusinessClass + "\n";

				 lbPlaneManifest->Items->Add(" N U M B E R   O F   P A S S E N G E R S");
				 lbPlaneManifest->Items->Add(str);
				 lbPlaneManifest->Items->Add("");

				 outFile << "\n\n  N U M B E R   O F   P A S S E N G E R S\n";
					 pin_ptr<const wchar_t> wch = PtrToStringChars(str);   // Pin memory so GC can't move it while native function is called
					 size_t convertedChars = 0;                            // Convert to Char
					 size_t sizeInBytes = ((str->Length + 1) * 2);
					 errno_t err = 0;
					 char    *ch = (char *)malloc(sizeInBytes);

				 err = wcstombs_s(&convertedChars, ch, sizeInBytes, wch, sizeInBytes);
				 outFile << ch << "\n" << "\n" << "\n";  // outFile << str->ToCharArray() << "\n" << "\n" << "\n";


				 lbPlaneManifest->Items->Add("         P A S S E N G E R   L I S T");
				 lbPlaneManifest->Items->Add("   Passenger Name                     seat");
				 outFile << "         P A S S E N G E R   L I S T\n";
				 outFile << "   Passenger Name                     seat\n";
				 
				 for (int i = 0; i < SIZE; i++)
				 {
				 if (passNameAr[i]->Length > 0)
				 {
					 str = String::Format("(0, -30)         (1)", passNameAr[i], seatAr[i]);
					 lbPlaneManifest->Items->Add(str);

					 pin_ptr<const wchar_t> wch = PtrToStringChars(str);   // Pin memory so GC can't move it while native function is called
					 size_t convertedChars = 0;                            // Convert to Char
					 size_t sizeInBytes = ((str->Length + 1) * 2);
					 errno_t err = 0;
					 char    *ch = (char *)malloc(sizeInBytes);

					 err = wcstombs_s(&convertedChars, ch, sizeInBytes, wch, sizeInBytes);
					 outFile << ch << "\n";  // outFile << str->ToCharArray() << "\n";

				 }
			 }
			 outFile.close();

		} 
	private: void DisplayManifest()
	    {
		    String^ str;
		    lbPlaneManifest->Items->Clear();
		    lbPlaneManifest->Items->Add("    P L A N E   M A N I F E S T");
		    lbPlaneManifest->Items->Add(" Seat          Passenger Name");
		    for (int i = 0; i < SIZE; i++)
		    {
			    str = "  " + seatAr[i] + "\t\t" + passNameAr[i];
			    lbPlaneManifest->Items->Add(str);
		    }
	    }
	private: void AssignSeat(String^ passName, String^ flightClass, int seatIdx)
		{
			passNameAr[seatIdx] = passName;

			if (flightClass == "First")
				numFirstClass++;
			else
				numBusinessClass++;

		}
	private: void PopulateSeatCombo()
		{
			int i;
			txtPassengerName->Text = "";
			flightClassAr = gcnew array<String^>(2);
			flightClassAr[0] = "First";
			flightClassAr[1] = "Business";
			cboFlightClass->DataSource = flightClassAr;
			cboFlightClass->SelectedIndex = 0;
			cboSeatNumber->Items->Clear();

			if (numFirstClass + numBusinessClass == 20)
			{
				btnCloseFlight->Focus();
				btnAddPassenger->Enabled = false;
				return;
			}

			txtPassengerName->Focus();

			if (numFirstClass < 4)
			{
				for (i = 0; i < 4; i++)
					if (passNameAr[i] == "")
						cboSeatNumber->Items->Add(seatAr[i]);
				
				if (numBusinessClass == 16)
				{
					flightClassAr = gcnew array<String^>(1);
					flightClassAr[0] = "First";
					cboFlightClass->DataSource = flightClassAr;
				}
			}
			else
			{
				flightClassAr = gcnew array<String^>(1);
				flightClassAr[0] = "Business";
				cboFlightClass->DataSource = flightClassAr;

				for (i = 4; i < SIZE; i++)
					if (passNameAr[i] == "")
						cboSeatNumber->Items->Add(seatAr[i]);
			}

			if (cboSeatNumber->Items->Count > 0)
				cboSeatNumber->SelectedIndex = 0;
		}
									  
    };
}
Last edited on
Topic archived. No new replies allowed.