So here I am, having a difficult time figuring out what's the problem, first of here's the code:

Preke.H

#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

class Preke
{
private:
	string pav;			// prekės pavadinimas
	int atdata;			// atvežimo į parduotuvę data
	int pardata;		// pardavimo data
	int pkiek;			// prekių kiekis
	double kaina;		// prekės kaina
public:
	Preke(string p = "", int ad = 0, int pd = 0, int pk = 0, double k = 0.0):
	  pav(p), atdata(ad), pardata(pd), pkiek(pk), kaina(k) {}
	  ~Preke() {};
	  bool operator == (Preke & pr){
		  return (pr.kaina > kaina) || (pr.kaina == kaina && pr.pav < pav);
	  string Spausdinti()
	  {
		stringstream eil;
		eil.setf(ios::fixed);
		eil << left << setw(35) << pav
			<< right << setprecision(12) << setw(10) << atdata
			<< right << setprecision(12) << setw(10) << pardata
			<< right << setprecision(4) << setw(10) << pkiek
			<< right << setprecision(5) << setw(8) << kaina << endl;

		return eil.str();
	  }
};

Rinkinys.h

// Prekių rinkinio klasė
#include "Preke.h"

class Rinkinys
{
private:
	static const int CMax = 100;
	Preke R[CMax]; int n;		// konteineris - prekiu masyvas
public:
	Rinkinys(): n(0) {}
	~Rinkinys() {}
	int Kiek()  { return n; }
	int Talpa() { return CMax; }
	Preke Imti(int i)  { return R[i]; }
	void Deti(Preke p) { if (n < CMax) R[n++] = p; }
	void Rikiuoti();
};

Rinkinys.cpp

#include "Rinkinys.h"

void Rinkinys::Rikiuoti()
{
  Preke p;
  for(int i = 0; i < n; i++)
    for(int j = i+1; j < n; j++)
      if(R[j] >= R[i]) {
          p  = R[i];
        R[i] = R[j];
        R[j] = p;
      }
}

Preke.cpp

#include "Preke.h"

main.cpp

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Rinkinys.h"
//----------------------------------------------------
char const CDfv[] = "Duomenys.txt";
char const CRfv[] = "Rezultatai.txt";
//----------------------------------------------------
void Duomenys(Rinkinys & R);
void Spausdinti(Rinkinys & R);
void Atrinkti(Rinkinys & R, Preke p, Rinkinys & A);
//----------------------------------------------------
int main()
{
	ofstream fr(CRfv); fr.close();
}
//----------------------------------------------------
void Duomenys(Rinkinys & R)
{ 
  ifstream fd(CDfv);
  bool yra = true;
  int k = R.Talpa();
  fd.ignore(150, '\n');              // praleidžiama komentarų eilutė
  fd.ignore(150, '\n');              // praleidžiama komentarų eilutė
  char eil[36]; int atdata, pardata, pkiek; double kaina;
  while(!fd.eof() && yra) {         // kol yra duomenų ir ji telpa į masyvą
    fd.get(eil, sizeof eil);
    fd >> atdata >> pardata >> pkiek >> kaina;
    if(!fd.eof() && (R.Kiek() < k) )
       R.Deti(Preke(eil, atdata, pardata, pkiek, kaina));
    else yra = false;
    fd.ignore();
  }
  fd.close();
}
//----------------------------------------------------

//----------------------------------------------------
void Atrinkti(Rinkinys & R, Preke p, Rinkinys & A)
{
  for (int i = 0; i < R.Kiek(); i++){
    Preke pr = R.Imti(i);
    if (pr == p) A.Deti(pr);
  }
}

ERRORS THAT I'm GETTING

>------ Build started: Project: L6-15, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2148: total size of array must not exceed 0x7fffffff bytes
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2079: 'Preke::Rinkinys::R' uses undefined class 'Preke'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(8) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(8) : error C2864: 'Preke::CDfv' : only static const integral data members can be initialized within a class
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : error C2229: class 'Preke' has an illegal zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : error C2864: 'Preke::CRfv' : only static const integral data members can be initialized within a class
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(21) : error C2535: 'void Preke::Duomenys(Preke::Rinkinys &)' : member function already defined or declared
1>        c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(11) : see declaration of 'Preke::Duomenys'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(42) : error C2535: 'void Preke::Atrinkti(Preke::Rinkinys &,Preke,Preke::Rinkinys &)' : member function already defined or declared
1>        c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(13) : see declaration of 'Preke::Atrinkti'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(48) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Rinkinys.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2148: total size of array must not exceed 0x7fffffff bytes
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2079: 'Preke::Rinkinys::R' uses undefined class 'Preke'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(4) : error C3254: 'Preke' : class contains explicit override 'Rikiuoti' but does not derive from an interface that contains the function declaration
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(4) : error C2838: 'Rikiuoti' : illegal qualified name in member declaration
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(14) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Preke.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.cpp(2) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Generating Code...
1>Build log was saved at "file://c:\Users\andriusa\Desktop\L6_v2\L6-15\L6-15\Debug\BuildLog.htm"
1>L6-15 - 14 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

now my first guess it has something to do with me having const in main.cpp and preke.h that doesn't go along for some reason. Any help will be appreciated!

I think you can't initialise Cmax within the class:

static const int CMax = 100;

Try this:

  • In your Rinkinys.h file do the following alterations
    static const int CMax;
          Preke R[];
  • Now add to the top of your Rinkinys.cpp file:
    const int Riknikys::Cmax = 100;
          Preke Rinkinys::R[Cmax];

Post here if some of the errors were solved. :)

It just gives more errors I think

1>------ Build started: Project: L6-15, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2057: expected constant expression
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2079: 'Preke::Rinkinys::R' uses undefined class 'Preke'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2229: class 'Preke::Rinkinys' has an illegal zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(8) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(8) : error C2864: 'Preke::CDfv' : only static const integral data members can be initialized within a class
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : error C2229: class 'Preke' has an illegal zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(9) : error C2864: 'Preke::CRfv' : only static const integral data members can be initialized within a class
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(21) : error C2535: 'void Preke::Duomenys(Preke::Rinkinys &)' : member function already defined or declared
1>        c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(11) : see declaration of 'Preke::Duomenys'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(42) : error C2535: 'void Preke::Atrinkti(Preke::Rinkinys &,Preke,Preke::Rinkinys &)' : member function already defined or declared
1>        c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(13) : see declaration of 'Preke::Atrinkti'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\main.cpp(48) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Rinkinys.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2057: expected constant expression
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2079: 'Preke::Rinkinys::R' uses undefined class 'Preke'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.h(8) : error C2229: class 'Preke::Rinkinys' has an illegal zero-sized array
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(2) : error C2653: 'Riknikys' : is not a class or namespace name
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(2) : error C2864: 'Preke::Cmax' : only static const integral data members can be initialized within a class
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(3) : error C2597: illegal reference to non-static member 'Preke::Cmax'
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(3) : error C2838: 'R' : illegal qualified name in member declaration
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(6) : error C3254: 'Preke' : class contains explicit override 'Rikiuoti' but does not derive from an interface that contains the function declaration
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(6) : error C2838: 'Rikiuoti' : illegal qualified name in member declaration
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\rinkinys.cpp(16) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Preke.cpp
1>c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.cpp(3) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\andriusa\desktop\l6_v2\l6-15\l6-15\preke.h(7)' was matched
1>Generating Code...
1>Build log was saved at "file://c:\Users\andriusa\Desktop\L6_v2\L6-15\L6-15\Debug\BuildLog.htm"
1>L6-15 - 20 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ok here is the code that I managed to compile on my system. I found one missing closing bracket at operator== in Preke class as well as calling operator>= while it is not defined. I marked all errors with "//!" comments on the side :)

#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

class Preke
{
private:
	string pav;			// prekės pavadinimas
	int atdata;			// atvežimo į parduotuvę data
	int pardata;		// pardavimo data
	int pkiek;			// prekių kiekis
	double kaina;		// prekės kaina
public:
	Preke(string p = "", int ad = 0, int pd = 0, int pk = 0, double k = 0.0):
	  pav(p), atdata(ad), pardata(pd), pkiek(pk), kaina(k) {}
	  ~Preke() {};
	  bool operator == (Preke & pr){
		  return (pr.kaina > kaina) || (pr.kaina == kaina && pr.pav < pav);
      } //!You were missing a closing bracket here

        //!You are also missing operator>= which would probably go here
      bool operator>=(Preke& pr) {
        return pr.atdata >= this->atdata;
      }
	  string Spausdinti()
	  {
		stringstream eil;
		eil.setf(ios::fixed);
		eil << left << setw(35) << pav
			<< right << setprecision(12) << setw(10) << atdata
			<< right << setprecision(12) << setw(10) << pardata
			<< right << setprecision(4) << setw(10) << pkiek
			<< right << setprecision(5) << setw(8) << kaina << endl;

		return eil.str();
	  }
};

// Prekių rinkinio klasė

class Rinkinys
{
private:
	static const int CMax = 100;
    Preke R[CMax];
	int n;		// konteineris - prekiu masyvas
public:
	Rinkinys(): n(0) {}
	~Rinkinys() {}
	int Kiek()  { return n; }
	int Talpa() { return CMax; }
	Preke Imti(int i)  { return R[i]; }
	void Deti(Preke p) { if (n < CMax) R[n++] = p; }
	void Rikiuoti();
};

void Rinkinys::Rikiuoti()
{
  Preke p;
  for(int i = 0; i < n; i++)
    for(int j = i+1; j < n; j++)
      if(R[j] >= R[i]) { //!You don't have an operator>= defined in Preke
          p  = R[i];
        R[i] = R[j];
        R[j] = p;
      }
}

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//----------------------------------------------------
char const CDfv[] = "Duomenys.txt";
char const CRfv[] = "Rezultatai.txt";
//----------------------------------------------------
void Duomenys(Rinkinys & R);
void Spausdinti(Rinkinys & R);
void Atrinkti(Rinkinys & R, Preke p, Rinkinys & A);
//----------------------------------------------------
int main()
{
	ofstream fr(CRfv); fr.close();
}
//----------------------------------------------------
void Duomenys(Rinkinys & R)
{
  ifstream fd(CDfv);
  bool yra = true;
  int k = R.Talpa();
  fd.ignore(150, '\n');              // praleidžiama komentarų eilutė
  fd.ignore(150, '\n');              // praleidžiama komentarų eilutė
  char eil[36]; int atdata, pardata, pkiek; double kaina;
  while(!fd.eof() && yra) {         // kol yra duomenų ir ji telpa į masyvą
    fd.get(eil, sizeof eil);
    fd >> atdata >> pardata >> pkiek >> kaina;
    if(!fd.eof() && (R.Kiek() < k) )
       R.Deti(Preke(eil, atdata, pardata, pkiek, kaina));
    else yra = false;
    fd.ignore();
  }
  fd.close();
}
//----------------------------------------------------

//----------------------------------------------------
void Atrinkti(Rinkinys & R, Preke p, Rinkinys & A)
{
  for (int i = 0; i < R.Kiek(); i++){
    Preke pr = R.Imti(i);
    if (pr == p) A.Deti(pr);
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.