Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include<fstream>
- using namespace std;
- static int iras_times= 0;
- class Allat {
- public:
- string nev;
- int kor;
- string get_nev(){
- return nev;
- }
- int get_kor(){
- return kor;
- }
- Allat(string nev_in,int kor_in){
- nev=nev_in;
- kor=kor_in;
- }
- virtual void say(){
- cout<<kor<<nev<<endl;
- }
- virtual void clean(){
- if (iras_times ==0) {
- try{
- remove("allatok.csv");
- }catch(exception E){
- cout<<"a file mar nem letezik"<<endl;
- }
- }
- }
- virtual void filebair(){
- ofstream file;
- file.open("allatok.csv",ios_base::app);
- file <<nev<<";"<<kor<<";";
- file.close();
- iras_times++;
- }
- };
- class Cica :public Allat{
- public:
- int karom;
- Cica(string nev_in,int kor_in, int karom_in):Allat(nev_in,kor_in){
- karom=karom_in;
- }
- virtual void filebair(){
- clean();
- ofstream file;
- file.open("allatok.csv",ios_base::app);
- file <<"cica"<<";"<<nev<<";"<<kor<<";"<<karom<<";"<<endl;
- file.close();
- iras_times++;
- }
- };
- class Kutya :public Allat{
- public:
- int db;
- Kutya(string nev_in,int kor_in, int db_in):Allat(nev_in,kor_in){
- db=db_in;
- }
- virtual void filebair(){
- clean();
- ofstream file;
- file.open("allatok.csv",ios_base::app);
- file <<"kutya"<<";"<<nev<<";"<<kor<<";"<<db<<";"<<endl;
- file.close();
- iras_times++;
- }
- };
- class Parser{
- string original_line;
- vector<string>szovegek;
- vector<int>integerek;
- public:
- Parser(string line){
- original_line=line;
- int hol_allunk_most=0;
- if (hol_allunk_most>=1){
- }else {
- string szoveg="";
- for (int i=0;i<line.length();i++){
- if(line[i]==';'){
- hol_allunk_most+=1;
- break;
- }
- szoveg+=line[i];
- }
- cout<<szoveg<<endl;
- }
- /* if(tipus=="cica"){
- cout<<"cicatipus"<<endl;
- }else if(tipus=="kutya"){
- cout<<"kutyatipus"<<endl;
- }else{
- cout<<"baj van"<<endl;
- }*/
- }
- };
- int main()
- {
- vector<Allat*> allatok;
- allatok.push_back(new Cica("Cirmi",15,20));
- allatok.push_back(new Kutya("Vadkacsa",1,80));
- for (int i=0;i<allatok.size();i++){
- allatok[i]->say();
- allatok[i]->filebair();
- }
- string line;
- string fajta;
- ifstream file("allatok.csv");
- if (file.is_open()){
- while (getline(file,line)){
- new Parser(line);
- /*cout<<line<<endl;
- string tipus="";
- for (int i=0;i<line.length();i++){
- if(line[i]==';'){
- break;
- }
- tipus+=line[i];
- }
- if(tipus=="cica"){
- cout<<"cicatipus"<<endl;
- }else if(tipus=="kutya"){
- cout<<"kutyatipus"<<endl;
- }else{
- cout<<"baj van"<<endl;
- }*/
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement