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

c++ 2 курс / 3 вариант 9

.txt
Скачиваний:
14
Добавлен:
12.02.2015
Размер:
3.77 Кб
Скачать
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct address { // описание структуры адрес

string oblast;
string city;
string street;
int house;
int flat;
int payment;
};

struct person {
	
address addr;
string name;
string lastname;
string surname;
};

void bubbleSortName(person* list, int n) {

person temp;
for (int j = 0; j < n - 1; j++) {
		
int f = 0;
int min = j;		
for(int i = j; i < (n - j - 1); i++) {
			
if (list[i].name.compare(list[i + 1].name) >= 0) {
temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
f = 1;
}
			
if (list[i].name.compare(list[min].name) < 0)
min = i;
}
if (f == 0)
break;
if (min != j) {
			
temp = list[j];
list[j] = list[min];
list[min] = temp;
}
}
}

void bubbleSortSurname(person* list, int n) {

person temp;
for (int j = 0; j < n - 1; j++) {
		
int f = 0;
int min = j;		
for(int i = j; i < (n - j - 1); i++) {
		
if (list[i].surname.compare(list[i + 1].surname) >= 0) {
temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
f = 1;
}
			
if (list[i].surname.compare(list[min].surname) < 0)
min = i;
}
if (f == 0)
break;
if (min != j) {
			
temp = list[j];
list[j] = list[min];
list[min] = temp;
}
}
}

void bubbleSortLastname(person* list, int n) {

person temp;
for (int j = 0; j < n - 1; j++) {
		
int f = 0;
int min = j;		
for(int i = j; i < (n - j - 1); i++) {
			
if (list[i].lastname.compare(list[i + 1].lastname) >= 0) {
temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
f = 1;
}
			
if (list[i].lastname.compare(list[min].lastname) < 0)
min = i;
}
if (f == 0)
break;
if (min != j) {
			
temp = list[j];
list[j] = list[min];
list[min] = temp;
}
}
}


int main() {

setlocale(LC_ALL, ""); // установка русскоязычного вывода в консоль
int count = 0; // количество пациентов
cout<<"Введите количество лиц: ";
cin>>count; // ввод количества пациентов
person* persons = new person[count]; // объявление динамического массива
	
	
cout<<"\nВведите личные данные"<<endl;
for (int i = 0; i < count; i++) { // ввод личных данных
		
cout<<"Введите фамилию"<<endl;
cin>>persons[i].surname;
cout<<"Введите имя"<<endl;
cin>>persons[i].name;
cout<<"Введите отчество"<<endl;
cin>>persons[i].lastname;
cout<<"Введите информацию о адресе лица"<<endl;
cout<<"Область"<<endl;
cin>>persons[i].addr.oblast;
cout<<"Город"<<endl;
cin>>persons[i].addr.city;
cout<<"Улица"<<endl;
cin>>persons[i].addr.street;
cout<<"Дом"<<endl;
cin>>persons[i].addr.house;
cout<<"Квартира"<<endl;
cin>>persons[i].addr.flat;
cout<<"Номер счета"<<endl;
cin>>persons[i].addr.payment;
}
	
int order = 0; // переменная для порядка сортировки
cout<<"Выберите порядок сортировки: 1 - по имени, 2 - по фамилии, 3 - по отчеству"<<endl;
cin>>order;
switch (order) {
	
case 1: 
bubbleSortName(persons, count); 
break;
case 2: 
bubbleSortSurname(persons, count); 
break;
case 3: 
bubbleSortLastname(persons, count); 
break;
default: 
cout<<"Неправильное значение"<<endl; 
break;
}
	
if (order != 1 || order != 2 || order != 3) { // вывод
		
cout<<"Рещультат: "<<endl;
for (int i = 0; i < count; i++) {
			
cout<<"Фамилия: "<<persons[i].surname<<endl;
cout<<"Имя: "<<persons[i].name<<endl;
cout<<"Отчество: "<<persons[i].lastname<<endl;
cout<<"Информация об адресе лица: "<<endl<<endl;
cout<<"Область: "<<persons[i].addr.oblast<<endl;
cout<<"Город: "<<persons[i].addr.city<<endl;
cout<<"Улица: "<<persons[i].addr.street<<endl;
cout<<"Дом: "<<persons[i].addr.house<<endl;
cout<<"Квартира: "<<persons[i].addr.flat<<endl;
cout<<"Номер счета: "<<persons[i].addr.payment<<endl;
cout<<endl;
}
}
	
cout<<endl;
system("pause");
return 0;
}
Соседние файлы в папке c++ 2 курс