Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int zakres(int x) {
- cin>>x;
- return x;
- }
- int iloscele() {
- int n;
- cout<<"Podaj ilosc elementow n: "<<endl;
- cin>>n;
- return n;
- }
- void gen(int tab[], int n, int a, int b) {
- for(int i=0;i<n;i++) {
- tab[i] = rand()%(b+1)+a;
- }
- cout<<endl<<"Liczby zostaly wygenerowane."<<endl;
- }
- int wyswietl(int tab[], int n) {
- cout<<"Wygenerowane liczby to: ";
- for(int i=0;i<n;i++) {
- cout<<tab[i]<<" ";
- }
- }
- void sortuj_wybor(int tab[], int n) {
- for(int j=0;j<n-1;j++) {
- int temp, pmin = j;
- for(int i=j+1;i<n;i++)
- if(tab[i]<tab[pmin]) pmin = i;
- temp = tab[pmin];
- tab[pmin] = tab[j];
- tab[j] = temp;
- }
- cout<<"Liczby zostaly posortowane.";
- }
- void sortuj_babel(int tab[], int n) {
- for (int i=0; i<9; i++)
- for (int j=0; j<9; j++)
- if (tab[j]>tab[j+1])
- swap(tab[j], tab[j+1]);
- cout<<"Liczby zostaly posortowane.";
- }
- void sortuj_wstawianie(int tab[], int n) {
- for(int j=n-2;j>=0;j--) {
- int x = tab[j];
- int i = j+1;
- while((i<n) && (x>tab[i])) {
- tab[i-1] = tab[i];
- i++;
- }
- tab[i-1] = x;
- }
- cout<<"Liczby zostaly posortowane.";
- }
- void maksymalna(int tab[], int n, int a) {
- int max=a;
- for(int i=0;i<n;i++) {
- if(tab[i]>max) {
- max = tab[i];
- }
- }
- cout<<"Liczba maksymalna to: "<<max<<endl;
- }
- void minimalna(int tab[], int n, int b) {
- int min=b;
- for(int i=0;i<n;i++) {
- if(tab[i]<min) {
- min = tab[i];
- }
- }
- cout<<"Liczba minimalna to: "<<min<<endl;
- }
- void srednia(int tab[], int n) {
- int suma=0, srednia=0;
- for(int i=0;i<n;i++) {
- suma = suma + tab[i];
- }
- srednia = suma / n;
- cout<<"Srednia liczb wynosi: "<<srednia<<endl;
- }
- /*
- void wystapienia() {
- }
- */
- int main() {
- srand(time(0));
- int tab[1000], n, a, b, wybor=12;
- while(wybor!=0) {
- cout<<endl<<"______________________________"<<endl;
- cout<<"|0. Wyjscie |" <<endl;
- cout<<"|1. Zakres liczb |" <<endl;
- cout<<"|2. Ilosc elementow n |" <<endl;
- cout<<"|3. Generowanie tablicy |" <<endl;
- cout<<"|4. Wyswietlanie |" <<endl;
- cout<<"|5. Sortowanie (wybor) |" <<endl;
- cout<<"|6. Sortowanie babelkowe |" <<endl;
- cout<<"|7. Sortowanie (wstawianie) |" <<endl;
- cout<<"|8. Liczba maksymalna |" <<endl;
- cout<<"|9. Liczba minimalna |" <<endl;
- cout<<"|10. Srednia liczb |" <<endl;
- cout<<"|11. Ilosc wystapien |" <<endl;
- cout<<"|_____________________________|" <<endl;
- cout<<endl<<"Wybierz dzialanie: ";
- cin>>wybor;
- switch(wybor) {
- case 0:
- cout<<endl<<"Wychodzenie z programu...";
- break;
- case 1:
- cout<<"Podaj zakres minimalny: ";
- a=zakres(a);
- cout<<"Podaj zakres maksymalny: ";
- b=zakres(b);
- break;
- case 2:
- n = iloscele();
- break;
- case 3:
- gen(tab, n, a, b);
- break;
- case 4:
- wyswietl(tab, n);
- break;
- case 5:
- sortuj_wybor(tab, n);
- break;
- case 6:
- sortuj_babel(tab, n);
- break;
- case 7:
- sortuj_wstawianie(tab, n);
- break;
- case 8:
- maksymalna(tab, n, a);
- break;
- case 9:
- minimalna(tab, n, b);
- break;
- case 10:
- srednia(tab, n);
- break;
- /*case 11:
- wystapienia();
- break;*/
- default:
- cout<<endl<<"Nieprawidlowe polecenie";
- break;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment