DilyaraL

налог

Nov 6th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. const int m = 20;
  6.  
  7. class Гражд
  8. {
  9. private:
  10. public:
  11. char name[m]=" "; int age; int tax; Гражд *children[5]; int child;
  12. bool lgota();
  13. void read(ifstream&f);// сначала нет налога
  14. };
  15.  
  16. class Налоговая
  17. {
  18. private:
  19. public:
  20. Гражд * a[m]; int n; int nl;
  21. void readY(ifstream&f);
  22. void creat(ifstream&f);
  23. void recal();
  24. void main();
  25.  
  26. };
  27. #include "stdafx.h"
  28. #include "Гражданин.h"
  29.  
  30.  
  31. bool Гражд::lgota()
  32. {
  33. int k=0;
  34. int i = 0;
  35. while (i<child)
  36. {
  37. if (children[i]->age < 18)
  38. k++;
  39. i++;
  40. }
  41. return (k > 2);
  42. }
  43.  
  44. void Гражд::read(ifstream & f)
  45. {
  46.  
  47. char x;
  48. int i;
  49. int j;
  50. if (!f.eof())
  51. {
  52. i = 0;
  53. while (f.get(x) && x != ' ')//записываем имя каждая строка начинается с пробела
  54. {
  55. name[i] = x;
  56. i++;
  57. }
  58. f >> age >> child;/////
  59. if (child != 0)
  60. {
  61. j = 0;
  62. i = 0;
  63. while (!f.eof() && j<child)
  64. {
  65. f.get(x);
  66. while (f.get(x) && x != ' ')//записываем детей
  67. {
  68. children[j]->name[i] = x;
  69. }
  70.  
  71. f >> children[j]->age >> children[j]->child;
  72. j++;
  73. }
  74.  
  75. }
  76. }
  77.  
  78. }
  79.  
  80. void out(char* b)
  81. {
  82. for (int i = 0; i < m&&b[i] != '\0'; i++)
  83. cout << b[i];
  84. cout << ' ';
  85. }
  86.  
  87. void Налоговая::readY(ifstream & f)
  88. {
  89. Гражд g;
  90. for (int i = 0; i < m; i++)
  91. {
  92. g.read(f);//считали с файла информацию об одном гражданине
  93. //strcpy(a[i]->name, g.name);
  94. for (int j = 0; j < m; j++)
  95. a[i]->name[j] = g.name[j];
  96. a[i]->age = g.age;
  97. a[i]->tax = g.tax;
  98. for (int j = 0; j < m; j++)
  99. a[i]->children[j] = g.children[j];
  100. }
  101. }
  102.  
  103. void Налоговая::creat(ifstream & f)
  104. {
  105. readY(f);
  106. cout << "Введите налог для обычных граждан ";
  107. cin >> n;
  108. cout << "Введите налог для льготной катерогии ";
  109. cin >> nl;
  110. }
  111.  
  112. void Налоговая::recal()
  113. {
  114. for (int i = 0; i < m; i++)
  115. {
  116. if (a[i]->lgota())
  117. a[i]->tax = nl;
  118. else
  119. a[i]->tax = n;
  120. }
  121. }
  122.  
  123. void Налоговая::main()
  124. {
  125. recal();
  126. for (int i = 0; i < m; i++)
  127. {
  128. out(a[i]->name);
  129. cout << a[i]->tax << endl;
  130. }
  131. }
  132.  
  133. #include "stdafx.h"
  134. #include "Гражданин.h"
  135.  
  136.  
  137. int main()
  138. {
  139. setlocale(LC_ALL, "Russian");
  140. ifstream in("Text.txt");
  141. Налоговая k;
  142. k.creat(in);
  143. k.main();
  144. system("pause");
  145. return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment