Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <cstring>
- #include <string>
- #include < math.h >
- using namespace std;
- struct date
- {
- char day[3];
- char mon[3];
- char year[5];
- };
- struct place
- {
- char city[30];
- char street[30];
- int house;
- int flat;
- int nomber;
- };
- struct list
- {
- char fam[30];
- char name[30];
- char ot[30];
- date birth;
- char edu;
- char marst;
- int child;
- char job;
- place adress;
- };
- void show(ifstream&f1)
- {
- list a;
- while (f1.peek() != EOF)
- {
- f1.read((char*)&a, sizeof(list));
- cout << a.fam <<' '<< a.name << ' ' << a.ot << ' ' << a.birth.day << ' ' << a.birth.mon << ' ' << a.birth.year<< ' ' << a.edu << ' ' << a.marst << ' '<<a.child<<' ' << a.job << ' ' << a.adress.city << ' ' << a.adress.street << ' ' << a.adress.house << ' ' << a.adress.flat << ' ' << a.adress.nomber<<endl;
- }
- }
- int* creat_array(int n)
- {
- int *a = new int[n];
- for (int i = 0; i < n; i++)
- a[i] = 0;
- return a;
- }
- void MAX(ifstream&in1, int*max, int n)
- {
- list a;
- char b[9];
- while (in1.peek() != EOF)
- {
- in1 >> a.fam >> a.name >> a.ot >> b >> a.edu >> a.marst >> a.child >> a.job >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.flat >> a.adress.nomber;
- if (a.job == 'A')
- {
- if (max[0] < a.child)
- max[0] = a.child;
- }
- else
- {
- if (a.job == 'B')
- {
- if (max[1] < a.child)
- max[1] = a.child;
- }
- else
- {
- if (a.job == 'C')
- {
- if (max[2] < a.child)
- max[2] = a.child;
- }
- else
- {
- if (a.job == 'D')
- {
- if (max[3] < a.child)
- max[3] = a.child;
- }
- else
- {
- if (a.job == 'E')
- {
- if (max[4] < a.child)
- max[4] = a.child;
- }
- else
- {
- if (a.job == 'F')
- if (max[5] < a.child)
- max[5] = a.child;
- }
- }
- }
- }
- }
- }
- in1.close();
- }
- void writebin(ifstream&in1,ofstream&outbin, int *max,int n)
- {
- list a;
- char b[9];
- while (in1.peek() != EOF)
- {
- in1 >> a.fam >> a.name >> a.ot >> b >> a.edu >> a.marst >> a.child >> a.job >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.flat >> a.adress.nomber;
- a.birth.day[0] = b[0];
- a.birth.day[1] = b[1];
- a.birth.day[2] = '\0';
- a.birth.mon[0] = b[2];
- a.birth.mon[1] = b[3];
- a.birth.mon[2] = '\0';
- a.birth.year[0] = b[4];
- a.birth.year[1] = b[5];
- a.birth.year[2] = b[6];
- a.birth.year[3] = b[7];
- a.birth.year[4] = '\0';
- if (a.job == 'A'&&max[0] == a.child)
- outbin.write((char*)&a, sizeof(list));
- else
- {
- if (a.job == 'B'&&max[1] == a.child)
- outbin.write((char*)&a, sizeof(list));
- else
- {
- if (a.job == 'C'&&max[2] == a.child)
- outbin.write((char*)&a, sizeof(list));
- else
- {
- if (a.job == 'D'&&max[3] == a.child)
- outbin.write((char*)&a, sizeof(list));
- else
- {
- if (a.job == 'E'&&max[4] == a.child)
- outbin.write((char*)&a, sizeof(list));
- else
- {
- if (a.job == 'F'&&max[5] == a.child)
- outbin.write((char*)&a, sizeof(list));
- }
- }
- }
- }
- }
- }
- in1.close();
- outbin.close();
- }
- void count( ifstream&inbin, int *k, int n)
- {
- list a;
- while (inbin.peek() != EOF)
- {
- inbin.read((char*)&a, sizeof(list));
- if (a.job == 'A')
- k[0]++;
- else
- {
- if (a.job == 'B')
- k[1]++;
- else
- {
- if (a.job == 'C')
- k[2]++;
- else
- {
- if (a.job == 'D')
- k[3]++;
- else
- {
- if (a.job == 'E')
- k[4]++;
- else
- {
- if (a.job == 'F')
- k[5]++;
- }
- }
- }
- }
- }
- }
- inbin.close();
- }
- void show_tabl(int* k, int n)
- {
- int Max = 0;
- for (int i = 0; i < 6; i++)
- if (Max < k[i])
- Max = k[i];
- double perc;
- for (int i = 0; i < 6; i++)
- {
- switch (i)
- {
- case 0: cout << 'A' << ' ';
- break;
- case 1: cout << 'B' << ' ';
- break;
- case 2: cout << 'C' << ' ';
- break;
- case 3: cout << 'D' << ' ';
- break;
- case 4: cout << 'E' << ' ';
- break;
- case 5: cout << 'F' << ' ';
- break;
- }
- perc = 10.0*k[i] / Max;
- perc = round(perc);
- for (int i = 0; i < perc; i++)
- cout << '*' << ' ';
- cout << endl;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- ifstream in1("Text.txt");
- ofstream outbin("Abit.bin", ios::binary);
- list a;
- char b[9];
- int n = 6;
- int *max = creat_array(n);
- MAX(in1, max, n);
- in1.open("Text.txt");
- writebin(in1, outbin, max, n);
- int *k = creat_array(n);
- ifstream inbin("Abit.bin", ios::binary);
- count(inbin, k, n);
- show_tabl(k, n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment