Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "string.h"
- #include "iostream"
- #include "stdio.h"
- #include "stdlib.h"
- #include "math.h"
- #include "ctime"
- #include "cmath"
- #include "conio.h"
- #include "iomanip"
- using namespace std;
- struct struc
- {
- char* Fam;
- char* Im;
- char* Ot;
- int day;
- int month;
- int year;
- };
- int Kol,i,j; // Kol - количество людей i - счетчик для массива j - счетчик для сортировки массива
- int const k=100; // Максимальное количество символов в имени\фамилии\отчестве
- struc *FamImOtDatPoj; // Массив структур
- void Input(struc **FamImOtDatPoj); // Ввод несортированного массива структур
- void Output(struc **FamImOtDatPoj); // Вывод отсортированного массива структур
- struc *Sort(struc **FamImOtDatPoj); // Сортировка массива структур по дате
- struc *Sort2(struc **FamImOtDatPoj); // Сортировка массива структур по фамилии
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "rus");
- Input(&FamImOtDatPoj);
- (*FamImOtDatPoj)=*Sort(&FamImOtDatPoj);
- printf("\n\n\n");
- Output(&FamImOtDatPoj);
- printf("\n\n\n");
- (*FamImOtDatPoj)=*Sort2(&FamImOtDatPoj);
- Output(&FamImOtDatPoj);
- delete [] FamImOtDatPoj;
- system("pause");
- return 0;
- }
- void Input (struc **FamImOtDatPoj)
- {
- cout << "Введите число людей\n" ;
- cin >> Kol ;
- *FamImOtDatPoj=new struc[Kol];
- for (i=0;i<Kol;i++) {
- (*FamImOtDatPoj)[i].Im=new char[k];
- (*FamImOtDatPoj)[i].Fam=new char[k];
- (*FamImOtDatPoj)[i].Ot=new char[k];
- }
- for (i=0;i<Kol;i++) {
- cout << "Введите имя,фамилию,отчество и дату рождения(день-месяц-год отдельно) [" << i+1 << "-го]:\n" ;
- cin >> (*FamImOtDatPoj)[i].Im >> (*FamImOtDatPoj)[i].Fam >> (*FamImOtDatPoj)[i].Ot >> (*FamImOtDatPoj)[i].day >> (*FamImOtDatPoj)[i].month >> (*FamImOtDatPoj)[i].year ;
- }
- }
- void Output(struc **FamImOtDatPoj)
- {
- for (i=00;i<Kol;i++)
- cout << (*FamImOtDatPoj)[i].Im << " " << (*FamImOtDatPoj)[i].Fam << " " << (*FamImOtDatPoj)[i].Ot << " "
- << (*FamImOtDatPoj)[i].day << " " << (*FamImOtDatPoj)[i].month << " " << (*FamImOtDatPoj)[i].year << "\n" ;
- }
- struc *Sort(struc **FamImOtDatPoj)
- {
- for (int i = 0; i<=Kol; i++) {
- for (j=i;((((*FamImOtDatPoj)[j - 1].year * 365 + (*FamImOtDatPoj)[j - 1].month * 30 + (*FamImOtDatPoj)[j - 1].day) <
- ((*FamImOtDatPoj)[j].year * 365 + (*FamImOtDatPoj)[j].month * 30 + (*FamImOtDatPoj)[j].day)) && (j > 0));j--);
- {
- swap((*FamImOtDatPoj)[j], (*FamImOtDatPoj)[j-1]);
- }
- }
- return (*FamImOtDatPoj);
- }
- struc *Sort2(struc **FamImOtDatPoj)
- {
- for (int i = 0; i<=Kol; i++)
- {
- for (j=i;((((*FamImOtDatPoj)[j - 1].Fam) < ((*FamImOtDatPoj)[j].Fam)) && (j >0 ));j--);
- {
- swap((*FamImOtDatPoj)[j], (*FamImOtDatPoj)[j-1]);
- }
- }
- return (*FamImOtDatPoj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement