Postanowiłem wstawić cały kod by było bardziej przejrzyście. Z niewiadomych mi powodów wszystko nagle zaczęło działać. No i utknąłem nad kolejnym problemem. Jakim jest wypisanie grupy, żeby sprawdzić, czy dobrze wpisałem do tablicy elementy.
Co do wektorów to mniej je znam, dlatego wzbraniam się od ich użycia, ale oczywiście nie mówię, że nie poznam, ale obecnie zależy mi przybliżeniu rozwiązania: napisania
funkcji zamien ktora jako argumenty uzyskuje trzy wektory v1, v2, v3 liczb
całkowitych oraz trzy nieujemne liczby całkowite l1, l2, l3 i zamienia ze soba wartosociami
elementy v1[l1], v2[l2] oraz v3[l3] w taki sposób, ze stara wartoosci v1[l1] ma byc zapisana
w v2[l2], stara wartosc v2[l2] w v3[l3], zas stara wartosc v3[l3] w v1[l1]. W przypadku
gdy którys z indeksów l1, l2, l3 lezy poza zakresem indeksów wektora, do którego sie odnosi,
funkcja powinna rzucic standardowy wyjatek outofrang. Przed rzuceniem wyjatku
funkcja nie powinna zmieniac wartosci zadnego z elementów wektorów v1, v2, v3.
#pragma once
#include <vector>
namespace lista7zad3 {
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 std;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
void ReadLiczby()
{
// int liczby[3];
// Wczytaj liczby l1,l2,l3
/*
liczby[0]=System::Convert::ToInt32( this->textBox4->Text);
liczby[1]=System::Convert::ToInt32( this->textBox5->Text);
liczby[2]=System::Convert::ToInt32( this->textBox6->Text);
//??UWAGI?? Problem z brakiem znaków!!!!
*/
}
void ReadPrzecinek()
{
if((this->textBox1->Text[0]<=48 == this->textBox1->Text[0]>=58 )&& (this->textBox2->Text[0]<=48 == this->textBox2->Text[0]>=58)&& (this->textBox3->Text[0]<=48 == this->textBox3->Text[0]>=58))
{
ReadVector();
}
else
{
MessageBox::Show("Źle wpisany wektor!!!", "Error", MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
Close();
}
}
void ReadVector()
{
int length[3];
int licznik[3];
licznik[0]=1; // liczba grup =(przecinki+1)
int n=0;
int z=0;
bool drugiprzecinek=false;
// Wczytaj wektory v1,v2,v3
//// dlugosc wektorów, aby wiedzieć ile wczytać znaków
length[0] = System::Convert::ToInt32( this->textBox1->Text->Length);
length[1] = System::Convert::ToInt32( this->textBox2->Text->Length);
length[2] = System::Convert::ToInt32( this->textBox3->Text->Length);
for(int j=1; j<length[0];j++)
{
if(this->textBox1->Text[j]==',')
{
if(drugiprzecinek==false)
{
drugiprzecinek=true; // pierwszy przecinek
licznik[0]+=1;
}
else
{
//drugi przecinek
MessageBox::Show("Dwa Przecinki", "Error", MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
Close();
}
}
else
{
drugiprzecinek=false; // warunek przecinków
}
}
int **tablica = new int *[licznik[0]]; // ilośc wskazników przypisane elementy
int *grupa = new int [licznik[0]]; // grupa n ma ile elementów? Odp grupa[0] ma .. wartosc
for(int i=0; i < length[0];i++)
{
if(this->textBox1->Text[i]==',')
{
//this->textBox6->Text+=System::Convert::ToString(z);
tablica[z] =new int [n]; // tablica grupy z zawiera n elementów(alokacja pamięci)
grupa[z]=n; // grupa z ma n elementów( ilosc elementow w grupie z)
if(z==licznik[0])
{
// Brak więcej grup
break;
}
else
{ // Kolejna grupa przygotowanie
z+=1; // licznik grup
n=0; // wyzerowuje, aby uzyskac od początku liczbe elementów w grupie
MessageBox::Show("Nowa Grupa", "Error", MessageBoxButtons::OK, MessageBoxIcon::Asterisk);
}
}
else
{
n++; // licznik elementów
}
}
//Wpisanie elementów
// wpisywanie do grupy elementów
for(int z=0; z<licznik[0]; z++)
{
for(int i=0; i < grupa[licznik[0]]; i++)
{
tablica[z][i]=System::Convert::ToInt32(this->textBox1->Text[i]);
this->textBox4->Text+=System::Convert::ToString(tablica[0][i]-48);
}
}
}
#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->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(84, 48);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(139, 20);
this->textBox1->TabIndex = 0;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(84, 83);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(139, 20);
this->textBox2->TabIndex = 1;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(84, 121);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(139, 20);
this->textBox3->TabIndex = 2;
//
// button1
//
this->button1->Location = System::Drawing::Point(172, 179);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(166, 30);
this->button1->TabIndex = 3;
this->button1->Text = L"Oblicz wektory";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(44, 48);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(19, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"v1";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(44, 83);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(19, 13);
this->label2->TabIndex = 5;
this->label2->Text = L"v2";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(44, 121);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(19, 13);
this->label3->TabIndex = 6;
this->label3->Text = L"v3";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(288, 121);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(15, 13);
this->label4->TabIndex = 12;
this->label4->Text = L"l3";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(288, 83);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(15, 13);
this->label5->TabIndex = 11;
this->label5->Text = L"l2";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(288, 48);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(15, 13);
this->label6->TabIndex = 10;
this->label6->Text = L"l1";
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(328, 48);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(139, 20);
this->textBox4->TabIndex = 9;
//
// textBox5
//
this->textBox5->Location = System::Drawing::Point(328, 83);
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System::Drawing::Size(139, 20);
this->textBox5->TabIndex = 8;
//
// textBox6
//
this->textBox6->Location = System::Drawing::Point(328, 118);
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System::Drawing::Size(139, 20);
this->textBox6->TabIndex = 7;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(560, 262);
this->Controls->Add(this->label4);
this->Controls->Add(this->label5);
this->Controls->Add(this->label6);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->textBox5);
this->Controls->Add(this->textBox6);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//Deklaracje
//int length[3];
// ReadLiczby();
ReadPrzecinek();
}
};
}