#include <iostream>
#include<conio.h>
#include<string>
#include<algorithm>
#include<list>
#include<iterator>
using namespace std;
string ppole1;
double ppole2;
string ppole3;
int ppole4;
struct vklad
{
string name;
double sum;
string type;
int stavka;
};
void print(list<vklad> bank)
{
cout << endl;
list<vklad> :: iterator acc;
for (acc = bank.begin(); acc != bank.end(); ++acc)
{
cout << (*acc).name << endl;
cout << (*acc).sum << endl;
cout << (*acc).type << endl;
cout << (*acc).stavka << endl;
}
}
void count_name(list<vklad> bank, string name)
{
int k = 0;
list<vklad> ::iterator acc;
for (acc = bank.begin(); acc != bank.end(); ++acc)
{
if ((*acc).name == name) k++;
}
cout << "Kol-vo vkladov na imya " << name << ":" << k;
}
void count_sum(list<vklad> bank, double sum)
{
int k = 0;
list<vklad> ::iterator acc;
for (acc = bank.begin(); acc != bank.end(); ++acc)
{
if ((*acc).sum == sum) k++;
}
cout << "Kol-vo vkladov na summu " << sum << ":" << k;
}
void count_type(list<vklad> bank, string type)
{
int k = 0;
list<vklad> ::iterator acc;
for (acc = bank.begin(); acc != bank.end(); ++acc)
{
if ((*acc).type == type) k++;
}
cout << "Kol-vo vkladov s tipom valuty " << type << ":" << k;
}
void count_stavka(list<vklad> bank, int stavka)
{
int k = 0;
list<vklad> ::iterator acc;
for (acc = bank.begin(); acc != bank.end(); ++acc)
{
if ((*acc).stavka == stavka) k++;
}
cout << "Kol-vo vkladov so stavkoy " << stavka << ":" << k;
}
bool defname(const vklad& first)
{
return first.name == ppole1;
}
bool defsum(vklad first)
{
return first.sum == ppole2;
}
bool deftype(vklad first)
{
return first.type == ppole3;
}
bool defstavka(vklad first)
{
return first.stavka == ppole4;
}
bool compare_name(const vklad& first, const vklad& second)
{
return first.name < second.name;
}
bool compare_sum(const vklad& first, const vklad& second)
{
return first.sum < second.sum;
}
bool compare_type(const vklad& first, const vklad& second)
{
return first.type < second.type;
}
bool compare_stavka(const vklad& first, const vklad& second)
{
return first.stavka < second.stavka;
}
int main()
{
list<vklad> accounts;
vklad account;
char Ch;
do
{
cout << "Name:";
cin >> account.name;
cout << "Summa vklada:";
cin >> account.sum;
cout << "Valuta type:";
cin >> account.type;
cout << "Stavka:";
cin >> account.stavka;
cin.ignore();
accounts.push_back(account);
cout << "For continue press Y or y else any key! ";
Ch = _getche();
cout << endl;
} while (Ch == 'Y' || Ch == 'y');
cout << endl << "List before sorting:" << endl;
print(accounts);
int a;
cout << "choose sort: \n1.name \n2.sum \n3.type \n4.stavka" << endl;
cin >> a;
switch (a)
{
case 1:accounts.sort(compare_name); break;
case 2:accounts.sort(compare_sum); break;
case 3:accounts.sort(compare_type); break;
case 4:accounts.sort(compare_stavka); break;
}
cout << endl << "List after sorting" << endl;
print(accounts);
cout << "choose pole: \n1.name \n2.sum \n3.type \n4.stavka" << endl;
cin >> a;
cout << "vvedite znchenie polya:" << endl;
string pole1;
double pole2;
string pole3;
int pole4;
switch (a)
{
case 1:cin >> pole1; count_name(accounts, pole1); break;
case 2:cin >> pole2; count_sum(accounts, pole2); break;
case 3:cin >> pole3; count_type(accounts, pole3); break;
case 4:cin >> pole4; count_stavka(accounts, pole4); break;
}
cout << endl <<"choose pole dlya novogo spiska: \n1.name \n2.sum \n3.type \n4.stavka" << endl;
cin >> a;
cout << "vvedite znchenie polya:" << endl;
if (a = 1)
{
cin >> ppole1;
list<vklad> defaccounts(accounts.size());
int k = count_if(accounts.begin(), accounts.end(), defname);
auto end = copy_if(accounts.begin(), accounts.end(), defaccounts.begin(), defname);
auto pos = remove_if(accounts.begin(), accounts.end(), defname);
accounts.erase(pos, accounts.end());
defaccounts.resize(distance(defaccounts.begin(), end));
cout << endl << "Noviy spisok vybrannoe pole kotorogo prinimaet zadannoe znachenie:" ;
print(defaccounts);
cout << endl << "Ishodniy spisok:";
print(accounts);
}
if (a = 2)
{
cin >> ppole2;
list<vklad> defaccounts(accounts.size());
int k = count_if(accounts.begin(), accounts.end(), defsum);
auto end = copy_if(accounts.begin(), accounts.end(), defaccounts.begin(), defsum);
auto pos = remove_if(accounts.begin(), accounts.end(), defsum);
accounts.erase(pos, accounts.end());
defaccounts.resize(distance(defaccounts.begin(), end));
cout << endl << "Noviy spisok vybrannoe pole kotorogo prinimaet zadannoe znachenie:";
print(defaccounts);
cout << endl << "Ishodniy spisok:";
print(accounts);
}
if (a = 3)
{
cin >> ppole3;
list<vklad> defaccounts(accounts.size());
int k = count_if(accounts.begin(), accounts.end(), deftype);
auto end = copy_if(accounts.begin(), accounts.end(), defaccounts.begin(), deftype);
auto pos = remove_if(accounts.begin(), accounts.end(), deftype);
accounts.erase(pos, accounts.end());
defaccounts.resize(distance(defaccounts.begin(), end));
cout << endl << "Noviy spisok vybrannoe pole kotorogo prinimaet zadannoe znachenie:";
print(defaccounts);
cout << endl << "Ishodniy spisok:";
print(accounts);
}
if (a = 4)
{
cin >> ppole4;
list<vklad> defaccounts(accounts.size());
int k = count_if(accounts.begin(), accounts.end(), defstavka);
auto end = copy_if(accounts.begin(), accounts.end(), defaccounts.begin(), defstavka);
auto pos = remove_if(accounts.begin(), accounts.end(), defstavka);
accounts.erase(pos, accounts.end());
defaccounts.resize(distance(defaccounts.begin(), end));
cout << endl << "Noviy spisok vybrannoe pole kotorogo prinimaet zadannoe znachenie:";
print(defaccounts);
cout << endl << "Ishodniy spisok:";
print(accounts);
}
}