Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

16_II / Семестровая работа(бинарные)

.doc
Скачиваний:
22
Добавлен:
10.02.2015
Размер:
36.86 Кб
Скачать

Семестровая работа: Бинарные файлы.

Задание:

Дан текстовый файл, содержащий следующую информацию о рабочих: -ФИО -Год рождения -Пол -Количество детей -Зарплата -Кредиты -Налог **Создать файл записей и добавить функции: **На основе файлов записи создать два текстовый файла, содержащих информацию о мужчинах имеющих более двух детей и о женщинах имеющих 1 ребенка, и при этом в колонке зарплата выводилось значение зарплата-налог-кредит=зарплата, при этом для мужчин налог уменьшить в 4раза, а кредит уменьшить на 20%; для женщин с одним ребенком налог уменьшить 2 раза, а кредит на 10%.

Входной текст.

Абунагимова        1976 w 2 5000 500 650 Ашрапова           1981 w 1 6500 1000 845 Багаутдинова       1969 w 1 9000 5000 1170 Бадыков            1972 m 2 10000 2000 1300 Губайдуллина       1966 w 0 8000 0 1040 Галиуллин          1959 m 3 19000 4000 2470 Гильмутдинова      1977 w 2 12000 3000 1560 Габдрахманов       1964 m 4 9000 500 1170 Гайнетдинов        1981 m 1 8000 1000 1040 Ильясова           1979 w 1 12000 0 1560 Исхаков            1972 m 1 11000 4000 1430 Набиуллина         1966 w 1 9500 600 1235 Нагимуллина        1964 w 0 3500 2000 455 Нурлыгараев        1976 m 2 5700 0 741 Каюмов             1983 m 5 13000 2000 1690 Романова           1962 w 3 12000 6000 1560 Рашитова           1955 w 1 9000 200 1170 Сабитов            1978 m 2 8500 600 1105 Ханнанов           1961 m 1 16000 7000 2080 Шагиева            1963 w 5 8500 1000 1105

Создание бинарных файлов. #include <iostream> #include <fstream> #include <stdlib.h> using namespace std; void main(){ struct doxod {     char FIO[20];     int GODROZH;         char POL;     int KOLDET;     double ZARPLAT;     double KREDIT;     double NALOG; }; doxod a; ifstream myin("baza dannyh.txt"); ofstream manout("doxod_man.bin", ios::binary); ofstream womanout("doxod_woman.bin", ios::binary); if(!myin) {     cout<<"Can't open file";     exit(1); } while(myin.peek()!=EOF) { myin>>a.FIO>>a.GODROZH>>a.POL>>a.KOLDET>>a.ZARPLAT>>a.KREDIT>>a.NALOG; if(a.POL=='m'&&a.KOLDET>=2){ a.NALOG=a.NALOG/4;     a.KREDIT=a.KREDIT*8/10;     a.ZARPLAT=a.ZARPLAT-a.NALOG-a.KREDIT;     manout.write((char*)&a,sizeof(struct doxod));} if(a.POL=='w'&&a.KOLDET==1){ a.NALOG=a.NALOG/2;     a.KREDIT=a.KREDIT*9/10;     a.ZARPLAT=a.ZARPLAT-a.NALOG-a.KREDIT;     womanout.write((char*)&a,sizeof(struct doxod));}}}

