#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct PersonalRecord
{
string name;
string dob;
string phone;
bool operator<(const PersonalRecord& other)const
{
return name < other.name;
}
};
void displayRecords(const vector<PersonalRecord>& records)
{
cout << "\nPersonal Records:\n";
cout << "--------\n";
for (const auto& record : records)
{
cout << "Name: " << record.name << ", DOB: " << record.dob<< ", Phone: " << record.phone << endl;
}
cout << "------------------\n";
}
void searchRecord(const vector<PersonalRecord>& records, const string& name)
{
auto it
= find_if
(records
.begin
(), records
.end(),[&name
](const PersonalRecord
& record
) {
return record.name == name;
});
{
cout << "\nRecord Found:\n";
cout << "Name: " << it->name << ", DOB: "<< it->dob<< ", Phone: "<< it->phone<< endl;
}
else
{
cout << "\nRecord not found.\n";
}
}
int main()
{
vector<PersonalRecord> records;
int n;
cout << "Enter the number of records: ";
cin >> n;
cin.ignore();
for (int i = 0; i < n; ++i) {
PersonalRecord record;
cout << "\nEnter details for record " << i + 1 << ":\n";
cout << "Name: ";
getline(cin, record.name);
cout << "DOB (DD/MM/YYYY): ";
getline(cin, record.dob);
cout << "Phone: ";
getline(cin, record.phone);
records.push_back(record);
}
sort(records
.begin
(), records
.end()); displayRecords(records);
string searchName;
cout << "\nEnter a name to search: ";
getline(cin, searchName);
searchRecord(records, searchName);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IFBlcnNvbmFsUmVjb3JkCnsKICAgIHN0cmluZyBuYW1lOwogICAgc3RyaW5nIGRvYjsKICAgIHN0cmluZyBwaG9uZTsKCiAgICBib29sIG9wZXJhdG9yPChjb25zdCBQZXJzb25hbFJlY29yZCYgb3RoZXIpY29uc3QKICAgIHsKICAgICAgICByZXR1cm4gbmFtZSA8IG90aGVyLm5hbWU7CiAgICB9Cn07Cgp2b2l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AgaW50IG47CgogICAgY291dCA8PCAiRW50ZXIgdGhlIG51bWJlciBvZiByZWNvcmRzOiAiOwogICAgY2luID4+IG47CiAgICBjaW4uaWdub3JlKCk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIFBlcnNvbmFsUmVjb3JkIHJlY29yZDsKICAgICAgICBjb3V0IDw8ICJcbkVudGVyIGRldGFpbHMgZm9yIHJlY29yZCAiIDw8IGkgKyAxIDw8ICI6XG4iOwogICAgICAgIGNvdXQgPDwgIk5hbWU6ICI7CiAgICAgICAgZ2V0bGluZShjaW4sIHJlY29yZC5uYW1lKTsKICAgICAgICBjb3V0IDw8ICJET0IgKEREL01NL1lZWVkpOiAiOwogICAgICAgIGdldGxpbmUoY2luLCByZWNvcmQuZG9iKTsKICAgICAgICBjb3V0IDw8ICJQaG9uZTogIjsKICAgICAgICBnZXRsaW5lKGNpbiwgcmVjb3JkLnBob25lKTsKICAgICAgICByZWNvcmRzLnB1c2hfYmFjayhyZWNvcmQpOwogICAgfQogICAgc29ydChyZWNvcmRzLmJlZ2luKCksIHJlY29yZHMuZW5kKCkpOwogICAgZGlzcGxheVJlY29yZHMocmVjb3Jkcyk7CiAgICBzdHJpbmcgc2VhcmNoTmFtZTsKICAgIGNvdXQgPDwgIlxuRW50ZXIgYSBuYW1lIHRvIHNlYXJjaDogIjsKICAgIGdldGxpbmUoY2luLCBzZWFyY2hOYW1lKTsKICAgIHNlYXJjaFJlY29yZChyZWNvcmRzLCBzZWFyY2hOYW1lKTsKCiAgICByZXR1cm4gMDsKfQo=
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct PersonalRecord
{
string name;
string dob;
string phone;
bool operator<(const PersonalRecord& other)const
{
return name < other.name;
}
};
void displayRecords(const vector<PersonalRecord>& records)
{
cout << "\nPersonal Records:\n";
cout << "--------\n";
for (const auto& record : records)
{
cout << "Name: " << record.name << ", DOB: " << record.dob<< ", Phone: " << record.phone << endl;
}
cout << "------------------\n";
}
void searchRecord(const vector<PersonalRecord>& records, const string& name)
{
auto it = find_if(records.begin(), records.end(),[&name](const PersonalRecord& record)
{
return record.name == name;
});
if (it != records.end())
{
cout << "\nRecord Found:\n";
cout << "Name: " << it->name << ", DOB: "<< it->dob<< ", Phone: "<< it->phone<< endl;
}
else
{
cout << "\nRecord not found.\n";
}
}
int main()
{
vector<PersonalRecord> records;
int n;
cout << "Enter the number of records: ";
cin >> n;
cin.ignore();
for (int i = 0; i < n; ++i) {
PersonalRecord record;
cout << "\nEnter details for record " << i + 1 << ":\n";
cout << "Name: ";
getline(cin, record.name);
cout << "DOB (DD/MM/YYYY): ";
getline(cin, record.dob);
cout << "Phone: ";
getline(cin, record.phone);
records.push_back(record);
}
sort(records.begin(), records.end());
displayRecords(records);
string searchName;
cout << "\nEnter a name to search: ";
getline(cin, searchName);
searchRecord(records, searchName);
return 0;
}