|
Помогите найти ошибки
#38641106
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Надо создать Windows-приложение, которое предлагает пользователю за-дать размер линейного массива, заполняет автоматически этот массив слу-чайными целыми числами в диапазоне от –50 до 70, выводит элементы этого массива, затем по выбору пользователя определяет, соответственно, для каждого варианта задание а), б), в).
а)Найти сумму отрицательных элементов
б)Найти сумму второго и наибольшего положительного элемен-тов массива
в)Найти разность максимального и минимального элементов массива
Выдает ошибки:
error LNK2005: "int * A" (?A@@3PAHA) єцх юяЁхфхыхэ т MyForm.obj
error LNK2005: "int n" (?n@@3HA) єцх юяЁхфхыхэ т MyForm.obj
error LNK2005: "int i" (?i@@3HA) єцх юяЁхфхыхэ т MyForm.obj
error LNK1169: юсэрЁєцхэ ьэюуюъЁрЄэю юяЁхфхыхээ√щ ёшьтюы - юфшэ шыш сюыхх
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. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335.
#pragma once
#include <stdlib.h>
#include <cmath>
#define m 15
int i,n;
int A[m];
namespace Project1 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::GroupBox^ groupBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::CheckBox^ checkBox3;
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)
{
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->groupBox1->SuspendLayout();
this->groupBox2->SuspendLayout();
this->SuspendLayout();
//
// groupBox1
//
this->groupBox1->Controls->Add(this->button1);
this->groupBox1->Controls->Add(this->textBox2);
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Location = System::Drawing::Point(38, 22);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(446, 150);
this->groupBox1->TabIndex = 0;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Ввод элементов массива";
//
// button1
//
this->button1->Location = System::Drawing::Point(308, 42);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(110, 20);
this->button1->TabIndex = 4;
this->button1->Text = L"Создать массив";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(18, 110);
this->textBox2->Name = L"textBox2";
this->textBox2->ReadOnly = true;
this->textBox2->Size = System::Drawing::Size(380, 20);
this->textBox2->TabIndex = 3;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(198, 42);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 2;
this->textBox1->Text = L"33";
this->textBox1->Leave += gcnew System::EventHandler(this, &MyForm::textBox1_Leave);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(148, 94);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(99, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"Исходный массив";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(6, 42);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(186, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Введите число элементов массива";
//
// groupBox2
//
this->groupBox2->Controls->Add(this->textBox5);
this->groupBox2->Controls->Add(this->checkBox3);
this->groupBox2->Controls->Add(this->button3);
this->groupBox2->Controls->Add(this->button2);
this->groupBox2->Controls->Add(this->checkBox2);
this->groupBox2->Controls->Add(this->checkBox1);
this->groupBox2->Controls->Add(this->textBox4);
this->groupBox2->Controls->Add(this->textBox3);
this->groupBox2->Location = System::Drawing::Point(38, 188);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(446, 128);
this->groupBox2->TabIndex = 1;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Найти";
//
// button3
//
this->button3->Location = System::Drawing::Point(257, 99);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 23);
this->button3->TabIndex = 5;
this->button3->Text = L"Выход";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(69, 99);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 4;
this->button2->Text = L"Вычислить";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
//
// checkBox2
//
this->checkBox2->AutoSize = true;
this->checkBox2->Location = System::Drawing::Point(9, 38);
this->checkBox2->Name = L"checkBox2";
this->checkBox2->Size = System::Drawing::Size(326, 30);
this->checkBox2->TabIndex = 3;
this->checkBox2->Text = L"сумма второго и наибольшего положительного элементов\r\n\r\n";
this->checkBox2->UseVisualStyleBackColor = true;
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(9, 19);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(197, 17);
this->checkBox1->TabIndex = 2;
this->checkBox1->Text = L"сумма отрицательных элементов";
this->checkBox1->UseVisualStyleBackColor = true;
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(340, 43);
this->textBox4->Name = L"textBox4";
this->textBox4->ReadOnly = true;
this->textBox4->Size = System::Drawing::Size(100, 20);
this->textBox4->TabIndex = 1;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(340, 17);
this->textBox3->Name = L"textBox3";
this->textBox3->ReadOnly = true;
this->textBox3->Size = System::Drawing::Size(100, 20);
this->textBox3->TabIndex = 0;
//
// checkBox3
//
this->checkBox3->AutoSize = true;
this->checkBox3->Location = System::Drawing::Point(9, 65);
this->checkBox3->Name = L"checkBox3";
this->checkBox3->Size = System::Drawing::Size(302, 17);
this->checkBox3->TabIndex = 6;
this->checkBox3->Text = L"разность максимального и минимального элементов";
this->checkBox3->UseVisualStyleBackColor = true;
//
// textBox5
//
this->textBox5->Location = System::Drawing::Point(340, 69);
this->textBox5->Name = L"textBox5";
this->textBox5->ReadOnly = true;
this->textBox5->Size = System::Drawing::Size(100, 20);
this->textBox5->TabIndex = 7;
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(496, 335);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->groupBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
this->Name = L"MyForm";
this->Text = L"ЛБ 5. Выполнил: Логишков Е.В группа 6234";
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//Проверка, что не пустой компонент textBox1
if(textBox1->Text!="")
{n=Convert::ToInt32(textBox1->Text); }else
{MessageBox::Show( "Заполните, пожалуйста, данные", "Ошибка ввода данных", MessageBoxButtons::OK, MessageBoxIcon::Exclamation );}
//очистка компонента textBox2
{textBox2->Text = "";
//Процесс создания массива и заполнение компонента textBox2 случайными чис-лами из диапазона [-10;10]
for (i = 0; i < n; ++i)
{
A[i] = rand ( ) % 21-10;
this->textBox2->AppendText(A[i]+" ");
}
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
//Обнуляем переменные
int sumOtr=0; int sumNaib=0; int razn=0; int maxAiP=-11;int maxAi=-11; int minAi=11;
sumNaib=A[1];
for (i= 0; i<n; i++)
{
//Проверяем условие и находим сумму отриц. элементов
if (A[i]<0) {sumOtr=sumOtr+A[i];}
//Проверяем условие и находим сумму второго и наиб. положительного элементов
if ((A[i]>0)&(A[i]>maxAiP)) {maxAiP=A[i];}
//Проверяем условие и находим разность максимального и минимального элементов
if (A[i]>maxAi) {maxAi=A[i];}
if (A[i]>minAi) {minAi=A[i];}
razn=maxAi-minAi;
}
if(maxAiP==-11) {sumNaib=sumNaib;}
else {sumNaib=sumNaib+maxAiP;}
//Если компоненты checkBox включены, то выводим результаты заданий в компо-ненты textBox
if (checkBox1->Checked==true){this->textBox3->Text=Convert::ToString (sumOtr);}
if (checkBox2->Checked==true){this->textBox4->Text=Convert::ToString (sumNaib);}
if (checkBox3->Checked==true){this->textBox5->Text=Convert::ToString (razn);}
}
private: System::Void textBox1_Leave(System::Object^ sender, System::EventArgs^ e) {
int l, t, k; bool a=true; String ^str;
str=textBox1->Text;
l=str->Length;
//индекс символа, с которым работаем
t=0;
//колличество запятых в строке (дабы избежать варианта 0,2384,1254,1251 – это не число)
k=0;
//двигаем индексатор, если наше число отрицательное
if(str[t]=='-') t++;
//число не может начинаться с запятой
if(str[t]==',') a=false;
while(t<l)
{ if(str[t]==',')
//если запятая стоит последним символом или запятая уже была найдена
{ if(t==l-1 || k>0) a=false;
k++;
}
//если t-ый символ не лежит в диапазоне от '0' до '9'
else if(str[t]<'0' || str[t]>'9') a=false;
t++;
}
if (a==false)
{ MessageBox::Show("параметр XN не является числом","Ошибка ввода данных",MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
//возврат фокуса текстовому полю
this->textBox1->Focus();
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Application ::Exit();
}
};
}
|
|
|