Создание текстовых файлов. #include <iostream> #include <fstream> #include <stdlib.h> using namespace std; void main(){     struct doxod {     char FIO[20];     int GODROZH;         char POL;     int KOLDET;     double ZARPLAT;     double KREDIT;     double NALOG; }; doxod a; ifstream manout("doxod_man.bin",ios::binary); ifstream womanout("doxod_woman.bin",ios::binary); ofstream manout1("doxod_mam.txt"); ofstream womanout1("doxod_woman.txt"); manout1<<"Мужчины, у которых 2 или более детей.\n"; manout1<<"\n"; womanout1<<"Женщины, у которых 1 ребенок.\n"; womanout1<<"\n"; if(!manout||!womanout) {     cout<<"Can't open files \n";     system ("pause");     exit(1); } while(manout.peek()!=EOF){ manout.read((char*)&a, sizeof(struct doxod));     manout1<<'|';     manout1.width(12);     manout1.setf(ios::left);     manout1<<a.FIO;     manout1<<'|';     manout1.width(4);     manout1.unsetf(ios::left);     manout1<<a.GODROZH;     manout1<<'|';     manout1<<' ';     manout1<<a.POL;     manout1<<'|';     manout1<<' ';     manout1.width(1);     manout1.setf(ios::left);     manout1<<a.KOLDET;     manout1<<'|';     manout1.width(8);     manout1<<a.ZARPLAT;     manout1<<'|';     manout1.unsetf(ios::left);     manout1<<'\n';       break;} while(womanout.peek()!=EOF){ womanout.read((char*)&a, sizeof(struct doxod));     womanout1<<'|';     womanout1.width(12);     womanout1.setf(ios::left);     womanout1<<a.FIO;     womanout1<<'|';     womanout1.width(4);     womanout1.unsetf(ios::left);     womanout1<<a.GODROZH;     womanout1<<'|';     womanout1<<' ';     womanout1<<a.POL;     womanout1<<'|';     womanout1<<' ';     womanout1.width(1);     womanout1.setf(ios::left);     womanout1<<a.KOLDET;     womanout1<<'|';     womanout1.width(8);     womanout1<<a.ZARPLAT;     womanout1<<'|';     womanout1.unsetf(ios::left);     womanout1<<'\n';        break;} manout1.width(33); manout1.fill('_'); manout1<<'_'; manout1<<'\n'; while(manout.peek()!=EOF){ manout.read((char*)&a, sizeof(struct doxod));     manout1.fill(' ');     manout1<<'|';     manout1.width(12);     manout1.setf(ios::left);     manout1<<a.FIO;     manout1<<'|';     manout1.width(4);     manout1.unsetf(ios::left);     manout1<<a.GODROZH;     manout1<<'|';     manout1<<' ';     manout1.width(1);     manout1<<a.POL;     manout1<<'|';     manout1<<' ';     manout1.width(1);     manout1.setf(ios::left);     manout1<<a.KOLDET;     manout1<<'|';     manout1.width(8);     manout1<<a.ZARPLAT;     manout1<<'|';     manout1.unsetf(ios::left);     manout1<<'\n';     manout1.width(33);     manout1.fill('_');     manout1<<'_';     manout1<<'\n';} womanout1.width(33); womanout1.fill('_'); womanout1<<'_'; womanout1<<'\n'; while(womanout.peek()!=EOF){ womanout.read((char*)&a, sizeof(struct doxod));     womanout1.fill(' ');     womanout1<<'|';     womanout1.width(12);     womanout1.setf(ios::left);     womanout1<<a.FIO;     womanout1<<'|';     womanout1.width(4);     womanout1.unsetf(ios::left);     womanout1<<a.GODROZH;     womanout1<<'|';     womanout1<<' ';     womanout1.width(1);     womanout1<<a.POL;     womanout1<<'|';     womanout1<<' ';     womanout1.width(1);     womanout1.setf(ios::left);     womanout1<<a.KOLDET;     womanout1<<'|';     womanout1.width(8);     womanout1<<a.ZARPLAT;     womanout1<<'|';     womanout1.unsetf(ios::left);     womanout1<<'\n';     womanout1.width(33);     womanout1.fill('_');     womanout1<<'_';     womanout1<<'\n';} }

Выходные файлы. Мужчины, у которых 2 или более детей. |Бадыков     |1972| m| 2|8075    | _________________________________ |Галиуллин   |1959| m| 3|15182.5 | _________________________________ |Габдрахманов|1964| m| 4|8307.5  | _________________________________ |Нурлыгараев |1976| m| 2|5514.75 | _________________________________ |Каюмов      |1983| m| 5|10977.5 | _________________________________ |Сабитов     |1978| m| 2|7743.75 | _________________________________

Женщины, у которых 1 ребенок. |Ашрапова    |1981| w| 1|5177.5  | _________________________________ |Багаутдинова|1969| w| 1|3915    | _________________________________ |Ильясова    |1979| w| 1|11220   | _________________________________ |Набиуллина  |1966| w| 1|8342.5  | _________________________________ |Рашитова    |1955| w| 1|8235    | _________________________________