#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
struct national//Нац. состав
{
char name[64];//национальность
unsigned int number;//численность
float percent;//процент от всего населения
};
struct population//население
{
unsigned int number;//численность
char lang[128];//гос. язык
unsigned int num_of_nationals;//кол-во национальностей
national **nationals;//национальный состав
};
struct geograph//географическое положение
{
char part_of_the_world[32];//часть света
char continent[32];//материк
unsigned int num_of_oceans;//кол-во океанов
char **oceans;//океаны
unsigned int num_of_seas;//кол-во морей
char **seas;//моря
unsigned int num_of_mountains;//кол-во горных цепей
char **mountains;//горные цепи
};
struct country//страна
{
char name[128];//название
unsigned int square;//площадь
population *popul;//население
geograph *place;//географическое положение
} **countries;
unsigned int num_of_countr;//кол-во стран
bool read_file(char *filename)//чтение данных о странах из файла
{
ifstream file;//объект файл
file.open(filename);//открываем файл с именем filename
if (file.fail()) return false;//не смогли открыть - возвращаем false
file>>num_of_countr;//считываем кол-во стран в файле
countries = new country*[num_of_countr];//создаём массив из заданного кол-ва стран
for (int i=0; i<num_of_countr; i++)//цикл считывания данных о странах
{
countries[i]=new country;
file>>countries[i]->name;
file>>countries[i]->square;
countries[i]->place=new geograph;
file>>countries[i]->place->continent;
file>>countries[i]->place->part_of_the_world;
file>>countries[i]->place->num_of_oceans;
countries[i]->place->oceans=new char*[countries[i]->place->num_of_oceans];
for (int j=0; j<countries[i]->place->num_of_oceans; j++)
{
countries[i]->place->oceans[j]=new char[32];
file>>countries[i]->place->oceans[j];
}
file>>countries[i]->place->num_of_seas;
countries[i]->place->seas=new char*[countries[i]->place->num_of_seas];
for (int j=0; j<countries[i]->place->num_of_seas; j++)
{
countries[i]->place->seas[j]=new char[32];
file>>countries[i]->place->seas[j];
}
file>>countries[i]->place->num_of_mountains;
countries[i]->place->mountains=new char*[countries[i]->place->num_of_mountains];
for (int j=0; j<countries[i]->place->num_of_mountains; j++)
{
countries[i]->place->mountains[j]=new char[64];
file>>countries[i]->place->mountains[j];
}
countries[i]->popul=new population;
file>>countries[i]->popul->number;
file>>countries[i]->popul->lang;
file>>countries[i]->popul->num_of_nationals;
countries[i]->popul->nationals=new national*[countries[i]->popul->num_of_nationals];
for (int j=0; j<countries[i]->popul->num_of_nationals; j++)
{
countries[i]->popul->nationals[j]=new national;
file>>countries[i]->popul->nationals[j]->name;
file>>countries[i]->popul->nationals[j]->number;
file>>countries[i]->popul->nationals[j]->percent;
}
}
return true;
}
int main()
{
cout<<"Enter filename with countries: ";
char temp[256];
cin>>temp;
if (!read_file(temp))
{
cout<<"ERROR!"<<endl;
return -1;
}
else
{
cout<<"Largest number of seas: ";
int max=0;
int t;
for (int i=0; i<num_of_countr; i++)
{
if (countries[i]->place->num_of_seas>max)
{
max=countries[i]->place->num_of_seas;
t=i;
}
}
cout<<countries[t]->name<<endl;
cout<<"Enter name of mountain: ";
cin>>temp;
cout<<"Countries:"<<endl;
for (int i=0; i<num_of_countr; i++)
{
int j=countries[i]->place->num_of_mountains;
for (int k=0; k<j; k++)
if (!strcmp(temp, countries[i]->place->mountains[k])) cout<<countries[i]->name<<endl;
}
cout<<"Enter number of nationals: ";
cin>>t;
cout<<"Countries:"<<endl;
for (int i=0; i<num_of_countr; i++)
{
if (countries[i]->popul->num_of_nationals>t) cout<<countries[i]->name<<endl;
}
cout<<"Enter name of country: ";
cin>>temp;
cout<<"Mountains:"<<endl;
for (int i=0; i<num_of_countr; i++)
{
if (!strcmp(temp, countries[i]->name))
{
int j=countries[i]->place->num_of_mountains;
for (int k=0; k<j; k++) cout<<countries[i]->place->mountains[k]<<endl;
}
}
cout<<"Enter number of population: ";
cin>>t;
cout<<"Countries:"<<endl;
for (int i=0; i<num_of_countr; i++)
{
if (countries[i]->popul->number<t) cout<<countries[i]->name<<endl;
}
}
return 0;
}