#include "iostream"
#include "fstream"
#include "string"
#include "vector"
using namespace std;
class List
{
public:
List()
{
this->number = int();
this->name = string();
this->adress = string();
}
List(int num, string name, string adr)
{
this->number = num;
this->name = name;
this->adress = adr;
}
int GetNumber()
{
return number;
}
string GetName()
{
return name;
}
string GetAdress()
{
return adress;
}
void setNumber(int num)
{
this->number = num;
}
void setName(string name)
{
this->name = name;
}
void setAdress(string adr)
{
this->adress = adr;
}
private:
int number;
string name;
string adress;
};
void Find(vector<List> vect, int num)
{
for (auto elem : vect)
{
if (elem.GetNumber() == num)
{
cout << "Person's " << elem.GetNumber() << " name is " << elem.GetName() << " and adress is " << elem.GetAdress() << endl;
}
}
}
vector<List> GetData()
{
vector<List> Data;
ifstream fin("List.txt");
List obj;
int number;
while (fin >> number)
{
string name, adress;
fin >> name;
fin >> adress;
obj.setName(name);
obj.setAdress(adress);
obj.setNumber(number);
Data.push_back(obj);
}
fin.close();
return Data;
}
int main()
{
int choise = 0;
do
{
cout << " 1. Add new." << endl;
cout << " 2. Find." << endl;
cout << " 3. Exit." << endl;
cin >> choise;
switch (choise)
{
case 1:
{
vector<List> Data = GetData();
int number;
string name, adress;
cout << "Enter a number ";
cin >> number;
cout << "Enter a name ";
cin >> name;
cout << "Enter an adress ";
cin >> adress;
List obj(number, name, adress);
Data.push_back(obj);
ofstream fout("List.txt");
for (auto elem : Data)
{
fout << elem.GetNumber() << endl;
fout << elem.GetName() << endl;
fout << elem.GetAdress() << endl;
}
fout.close();
break;
}
case 2:
{
vector<List> Data = GetData();
int number;
cout << "Enter a number ";
cin >> number;
Find(Data, number);
break;
}
case 3:
{
break;
}
default:
{
cout << endl;
break;
}
}
} while (choise != 3);
system("pause");
exit (0);
}
Comments
Leave a comment