Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1.  
  2. #include <fstream>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Person {
  8.  
  9. public:
  10. string name;
  11. string surname;
  12. int age;
  13. float effectiveness;
  14.  
  15. void setName(string newName)
  16. {
  17. name = newName;
  18. }
  19.  
  20. string getName()
  21. {
  22. return name;
  23. }
  24.  
  25. void setSurname(string newSurname)
  26. {
  27. surname = newSurname;
  28. }
  29.  
  30. string getSurname()
  31. {
  32. return surname;
  33. }
  34.  
  35. void setAge(int newAge)
  36. {
  37. age = newAge;
  38. }
  39.  
  40. int getAge()
  41. {
  42. return age;
  43. }
  44.  
  45. void setEffectiveness(float newEffectiveness)
  46. {
  47. effectiveness = newEffectiveness;
  48. }
  49.  
  50. float getEffectiveness()
  51. {
  52. return effectiveness;
  53. }
  54.  
  55. };
  56.  
  57.  
  58. int main()
  59. {
  60. Person p1;
  61.  
  62. ofstream fileMax;
  63. string plik;
  64.  
  65. string name;
  66. string surname;
  67. int age;
  68. int j, i;
  69. float effectiveness;
  70. float effectivenessMax = 0;
  71.  
  72. cout << "Podaj nazwe pliku.\n" ;
  73. cin >> plik;
  74. ofstream plyk;
  75. plyk.open(plik);
  76. if(!plyk.is_open())
  77. {
  78. cout << "Plik nie jest otwarty.\n";
  79. }
  80.  
  81. cout << "Podaj ile osob chcesz dodac:";
  82. cin >> j;
  83. for(i=0; i<j; i++){
  84. cin >> name >> surname >> age >> effectiveness;
  85. plyk << name << " " << surname << " " << age << " " << effectiveness << endl;
  86.  
  87. }
  88. plyk.close();
  89.  
  90. ifstream file;
  91.  
  92. file.open(plik);
  93. if (!file.good())
  94. {
  95. cout << "Nie znaleziono pliku";
  96. exit(0);
  97. }
  98. else
  99. {
  100. string linia;
  101. while (getline(file,linia))
  102. {
  103. file >> name;
  104. file >> surname;
  105. file >> age;
  106. file >> effectiveness;
  107. if (name.length() > 3)
  108. {
  109.  
  110. if (name.substr(name.length() - 3, 3) == "ski")
  111. {
  112.  
  113. if (effectiveness > effectiveness)
  114. {
  115. p1.setName(name);
  116. p1.setSurname(surname);
  117. p1.setAge(age);
  118. p1.setEffectiveness(effectiveness);
  119.  
  120. }
  121.  
  122. }
  123. }
  124. }
  125. }
  126. file.close();
  127.  
  128. surname = p1.getSurname();
  129. string surnameextra;
  130.  
  131. for (int i = 0; i < surname.length() - 4; i++)
  132. {
  133. surnameextra.insert(i, "*");
  134. }
  135.  
  136. surname.replace(1, surname.length() - 3, surnameextra);
  137. p1.setSurname(surname);
  138. string nazwa=nazwa+".max.txt";
  139. fileMax.open(nazwa);
  140. if (!fileMax.good())
  141. {
  142. cout << "Nie Udalo sie otworzyc pliku";
  143. return 0;
  144. }
  145. else
  146. {
  147. fileMax << p1.getName() << p1.getSurname() << p1.getAge();
  148. }
  149.  
  150. fileMax.close();
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement