Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- struct kolcsonzes
- {
- char datum[12];
- char tipus[20];
- int sorszam;
- int ido;
- };
- class kolcsonzo
- {
- private:
- kolcsonzes *k;
- int db;
- public:
- kolcsonzo(char fnev[]);
- ~kolcsonzo();
- int Getdb();
- int GetMagellan();
- int GetMedian();
- int MedianBevetel();
- int Osszbevetel();
- int LeghosszabbKolcsonzes();
- int LegtobbKolcsonzes();
- void Lista();
- void Kiir();
- };
- kolcsonzo::kolcsonzo(char fnev[])
- {
- ifstream be(fnev);
- if(!be)
- {
- cerr<<"hiba";
- exit(-1);
- }
- db=0;
- char sor[80];
- while(!be.eof())
- {
- be.getline(sor,80);
- if(!be.eof()) db++;
- }
- be.clear();
- be.seekg(0,ios::beg);
- k=new kolcsonzes[db];
- if(k==0)
- {
- cerr<<"hiba2";
- exit(-2);
- }
- for(int i=0; i<db;i++)
- {
- be>>k[i].datum;
- be>>k[i].tipus;
- be>>k[i].sorszam;
- be>>k[i].ido;
- }
- be.close();
- }
- kolcsonzo::~kolcsonzo()
- {
- if(k!=0)
- delete[]k;
- }
- int kolcsonzo::Getdb()
- {
- return db;
- }
- int kolcsonzo::GetMagellan()
- {
- int m=0;
- for (int i = 0; i<db; i++)
- {
- if(strcmp(k[i].tipus,"magellan")==0)
- {
- m++;
- }
- }
- return m;
- }
- int kolcsonzo::GetMedian()
- {
- int m=0;
- for (int i = 0; i<db; i++)
- {
- if(strcmp(k[i].tipus,"median")==0)
- {
- m++;
- }
- }
- return m;
- }
- int kolcsonzo::MedianBevetel()
- {
- int mbev=0;
- for (int i = 0; i<db; i++)
- {
- if(strcmp(k[i].tipus,"median")==0)
- {
- mbev+=k[i].ido*1000;
- }
- }
- return mbev;
- }
- int kolcsonzo::Osszbevetel()
- {
- int bev=0;
- for (int i = 0; i<db; i++)
- {
- if(strcmp(k[i].tipus,"median")==0)
- {
- bev+=k[i].ido*1000;
- }
- else
- {
- bev+=k[i].ido*1200;
- }
- }
- return bev;
- }
- int kolcsonzo::LeghosszabbKolcsonzes()
- {
- int l=k[0].ido;
- for (int i = 0; i<db; i++)
- {
- if(k[i].ido>l)
- {
- l=k[i].ido;
- }
- }
- return l;
- }
- int kolcsonzo::LegtobbKolcsonzes()
- {
- int max=0, maxsorszam=0, hanyszor=0;
- for (int s = 20; s<31; s++)
- {
- hanyszor=0;
- for (int i = 0; i<db; i++)
- {
- if(k[i].sorszam==s)
- {
- hanyszor++;;
- }
- }
- if(max<hanyszor)
- {
- maxsorszam=s;
- max=hanyszor;
- }
- }
- return maxsorszam;
- }
- void kolcsonzo::Lista()
- {
- cout <<setw(12)<<"datum"<<setw(20)<<"tipus"<<setw(10)<<"sorszam"<<setw(10)<<"kolcsido"<<endl;
- for (int i = 0; i<db; i++)
- {
- if(k[i].ido>5)
- {
- cout << setw(12)<<k[i].datum<<setw(20)<<k[i].tipus<<setw(10)<<k[i].sorszam<<setw(10)<<k[i].ido<<endl;
- }
- }
- }
- void kolcsonzo::Kiir()
- {
- cout <<setw(14)<<"datum"<<setw(20)<<"tipus"<<setw(10)<<"sorszam"<<setw(10)<<"kolcsido"<<endl;
- for (int i = 0; i<db; i++)
- {
- cout << i+1 <<"."<<setw(12)<<k[i].datum<<setw(20)<<k[i].tipus<<setw(10)<<k[i].sorszam<<setw(10)<<k[i].ido<<endl;
- }
- }
- int main(int argdb, char* argv[])
- {
- if(argdb!=2)
- {
- cout<<"hibas programinditas\n";
- return 1;
- }
- kolcsonzo ketkerek(argv[1]);
- cout<<"Az allomanyban levo adatok:\n";
- ketkerek.Kiir();
- cout<<endl;
- cout<<"A kolcsonzesek szama: "<<ketkerek.Getdb()<<endl;
- cout<<"A magellan kolcsonzesek szama: "<<ketkerek.GetMagellan()<<endl;
- cout<<"A median kolcsonzesek szama: "<<ketkerek.GetMedian()<<endl;
- cout<<"A median kerekparokkal szerzett bevetel: "<<ketkerek.MedianBevetel()<<endl;
- cout<<"A kerekparokkal szerzett osszbevetel: "<<ketkerek.Osszbevetel()<<endl;
- cout<<"A leghosszabb kolcsonzes ideje: "<<ketkerek.LeghosszabbKolcsonzes()<<endl;
- cout<<"A legtobbszor kolcsonzott kerekpar sorszama: "<<ketkerek.LegtobbKolcsonzes()<<endl;
- cout<<endl;
- cout<<"Az 5 oranal hosszabb kolcsonzesek:\n";
- ketkerek.Lista();
- cout<<endl<<endl;
- cout<<"***************** dinamikus objektum *****************\n\n";
- kolcsonzo *kektura=new kolcsonzo(argv[1]);
- if(kektura==0)
- {
- cerr<<"keves a memoria 2";
- return 2;
- }
- cout<<"Az allomanyban levo adatok:\n";
- kektura->Kiir();
- cout<<endl;
- cout<<"A kolcsonzesek szama: "<<kektura->Getdb()<<endl;
- cout<<"A magellan kolcsonzesek szama: "<<kektura->GetMagellan()<<endl;
- cout<<"A median kolcsonzesek szama: "<<kektura->GetMedian()<<endl;
- cout<<"A median kerekparokkal szerzett bevetel: "<<kektura->MedianBevetel()<<endl;
- cout<<"A kerekparokkal szerzett osszbevetel: "<<kektura->Osszbevetel()<<endl;
- cout<<"A leghosszabb kolcsonzes ideje: "<<kektura->LeghosszabbKolcsonzes()<<endl;
- cout<<"A legtobbszor kolcsonzott kerekpar sorszama: "<<kektura->LegtobbKolcsonzes()<<endl;
- cout<<endl;
- cout<<"Az 5 oranal hosszabb kolcsonzesek:\n";
- kektura->Lista();
- delete kektura;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement