Problem z biblioteka.

marc_90

Użytkownik
Dołączył
Październik 30, 2010
Posty
5
Witam wszystkich

Nie dawno zacząłem programować w visual c++ i mam problem z dobraniem odpowiedniej biblioteki. Więc mam napisać program który w tablicy wylosuje losowe liczby i posortuje je. Do tego celu mam użyć dwóch przycisków i dwóch tablic. Nie wiem niestety jakiej biblioteki użyć. Możecie pomóc?
 

discovery44

Były Moderator
Dołączył
Sierpień 14, 2007
Posty
763
Po co Ci biblioteki do prostego liczenia?
Kod:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <iostream> // g++ wymaga do sleep()
typedef int TYP;
 
void bubblesort( TYP a[], int n ) 
{
  int i,j;
  TYP tmp;
  int change;
 
  for (i=0; i<n-1; ++i) 
  {
       change=0;
       for (j=0; j<n-1-i; j++)
       { 
          if (a[j+1] < a[j])   //porównanie sąsiądów
          {  
              tmp = a[j];      
              a[j] = a[j+1];
              a[j+1] = tmp;    //wypchanie bąbelka     
              change=1;
          }
       }
       if(!change) break;      // nie dokonano zmian - koniec!
  }
}

void losuj(int arr[], int zakres, int max = 10)
{
    for(int i = 0 ; i < max ; i++)
    {
        srand((unsigned)time(NULL) );
        arr[i] = rand() % zakres;
        sleep(1);
    }
}

int main()
{
    int arr[10];
    losuj(arr, 20, sizeof(arr) / 4);
    for(int i = 0 ; i < sizeof(arr) / 4 ; i++) printf("%d ", arr[i]);
    printf("\n");
    bubblesort(arr, sizeof(arr) / 4);
    for(int i = 0 ; i < sizeof(arr) / 4 ; i++) printf("%d ", arr[i]);
    printf("\n");
}
http://pl.wikisource.org/wiki/Sortowanie_bąbelkowe/kod#C, dodałem Ci kod do losowania.
 
Ostatnia edycja:

marc_90

Użytkownik
Dołączył
Październik 30, 2010
Posty
5
Kod:
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				tab->RowCount=5;
				tab->ColumnCount=5;

				 for (int j=0;j<5;j++)
					 for (int i=0;i<5;i++)
						 tab->Rows[j]->Cells[i]->Value= (unsigned char)rand();
			 }
	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
			{
  int i,j,a;
	for (i=0;i<5;i++)
  for (j=0;j<5;j++)
	  if (tab[j+1,0]<tab[j,0])
	  {
		tab[j,i]=a;
		tab[j,i]=tab[j+1,i];
		tab[j+1,i]=a;
	  }
};

Możesz przeanalizować co robię źle? Wyskakują mi takie błędy:

Kod:
1>.\losowanie i sortowanie.cpp(6) : error C2143: syntax error : missing ';' before 'using'
1>c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(127) : error C2676: binary '<' : 'System::Windows::Forms::DataGridViewCell ^' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(129) : error C2664: 'void System::Windows::Forms::DataGridView::default::set(int,int,System::Windows::Forms::DataGridViewCell ^)' : cannot convert parameter 3 from 'int' to 'System::Windows::Forms::DataGridViewCell ^'
1>        No user-defined-conversion operator available, or
1>        No standard conversion exists from the boxed form of the arithmetic type to the target type
1>c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(129) : error C2661: 'System::Windows::Forms::DataGridView::default::get' : no overloaded function takes 0 arguments
1>c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(131) : error C2664: 'void System::Windows::Forms::DataGridView::default::set(int,int,System::Windows::Forms::DataGridViewCell ^)' : cannot convert parameter 3 from 'int' to 'System::Windows::Forms::DataGridViewCell ^'
1>        No user-defined-conversion operator available, or
1>        No standard conversion exists from the boxed form of the arithmetic type to the target type
1>c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(131) : error C2661: 'System::Windows::Forms::DataGridView::default::get' : no overloaded function takes 0 arguments
1>.\losowanie i sortowanie.cpp(19) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\marcin\documents\visual studio 2008\projects\losowanie i sortowanie\losowanie i sortowanie\Form1.h(4)' was matched
1>Generating Code...
 
Do góry Bottom