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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
| #include<stdio.h>
#include<conio.h>
#include<cstdio>
#include<string>
#include<stdlib.h>
#include<iostream>
#include<fstream>
#include<new>
using namespace std;
class Abitur{
int i, j;
char name[21];
char surname[21];
char patronymic[21];
char address[21];
int estimation[3];
public:
Abitur(const char *name_,const char *surname_, const char *patronymic_, const char *address_ , const int *estimation);
virtual ~Abitur();
friend int inMoscow(Abitur *abitur[]);
friend class Abitur_;
virtual void print_(){
cout<<"Name: "<< name <<endl;
cout<<"Surname: "<< surname <<endl;
cout<<"Patronymic: "<< patronymic <<endl;
cout<<"Address: "<<address<<endl;
for(int i=0; i<3; i++)
cout << "estimation "<< i+1 <<" "<< estimation[i] <<endl;
}
};
class Abitur_: public Abitur{
char medal[7]; //Gold end Silver
int place; //1 2 end 3
public:
Abitur_(const char *name_, const char *surname_, const char *patronymic_, const char *address_ , const int *estimation_, const char *medal_, int place_);
~Abitur_();
void print_(){
cout<<"Name: "<< name <<endl;
cout<<"Surname: "<< surname <<endl;
cout<<"Patronymic: "<< patronymic <<endl;
cout<<"Address: "<<address<<endl;
for(int i=0; i<3; i++)
cout << "estimation "<< i+1 <<" "<< estimation[i] <<endl;
cout<<"Medal: "<<medal<<endl;
cout<<"Place: "<<place<<endl;
};
};
Abitur::Abitur(const char *name_, const char *surname_, const char *patronymic_, const char *address_ , const int *estimation_)
{
strcpy(name, name_);
strcpy(surname, surname_);
strcpy(patronymic, patronymic_);
strcpy(address, address_);
for(j=0; j<3; j++)
{
estimation[j]=estimation_[j];
}
};
Abitur::~Abitur(){
};
Abitur_::Abitur_(const char *name_, const char *surname_, const char *patronymic_, const char *address_ , const int *estimation_, const char *medal_, int place_):Abitur(name_,surname_,patronymic_,address_,estimation)
{
strcpy(name, name_);
strcpy(surname, surname_);
strcpy(patronymic, patronymic_);
strcpy(address, address_);
strcpy(medal, medal_);
place=place_;
for(j=0; j<3; j++)
{
estimation[j]=estimation_[j];
}
}
Abitur_::~Abitur_(){
};
int inMoscow(Abitur *abitur[]){
int n=0;;
for(int i=0; i<3; i++){
if(strcmp(abitur[i]->address, "Moscow")==0){ n++;};
}
return n;
};
void main(){
int i, j, r;
Abitur *abitur[6];
char name[21];
char surname[21];
char patronymic[21];
char address[21];
int estimation[3];
char medal[7];
int place;
cout<<"Enter the data on the student:"<<endl;
for(i=0; i<3; i++){
cout<<"Name :";
cin>>name;
cout<<endl;
cout<<"Surname :";
cin>>surname;
cout<<endl;
cout<<"patronymic :";
cin>>patronymic;
cout<<endl;
cout<<"Address :";
cin>>address;
cout<<endl;
cout<<"Estimation :";
cout<<endl;
for(j=0; j<3; j++){
cout << "estimation number"<< j+1 <<": ";
cin>>estimation[j];
cout<<endl;
}
try{
abitur[i] = new Abitur(name, surname, patronymic, address, estimation);
} catch(bad_alloc ba){
cout<<"Mistake at allocation of memory";
getch();
return;
}
}
for(i=3; i<6; i++){
cout<<"Name :";
cin>>name;
cout<<endl;
cout<<"Surname :";
cin>>surname;
cout<<endl;
cout<<"patronymic :";
cin>>patronymic;
cout<<endl;
cout<<"Address :";
cin>>address;
cout<<endl;
cout<<"Medal :";
cin>>medal;
cout<<endl;
cout<<"Place :";
cin>>place;
cout<<endl;
cout<<"Estimation :";
cout<<endl;
for(j=0; j<3; j++){
cout << "estimation number"<< j+1 <<": ";
cin>>estimation[j];
cout<<endl;
}
try
{
abitur[i] = new Abitur_(name, surname, patronymic, address, estimation, medal, place);
}
catch(bad_alloc ba)
{
cout<<"Mistake at allocation of memory";
getch();
return;
}
}
cout<<"Enter number of the student:";
cin>>r;
if(r<0 || r>6){cout<<"Not the correct data"<<endl;}
else{r--; abitur[r]->print_() ;}
cout<<inMoscow(abitur)<<" students live at Moscow"<<endl;
for (int i = 0; i < 6; ++i)
{
delete abitur[i];
}
getch();
} |