Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int m = 20;
- class Гражд
- {
- private:
- public:
- char name[m]=" "; int age; int tax; Гражд *children[5]; int child;
- bool lgota();
- void read(ifstream&f);// сначала нет налога
- };
- class Налоговая
- {
- private:
- public:
- Гражд * a[m]; int n; int nl;
- void readY(ifstream&f);
- void creat(ifstream&f);
- void recal();
- void main();
- };
- #include "stdafx.h"
- #include "Гражданин.h"
- bool Гражд::lgota()
- {
- int k=0;
- int i = 0;
- while (i<child)
- {
- if (children[i]->age < 18)
- k++;
- i++;
- }
- return (k > 2);
- }
- void Гражд::read(ifstream & f)
- {
- char x;
- int i;
- int j;
- if (!f.eof())
- {
- i = 0;
- while (f.get(x) && x != ' ')//записываем имя каждая строка начинается с пробела
- {
- name[i] = x;
- i++;
- }
- f >> age >> child;/////
- if (child != 0)
- {
- j = 0;
- i = 0;
- while (!f.eof() && j<child)
- {
- f.get(x);
- while (f.get(x) && x != ' ')//записываем детей
- {
- children[j]->name[i] = x;
- }
- f >> children[j]->age >> children[j]->child;
- j++;
- }
- }
- }
- }
- void out(char* b)
- {
- for (int i = 0; i < m&&b[i] != '\0'; i++)
- cout << b[i];
- cout << ' ';
- }
- void Налоговая::readY(ifstream & f)
- {
- Гражд g;
- for (int i = 0; i < m; i++)
- {
- g.read(f);//считали с файла информацию об одном гражданине
- //strcpy(a[i]->name, g.name);
- for (int j = 0; j < m; j++)
- a[i]->name[j] = g.name[j];
- a[i]->age = g.age;
- a[i]->tax = g.tax;
- for (int j = 0; j < m; j++)
- a[i]->children[j] = g.children[j];
- }
- }
- void Налоговая::creat(ifstream & f)
- {
- readY(f);
- cout << "Введите налог для обычных граждан ";
- cin >> n;
- cout << "Введите налог для льготной катерогии ";
- cin >> nl;
- }
- void Налоговая::recal()
- {
- for (int i = 0; i < m; i++)
- {
- if (a[i]->lgota())
- a[i]->tax = nl;
- else
- a[i]->tax = n;
- }
- }
- void Налоговая::main()
- {
- recal();
- for (int i = 0; i < m; i++)
- {
- out(a[i]->name);
- cout << a[i]->tax << endl;
- }
- }
- #include "stdafx.h"
- #include "Гражданин.h"
- int main()
- {
- setlocale(LC_ALL, "Russian");
- ifstream in("Text.txt");
- Налоговая k;
- k.creat(in);
- k.main();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment