Цитата:
#include <iostream>
#include <fstream>
enum ChosenOperation { ADD = 1, SHOW, DELETE, EXIT };
enum SearchingCriteria { NAME = 1, ADDRESS, PHONE, AGE };
struct Human
{
std::string full_name; // фамилия имя отчество
std::string address; // домашний адрес
std::string phone; // телефон
unsigned int age; // возраст
};
void add_new_entry_to_file( std::string filename )
{
std::cout << "\n\n\tAdding new student to database.\n\n";
std::cout << "Enter number of entries: ";
unsigned int number_of_entries;
std::cin >> number_of_entries;
std::cout << "\n\n\tEnter all nessesary data of each entry.\n\n";
struct Human* human = new struct Human[number_of_entries];
for ( unsigned int i = 0, nth; i < number_of_entries; ++i )
{
nth = i + 1;
while ( std::cin.get() != '\n' );
std::cout
<< "Enter full name of "
<< nth
<< " student: ";
std::getline( std::cin, human[i].full_name );
std::cout
<< "Enter address of "
<< nth
<< " student: ";
std::getline( std::cin, human[i].address );
std::cout
<< "Enter phone number of "
<< nth
<< " student: ";
std::getline( std::cin, human[i].phone );
std::cout
<< "Enter age of "
<< nth
<< " student: ";
std::cin >> human[i].age;
std::cout << "\n";
}
std: fstream fout( filename.c_str() );
for ( unsigned int i = 0; i < number_of_entries; ++i )
{
fout
<< human[i].full_name
<< "|"
<< human[i].address
<< "|"
<< human[i].phone
<< "|"
<< human[i].age
<< "\n";
}
fout.close();
delete [] human;
}
void show_data( std::string filename )
{
// TODO
}
void delete_data_in_file( std::string filename, int searching_criteria )
{
// TODO
}
int main()
{
int key = 0;
while ( key != ChosenOperation::EXIT )
{
std::cout
<< "MENU:\n\n"
<< "\t1 - ADD\n"
<< "\t2 - SHOW\n"
<< "\t3 - Delete\n"
<< "\t4 - EXIT(Esc)\n\n"
<< "Press any key: ";
std::cin >> key;
switch ( key )
{
case ChosenOperation::ADD :
add_new_entry_to_file( "Person.txt" );
case ChosenOperation::SHOW :
show_data( "Person.txt" );
case ChosenOperation::Delete:
delete_data_in_file( "Person.txt", SearchingCriteria::AGE );
case ChosenOperation::EXIT :
key = ChosenOperation::EXIT;
}
}
return 0;
}
|
Вопрос состоит в том, как можно удалить запись с указанным возрастом?
Не совсем знаю ,как реализовать, может быть кто-нибудь поможет?!!!