Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include<fstream>
  4.  
  5. using namespace std;
  6.  
  7. static int iras_times= 0;
  8.  
  9. class Allat {
  10. public:
  11.  
  12. string nev;
  13. int kor;
  14.  
  15.  
  16.  
  17.  
  18. string get_nev(){
  19. return nev;
  20. }
  21.  
  22. int get_kor(){
  23. return kor;
  24. }
  25.  
  26. Allat(string nev_in,int kor_in){
  27. nev=nev_in;
  28. kor=kor_in;
  29. }
  30.  
  31. virtual void say(){
  32. cout<<kor<<nev<<endl;
  33. }
  34.  
  35. virtual void clean(){
  36. if (iras_times ==0) {
  37. try{
  38. remove("allatok.csv");
  39. }catch(exception E){
  40. cout<<"a file mar nem letezik"<<endl;
  41. }
  42. }
  43. }
  44.  
  45. virtual void filebair(){
  46.  
  47.  
  48. ofstream file;
  49. file.open("allatok.csv",ios_base::app);
  50. file <<nev<<";"<<kor<<";";
  51. file.close();
  52. iras_times++;
  53. }
  54.  
  55. };
  56.  
  57. class Cica :public Allat{
  58. public:
  59. int karom;
  60.  
  61. Cica(string nev_in,int kor_in, int karom_in):Allat(nev_in,kor_in){
  62. karom=karom_in;
  63. }
  64.  
  65. virtual void filebair(){
  66. clean();
  67. ofstream file;
  68. file.open("allatok.csv",ios_base::app);
  69. file <<"cica"<<";"<<nev<<";"<<kor<<";"<<karom<<";"<<endl;
  70. file.close();
  71. iras_times++;
  72. }
  73.  
  74. };
  75.  
  76. class Kutya :public Allat{
  77. public:
  78. int db;
  79.  
  80. Kutya(string nev_in,int kor_in, int db_in):Allat(nev_in,kor_in){
  81. db=db_in;
  82. }
  83.  
  84. virtual void filebair(){
  85. clean();
  86. ofstream file;
  87. file.open("allatok.csv",ios_base::app);
  88. file <<"kutya"<<";"<<nev<<";"<<kor<<";"<<db<<";"<<endl;
  89. file.close();
  90. iras_times++;
  91. }
  92.  
  93.  
  94. };
  95.  
  96. class Parser{
  97.  
  98. string original_line;
  99. vector<string>szovegek;
  100. vector<int>integerek;
  101.  
  102.  
  103. public:
  104. Parser(string line){
  105. original_line=line;
  106. int hol_allunk_most=0;
  107.  
  108.  
  109. if (hol_allunk_most>=1){
  110.  
  111. }else {
  112. string szoveg="";
  113. for (int i=0;i<line.length();i++){
  114. if(line[i]==';'){
  115. hol_allunk_most+=1;
  116. break;
  117. }
  118. szoveg+=line[i];
  119. }
  120. cout<<szoveg<<endl;
  121. }
  122.  
  123. /* if(tipus=="cica"){
  124. cout<<"cicatipus"<<endl;
  125. }else if(tipus=="kutya"){
  126. cout<<"kutyatipus"<<endl;
  127. }else{
  128. cout<<"baj van"<<endl;
  129. }*/
  130. }
  131. };
  132.  
  133. int main()
  134. {
  135.  
  136. vector<Allat*> allatok;
  137.  
  138. allatok.push_back(new Cica("Cirmi",15,20));
  139. allatok.push_back(new Kutya("Vadkacsa",1,80));
  140.  
  141.  
  142. for (int i=0;i<allatok.size();i++){
  143. allatok[i]->say();
  144. allatok[i]->filebair();
  145. }
  146.  
  147. string line;
  148. string fajta;
  149. ifstream file("allatok.csv");
  150. if (file.is_open()){
  151. while (getline(file,line)){
  152. new Parser(line);
  153. /*cout<<line<<endl;
  154. string tipus="";
  155. for (int i=0;i<line.length();i++){
  156. if(line[i]==';'){
  157. break;
  158. }
  159. tipus+=line[i];
  160. }
  161. if(tipus=="cica"){
  162. cout<<"cicatipus"<<endl;
  163. }else if(tipus=="kutya"){
  164. cout<<"kutyatipus"<<endl;
  165. }else{
  166. cout<<"baj van"<<endl;
  167. }*/
  168. }
  169. }
  170.  
  171.  
  172.  
  173.  
  174. return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement