Prekė.h
#include <string>
using namespace std;
class Prekė
{
private:
string pavadinimas;
double pagaminimodata;
int kiekis;
double kaina;
double vartojimolaikas;
public:
Prekė();
Prekė(string pavad, double pagam_dat, int kiek, double kain, double vart_laik);
~Prekė();
string ImtiPavadinimą() { return pavadinimas; }
double ImtiPagaminimoDatą() { return pagaminimodata; }
int ImtiKiekį() { return kiekis; }
double ImtiKainą() { return kaina; }
double ImtiVartojimoLaiką() { return vartojimolaikas; }
bool operator >(const Prekė & kitas);
};
Galiojimas.h
#include "Prekė.h"
class Galiojimas
{
public:
static const int CMax = 100;
private:
Prekė P[CMax];
int n;
public:
Galiojimas();
~Galiojimas();
void DėtiPrekę(Prekė pr, int ind) { P[ind] = pr; }
Prekė ImtiPrekę(int ind) { return P[ind]; }
void DėtiNaująPrekę(Prekė pr) { P[n] = pr;
n++; }
int ImtiN() { return n; }
void Rikiuoti();
};
Prekė.cpp
#include "Prekė.h"
Prekė::Prekė(): pavadinimas(""), pagaminimodata(0.0), kiekis(0),
kaina(0.0), vartojimolaikas(0.0)
{
}
Prekė::Prekė(string pavad, double pagam_dat, int kiek, double kain, double vart_laik):
pavadinimas(pavad), pagaminimodata(pagam_dat), kiekis(kiek),
kaina(kain), vartojimolaikas(vart_laik)
{
}
Prekė::~Prekė()
{
}
bool Prekė::operator >(const Prekė & kitas)
{
return vartojimolaikas > kitas.vartojimolaikas;
}
Galiojimas.cpp
#include "Galiojimas.h"
Galiojimas::Galiojimas(): n(0)
{
}
Galiojimas::~Galiojimas()
{
}
void Galiojimas::Rikiuoti()
{
for (int i = 0; i < n-1; i++) {
int mind = i;
for (int j = i+1; j < n; j++)
if (P[j] > P[mind])
mind = j;
Prekė pr = P[mind];
P[mind] = P[i];
P[i] = pr;
}
}
main.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include "Galiojimas.h"
using namespace std;
//----------------------------------------------------------
const char CDfv[] = "Duomenys.txt";
const char CRfv[] = "Rezultatai.txt";
//----------------------------------------------------------
void Įvesti(const char fv[], Galiojimas & prekės);
void Spausdinti(const char fv[], Galiojimas & prekės, string komentarai);
void Atrinkti(Galiojimas & prekės, Galiojimas & nebegaliojančiosPrekės, double data);
//----------------------------------------------------------
int main()
{
setlocale(LC_ALL, "Lithuanian");
ofstream fr(CRfv); fr.close();
Galiojimas visosPrekės,
nebegaliojančiosPrekės;
double data;
double nuostolis;
cout << "Programa darbą pradėjo" << endl;
cout << "Įveskite šiandienos datą (pvz.: 2011.11.28): " << endl;
cin >> data >> endl;
cout << "Gautas nuostolis sunaikinus nebegaliojančias prekes: " << nuostolis << endl;
Įvesti(CDfv, visosPrekės);
Spausdinti(CRfv, visosPrekės, " Visų prekių sąrašas");
Atrinkti(visosPrekės, nebegaliojančiosPrekės, data);
nebegaliojančiosPrekės.Rikiuoti();
Spausdinti(CRfv, nebegaliojančiosPrekės, " Sąrašas prekių, kurių galiojimo laikas pasibaigęs");
return 0;
}
//----------------------------------------------------------
void Įvesti(const char fv[], Galiojimas & prekės)
{
string pavadinimas;
double pagaminimodata;
int kiekis;
double kaina;
double vartojimolaikas;
ifstream fd(fv);
while (!fd.eof() && prekės.ImtiN() < prekės.CMax) {
fd >> pavadinimas >> pagaminimodata >> kiekis >> kaina >> vartojimolaikas;
fd.ignore();
Prekė P(pavadinimas, pagaminimodata, kiekis, kaina, vartojimolaikas);
prekės.DėtiNaująPrekę(P);
}
fd.close();
}
//----------------------------------------------------------
void Spausdinti(const char fv[], Galiojimas & prekės, string komentarai)
{
ofstream fr(fv, ios::app);
fr << komentarai << endl;
fr << "----------------------------------------------------------------------" << endl;
fr << "Pavadinimas Pagaminimo data Kiekis Kaina Vartojimo laikas" << endl;
fr << "----------------------------------------------------------------------" << endl;
for (int i = 0; i < prekės.ImtiN(); i++) {
Prekė P = prekės.ImtiPrekę(i);
fr << left << setw(12) << P.ImtiPavadinimą() << " "
<< right << setw(4) << setprecision(8) << fixed << P.ImtiPagaminimoDatą() << " "
<< P.ImtiKiekį() << " "
<< setw(7)<< setprecision(2) << fixed
<< P.ImtiKainą() << " "
<< setw(4) << setprecision(2) << fixed << P.ImtiVartojimoLaiką() << endl;
}
fr << "------------------------------------------------" << endl << endl;
fr.close();
}
//----------------------------------------------------------
void Atrinkti(Galiojimas & prekės, Galiojimas & nebegaliojančiosPrekės, double data)
{
for (int i = 0; i < prekės.ImtiN(); i++) {
Prekė P = prekės.ImtiPrekę(i);
if ((P.ImtiPagaminimoDatą() + P.ImtiVartojimoLaiką() >= data))
nebegaliojančiosPrekės.DėtiNaująPrekę(P);
}
}
//----------------------------------------------------------
double Nuostolis(Galiojimas & prekės, Galiojimas & nebegaliojančiosPrekės, int n)
{
double nuostolis = 0;
for (int i = 0; i < prekės.ImtiN(); i++) {
Prekė P = prekės.ImtiPrekę(i);
nuostolis += (P.ImtiKiekį() * P.ImtiKainą());
n++;
return nuostolis;
}
}
Error
cout << "Įveskite šiandienos datą (pvz.: 2011.11.28): " << endl;
cin >> data >> endl;
cout << "Gautas nuostolis sunaikinus nebegaliojančias prekes: " << nuostolis << endl;
------ Build started: Project: , Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\.cpp(25) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): or 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(155): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(161): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(168): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(175): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(194): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(228): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(247): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(273): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(291): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(309): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(329): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(348): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(367): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(386): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(404): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(422): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 9.0\vc\include\istream(441): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::basic_istream<_Elem,_Traits>, overloaded-function)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
Build log was saved at "file://c:\.htm"
- 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What's the problem?