Hej,
Na tym etapie mam problem z programem.
Poniżej kod z błędami. Napiszcie co robię źle.
// main.cpp
#include <cstdlib>
#include <iostream>
#include "statystyka.h"
using namespace std;
int main()
{
STATYSTYKA sysy();
float * tab = new float[ liczbaEl ];
if( tab == 0 )
{
cout << "Brak pamięci\n";
}
system( "PAUSE" );
return EXIT_SUCCESS;
}
// statystyka.h
#ifndef STATYSTYKA_H_
#define STATYSTYKA_H_
class STATYSTYKA
{
public:
STATYSTYKA();
float liczbaEl;
float tab[ liczbaEl ];
int ile;
float min;
private:
void nowawartosc();
int ilef();
void utworz();
void wypisz();
float srednia();
float maxf();
float minf();
void wartosc();
};
#endif
C/C++
// statystyka.cpp
#include <cstdlib>
#include <iostream>
#include "statystyka.h"
using namespace std;
STATYSTYKA::STATYSTYKA()
{
}
void STATYSTYKA::wartosc()
{
cout << "Która wartość chcesz wyświetlić? ";
cin >> liczbaEl;
if( !liczbaEl )
{
cout << "Brak takiego elementu!\n";
}
else
{
cout << "\nTa liczba to: " << tab[ liczbaEl ];
}
}
void STATYSTYKA::nowawartosc()
{
cout << "Którą element chcesz zaminić? ";
cin >> liczbaEl;
if( !liczbaEl )
{
cout << "Brak takiego elementu!\n";
}
else
{
cout << "\nWprowadź nowy element: ";
cin >> tab[ liczbaEl ];
}
}
int STATYSTYKA::ilef()
{
int ile = 0;
for( int i = 0; i < liczbaEl; i++ )
{
ile += tab[ liczbaEl ];
cout << ile;
}
return ile;
}
void STATYSTYKA::utworz()
{
if( liczbaEl <> NULL )
delete[] tab;
STATYSTYKA::STATYSTYKA() //
{
cout << "\nPodaj wielkość tablicy: ":
cin >> liczbaEl;
}
}
void STATYSTYKA::wypisz()
{
for( i = 0; i < liczbaEl; i++ )
{
cout << "\nW elemencie tablicy pod numerem: " << liczbaEl;
cout << " - znajduje sie liczba: " << tab[ liczbaEl ];
}
}
float STATYSTYKA::srednia()
{
float sred = 0;
for( int i = 0; i < liczbaEl; i++ )
{
suma += tab[ liczbaEl ];
sred = suma / ile;
}
return sred;
}
float STATYSTYKA::maxf()
{
float max = tab[ 0 ];
if( int i = 1; i < liczbaEl; i++ )
{
if( tab[ liczbaEl ] > max )
max = tab[ liczbaEl ];
}
return max;
}
float STATYSTYKA::minf()
{
float min = tab[ 0 ];
if( int i = 1; i < liczbaEl; i++ )
{
if( tab[ liczbaEl ] < min )
min = tab[ liczbaEl ];
}
return min;
}
In file included from main.cpp:4:
statystyka.h:9: error: invalid use of non-static data member `STATYSTYKA::liczbaEl'
statystyka.h:10: error: from this location
main.cpp: In function `int main()':
main.cpp:11: error: `liczbaEl' undeclared (first use this function)
main.cpp:11: error: (Each undeclared identifier is reported only once for each function it appears in.)
make.exe: *** [main.o] Error 1