DilyaraL

налоговаяклассы

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