include iostream include vector include algorithm include string inclu

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <fstream>
using namespace std;
/*class Date{
public:
int d;
int m;
int y;
};*/
class Record;
typedef vector<Record> Notes;
vector<Record>::iterator index;
class Record{
string Name;
int TNumber, d, m, y;
//Date BirthDay;
public:
void InputRecord(){
string name;
int len;
cout<<"Input Name & Age"<<endl;
cin>>name;
len=name.length();
for(int i=0; i<len; i++)
if(isdigit(name[i])) throw 1;//проверка на цифру
Name=name;
cin>>TNumber>>d>>m>>y;
}
void ShowRecord() const { cout<<Name<<" "<<TNumber<<" "<<d<<m<<y<<endl;}
int GetNumber()const {return TNumber;}
string GetName()const {return Name;}
int GetDateD() const {return d;}
int GetDateM() const {return m;}
int GetDateY() const {return y;}
friend ifstream& operator >> (ifstream& s, Record& obj)
{ s>>obj.Name>>obj.TNumber>>obj.d>>obj.m>>obj.y; return s;}
friend ofstream& operator << (ofstream& s, Record& obj)
{ s<<obj.Name<<endl<<obj.TNumber<<endl<<obj.d<<"."<<obj.m<<"."<<obj.y<<endl; return s;}
bool operator<( Record b)
{
if(Name<b.Name) return true;
return false;
}
};
class Notebook{
Notes note;
Record rec;
public:
void InputNotebook()
{
char flag=true;
while (flag)
{
try
{ rec.InputRecord();
note.push_back(rec);
flag=false;
}//try
catch(int) { cout<<"Once more Name"<<endl; }
}
}
void ShowBase()
{ int n=note.size();
for (int i=0; i<n; i++)
note[i].ShowRecord();
}
//Перегрузка индексации для MyBase
Record& operator [](int i)
{return note[i]; }
//Очистка контейнера
void ClearBase()
{note.clear(); }
//Вычисление среднего значения элементов age в контейнере
/*int AverageAge()
{
int n=bs.size();
int buf=0;
for(index=bs.begin(); index!=bs.end(); index++)
buf=buf + (*index).GetAge();
buf=buf/n;
return buf;
}*/
//Сортировка
void SortBase()
{ std::sort(note.begin(),note.end());}
//Запись в файл содержимого контейнера
void InFile()
{//Здесь включить try на открытие файла
fstream out("C:\\computer\\das.txt",ios::out);
int n=note.size();
for (int i=0; i<n; i++){
out<<note[i].GetName<<" "<<note[i].GetNumber()<<" "<<note[i].GetDateD()<<"."<<note[i].GetDateM()<<"."<<note[i].GetDateY();
cout<<note[i].GetName<<" "<<note[i].GetNumber()<<" "<<note[i].GetDateD()<<"."<<note[i].GetDateM()<<"."<<note[i].GetDateY();
}
}
};
int main()
{
Notebook mb;
mb.InputNotebook();
mb.ShowBase();
mb.SortBase();
mb.InFile();
mb.ClearBase();
mb.ShowBase();
return 0;
}