include iostream include string include fstream using namespace std st

  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#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;
}