{lang: ‘ru’}

Сформировать массив на диске, содержащий сведения о сотрудниках института. Структурный тип содержит поля: фамилия работающего, название отдела, год рождения, стаж работы, должность, оклад.

Написать программу, которая выбирает необходимую информацию с диска и выводит на экран:

- список сотрудников пенсионного возраста на сегодняшний день с указанием стажа работы;

- средний стаж, работающих в отделе Х.

#include <iostream>
#include <fstream>
#include <conio.h>
#include <string.h>
#include <windows.h>

using namespace std;

struct staff
{
	char surname[100];
	char dept[100]; //отдел
	int birthDate; // год рождения
	char post[100]; // должность
	int exp; // стаж
	int salary; // оклад
};

void add_Info()
{
	staff buf;
	ofstream f("lab.dat", ios::app);
	char s[100];
	memset(&buf, 0, sizeof(staff));
	cout << "Введите информацию:"<<endl;
	cout << "tфамилия: ";
	cin.getline(s, sizeof(s));
	cin.getline(s, sizeof(s));
	strcpy(buf.surname, s);
	cout << "tотдел: ";
	cin.getline(s, sizeof(s));
	strcpy(buf.dept, s);
	cout << "tдолжность: ";
	cin.getline(s, sizeof(s));
	strcpy(buf.post, s);
	cout << "tдата рождения: ";
	cin >> buf.birthDate;
	cout<<"tстаж: ";
	cin>>buf.exp;
	cout<<"tоклад: ";
	cin>>buf.salary;

	f.write((char *)&buf, sizeof(staff));
	f.close();
}

void show_pensionary()
{
	staff buf;

	SYSTEMTIME systime;
 	GetLocalTime(&systime);

	ifstream f("lab.dat");
	while(!f.eof())
	{
		memset(&buf, 0, sizeof(staff));
		f.read((char *)&buf, sizeof(staff));
		if(((systime.wYear - buf.birthDate) > 60) && buf.birthDate != NULL)
		{
			cout << (systime.wYear - buf.birthDate) << endl;
			cout << "Фамилия: " << buf.surname << endl
			<<  "Отдел: " << buf.dept << endl
			<<  "Должность: " << buf.post << endl
			<<  "Стаж: " << buf.exp << endl << endl;
		}
	}
	f.close();
	getch();
}

void show_totalExp()
{
	staff buf;
	char dept[100];
	int totalExp = 0, count = 0;

	ifstream f("lab.dat");

	cout << "Введите название отдела: ";
	cin.getline(dept, sizeof(dept));
	cin.getline(dept, sizeof(dept));

	system("cls");
	while(!f.eof())
	{
		memset(&buf, 0, sizeof(staff));
		f.read((char *)&buf, sizeof(staff));
		if(*buf.dept == *dept)
		{
			count++;
			totalExp += buf.exp;
		}
	}
	cout << "Средний стаж в отделе " << buf.dept << ": " << totalExp / count << endl;
	f.close();
	getch();
}

void main(void)
{
	setlocale(LC_ALL, "Russian");
#define kol 4
	int choice;
	char menu[kol][100]={"1. Добавить информацию о сотруднике",
		"2. Список сотрудников пенсионного возраста",
		"3. Средний стаж, работающих в отделе Х",
		"4. Выход"};
	do
	{
		system("cls");
		for(int i = 0; i < kol; i++)
			cout << menu[ i ] << endl;
		cout << "Ваш выбор: ";
		cin >> choice;
		system("cls");
		switch(choice)
		{
		case 1:
			add_Info();
			break;
		case 2:
			show_pensionary();
			break;
		case 3:
			show_totalExp();
			break;
		default: ;
		}
	}
	while(choice != 4);
}

 


Получайте новые статьи блога прямо себе на почту