To jest cały kod programu, dominanta nie jest zrobiona, vectora nie znam w sumie za bardzo, pisałem tak jak umiałem i kiedyś mi działały te tablice i tablicę muszę przekazywać między funkcjami, nie mogę zrobić globalnej, bo z globalną wszystko działa, ale takie zadanie mam.
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
void wypelnienie(int *tab, int &ile)
{
srand(time(NULL));
system("CLS");
cout<<"Iloma znakami chcesz wypełnić tablicę?"<<endl;
cout<<"Ile = ";
cin>>ile;
tab = new int[ile];
for (int i=0;i<ile;i++)
{
tab[i]=rand()%200-100;
}
cout<<tab[0];
system("pause");
}
void wypisanie(int *tab, int &ile)
{
system("CLS");
system("pause");
if (ile>0)
{
cout<<"Tablica z zakresu (-100;100):"<<endl;
for (int i=0;i<ile;i++)
cout<<tab[i]<<"\t";
cout<<endl<<endl;
system("pause");
}
}
void dominanta(int *tab, int &ile)
{
int dom, bufordom, iledom, buforiledom;
system("CLS");
}
void wybor(int x, int *tab, int &ile)
{
switch (x)
{
case 1:
{
wypelnienie(tab, ile);
break;
}
case 2:
{
wypisanie(tab, ile);
break;
}
case 3:
{
dominanta(tab, ile);
break;
}
case 0:
{
system("CLS");
cout<<"Wyjście z programu";
Sleep(1000);
break;
}
default:
{
system("CLS");
cout<<"Brak takiej opcji";
Sleep(1000);
system("CLS");
break;
}
}
}
void menu(int *tab, int &ile)
{
int x;
do
{
cout<<"Program do tworzenia tablicy"<<endl<<endl;
cout<<"1. Wypełnienie tablicy "<<endl;
cout<<"2. Wypisanie tablicy"<<endl;
cout<<"3. Znalezienie dominanty"<<endl;
cout<<"0. Wyjście"<<endl<<endl;
cout<<"Twój wybór = ";
cin>>x;
wybor(x, tab, ile);
system("CLS");
} while (x!=0);
}
int main()
{
int *tab, ile=0;
setlocale(LC_ALL,"Polish");
menu(tab, ile);
}