Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. struct autost{
  7. char rendszam[8];
  8. char tipus[20];
  9. double ar;
  10. unsigned int ev;
  11. };
  12.  
  13. int Bovit(char *fajlnev)
  14. {
  15. autost aut;
  16. char eldont;
  17. int db=0;
  18. ofstream ki(fajlnev,ios::app|ios::binary);
  19. if(ki.fail())
  20. {
  21. cerr << "Hibas fajlnyitas." << endl;
  22. system("PAUSE");
  23. exit(-1);
  24. }
  25. do
  26. {
  27. cout << "Auto rendszama:";
  28. cin.getline(aut.rendszam,8);
  29. cin.sync();
  30. cin.clear();
  31. cout << "Auto tipusa:";
  32. cin.get(aut.tipus,19);
  33. cin.sync();
  34. cin.clear();
  35. cout << "Auto ara:";
  36. cin >> aut.ar;
  37. cout << "Auto evjara:";
  38. cin >> aut.ev;
  39. db++;
  40. ki.write((char*)&aut,sizeof(aut));
  41. cout << "Uj adat(I/N):";
  42. cin >> eldont;
  43. } while(toupper(eldont)=='I');
  44. ki.close();
  45. return db;
  46. }
  47.  
  48. int megjelenit(char *fajlnev)
  49. {
  50. autost aut;
  51. int db=0;
  52. ifstream be(fajlnev, ios::app|ios::binary);
  53. if(be.fail())
  54. {
  55. cerr << "Hibas fajlnyitas." << endl;
  56. system("PAUSE");
  57. exit(-1);
  58. }
  59. while(be.read((char*)&aut, sizeof(aut))) //(!be.eof()) is jű
  60. {
  61. be.read((char*)&aut,sizeof(aut));
  62. db++;
  63. cout << aut.rendszam << " " << aut.tipus << " " << aut.ar << " " << aut.ev << endl;
  64. }
  65. return db;
  66. }
  67.  
  68. bool keres(char *fajlnev, char *r, char *t, int a, int e)
  69. {
  70. autost aut;
  71. bool adat=false;
  72. ifstream be(fajlnev, ios::app|ios::binary);
  73. if(be.fail())
  74. {
  75. cerr << "Hibas fajlnyitas." << endl;
  76. system("PAUSE");
  77. exit(-1);
  78. }
  79. while(!be.eof())
  80. {
  81. be.read((char*)&aut,sizeof(aut));
  82. if(strcmp(aut.rendszam,r)==0 && strcmp(aut.tipus,t)==0 && aut.ar==a && aut.ev==e) //strcmp char tipus összehasonlításhoz
  83. {
  84. adat=true;
  85. cout << aut.rendszam << endl;
  86. cout << aut.tipus << endl;
  87. cout << aut.ar << endl;
  88. cout << aut.ev << endl;
  89. break;
  90. }
  91. }
  92. return adat;
  93. }
  94.  
  95. autost legdragab(char *fajlnev)
  96. {
  97. autost a;
  98. autost aut={"","",0,0};
  99.  
  100. ifstream be(fajlnev, ios::app|ios::binary);
  101. if(be.fail())
  102. {
  103. cerr << "Hibas fajlnyitas." << endl;
  104. system("PAUSE");
  105. exit(-1);
  106. }
  107. while(be.read((char*)&a, sizeof(aut))) //(!be.eof()) is jű
  108. {
  109. if(a.ar>aut.ar)
  110. aut=a;
  111. }
  112. be.close();
  113. return aut;
  114. }
  115.  
  116. int main()
  117. {
  118. char fajlnev[50]={"C:\\Munka\\autok.dat"};
  119. int viszi;
  120. /*viszi=Bovit(fajlnev);
  121. cout << viszi << endl;*/
  122. megjelenit(fajlnev);
  123. //bool ss=keres(fajlnev,"abc-666","qwertz",50000,2000);
  124. //cout << ss << endl;
  125. autost aut=legdragab(fajlnev);
  126. cout << aut.rendszam << " " << aut.tipus << " " << aut.ar << " " << aut.ev << endl;
  127. system("PAUSE");
  128. return 0;
  129. }
Add Comment
Please, Sign In to add comment