27.06.2019, 00:01. Показов 834. Ответов 0
Полный текст задания: Идентификатором личности являются паспорт, где зафиксированы ваши фамилия, имя и отчество, дата и место рождения, пол, место жительства, номер паспорта и кем и когда он выдан. Для компьютерной обработки данных о людях в каком-то учреждении создать класс, полями которого будут все вышеперечисленные элементы.
1. Создать класс Homo с перечисленными выше полями и методами доступа к ним и методом вычисления возраста по текущей дате и дате рождения. Возраст округлять до ближайшего целого.
2. Создать класс Student с дополнительными полями University, Faculty, Speciality, Year и метода подсчета среднего балла по пяти дисциплинам: Computer Science, Discrete Mathematic, Algebra, Geometry. Считайте, что ваша стипендия пропорциональна этом рейтинге - это ваш способ существования, ваш доход.
3. Создать класса: Doctor i Dealer. Доход первого зависит от его опыта практической работы, а другого от количества проданных автомобилей.
4. Написать программу, которая перечень людей разных профессий (студентов, врачей и торговцев в доильному порядке и произвольного количества) и выводит доход каждого из них с указанием профессии и способа получения дохода.
Текст программы:
1)Пр.cpp
| C++ |
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
| #include "Dealer.h"
#include "Doctor.h"
#include "Student.h"
#include "Homo.h"
#include <string.h>
int main() {
setlocale(LC_ALL, "RUS");
int ch, n1, n2, n3, a, i1=0, i2=0, i3=0;
string b;
cout << "Сколько студентов будет содержать список? ";
cin >> n1;
Student *S;
S = new Student[n1];
cout << "Сколько докторов будет содержать список? ";
cin >> n2;
Doctor *DC;
DC = new Doctor[n2];
cout << "Сколько диллеров будет содержать список? ";
cin >> n3;
Dealer *DL;
DL = new Dealer[n3];
do {
system("cls");
cout << "Добавить..." << endl << "1 - студента" << endl << "2 - доктора" << endl << "3 - диллера" << endl << "4 - вывести всех учасников списка"
<< endl << "5 - выход из программы" << endl;
cin >> ch;
system("cls");
switch (ch) {
case 1:
if (i1 < n1) {
cout << "День рождения: ";
cin >> a;
S[i1].SetDayb(a);
cout << "Месяц рождения: ";
cin >> a;
S[i1].SetMounthb(a);
cout << "Год рождения: ";
cin >> a;
S[i1].SetYearb(a);
cout << "Имя: ";
cin >> b;
S[i1].SetName(b);
cout << "Фамилия: ";
cin >> b;
S[i1].SetSurname(b);
cout << "Отчество: ";
cin >> b;
S[i1].SetPat(b);
cout << "Пол: ";
cin >> b;
S[i1].SetMof(b);
cout << "Место рождения: ";
cin >> b;
S[i1].SetPlaceb(b);
cout << "Номер паспорта: ";
cin >> b;
S[i1].SetNumber(b);
cout << "Место выдачи паспорта: ";
cin >> b;
S[i1].SetPassportp(b);
cout << "Кем выдан: ";
cin >> b;
S[i1].SetPassportg(b);
cout << "Год поступления: ";
cin >> a;
S[i1].SetYear(a);
cout << "Университет: ";
cin >> b;
S[i1].SetUniversity(b);
cout << "Факультет: ";
cin >> b;
S[i1].SetFaculty(b);
cout << "Специальность: ";
cin >> b;
S[i1].SetSpeciality(b);
S[i1].rate();
i1++;
}
else cout << "Вы пытаетесь ввести слишком много членов!"<<endl;
system("cls");
break;
case 2:
if (i2 < n2) {
cout << "День рождения: ";
cin >> a;
DC[i2].SetDayb(a);
cout << "Месяц рождения: ";
cin >> a;
DC[i2].SetMounthb(a);
cout << "Год рождения: ";
cin >> a;
DC[i2].SetYearb(a);
cout << "Имя: ";
cin >> b;
DC[i2].SetName(b);
cout << "Фамилия: ";
cin >> b;
DC[i2].SetSurname(b);
cout << "Отчество: ";
cin >> b;
DC[i2].SetPat(b);
cout << "Пол: ";
cin >> b;
DC[i2].SetMof(b);
cout << "Место рождения: ";
cin >> b;
DC[i2].SetPlaceb(b);
cout << "Номер паспорта: ";
cin >> b;
DC[i2].SetNumber(b);
cout << "Место выдачи паспорта: ";
cin >> b;
DC[i2].SetPassportp(b);
cout << "Кем выдан: ";
cin >> b;
DC[i2].SetPassportg(b);
cout << "Опыт работы: ";
cin >> a;
DC[i2].SetExp(a);
}
else cout << "Вы пытаетесь ввести слишком много членов!" << endl;
system("cls");
break;
case 3:
if (i2 < n2) {
cout << "День рождения: ";
cin >> a;
DL[i2].SetDayb(a);
cout << "Месяц рождения: ";
cin >> a;
DL[i2].SetMounthb(a);
cout << "Год рождения: ";
cin >> a;
DL[i2].SetYearb(a);
cout << "Имя: ";
cin >> b;
DL[i2].SetName(b);
cout << "Фамилия: ";
cin >> b;
DL[i2].SetSurname(b);
cout << "Отчество: ";
cin >> b;
DL[i2].SetPat(b);
cout << "Пол: ";
cin >> b;
DL[i2].SetMof(b);
cout << "Место рождения: ";
cin >> b;
DL[i2].SetPlaceb(b);
cout << "Номер паспорта: ";
cin >> b;
DL[i2].SetNumber(b);
cout << "Место выдачи паспорта: ";
cin >> b;
DL[i2].SetPassportp(b);
cout << "Кем выдан: ";
cin >> b;
DL[i2].SetPassportg(b);
cout << "Количество проданых автомобилей: ";
cin >> a;
DL[i2].SetNoc(a);
}
else cout << "Вы пытаетесь ввести слишком много членов!" << endl;
system("cls");
break;
break;
case 4:
cout << "Имя\tФамилия\tОтчество\tРод деятельности\tЗаработок" << endl;
for (int i=0; i < n1; i++) {
cout << S[i].GetName() << "\t" << S[i].GetSurname() << "\t" << S[i].GetPat() << "\t" << "Студент \t" << S[i].GetSalary() << endl;
}
for (int i = 0; i < n2; i++) {
cout << DC[i].GetName() << "\t" << DC[i].GetSurname() << "\t" << DC[i].GetPat() << "\t" << "Доктор \t" << DC[i].GetSalary() << endl;
}
for (int i = 0; i < n3; i++) {
cout << DL[i].GetName() << "\t" << DL[i].GetSurname() << "\t" << DL[i].GetPat() << "\t" << "Диллер \t" << DL[i].GetSalary() << endl;
}
system("pause");
break;
case 5:
break;
default:
cout << "Выберите корректный вариант: ";
}
} while (ch!=5);
system("pause");
} |
|
2)Homo.cpp
| C++ |
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
| #include "Homo.h"
#include <string.h>
using namespace std;
Homo::Homo()
{
setlocale(LC_ALL, "RUS");
}
int Homo::age(int y, int m) {
if ((mounthb - m) >= 6) {
return yearb - y + 1;
}
return yearb - y;
}
Homo::~Homo()
{
}
void Homo::SetYearb(int y)
{
yearb = y;
}
int Homo::GetYearb(void)
{
return yearb;
}
void Homo::SetDayb(int y) {
dayb = y;
}
int Homo::GetDayb(void) {
return dayb;
}
void Homo::SetMounthb(int y) {
mounthb = y;
}
int Homo::GetMounthb(void) {
return mounthb;
}
void Homo::SetYearg(int y) {
yearg = y;
}
int Homo::GetYearg(void) {
return yearg;
}
void Homo::SetName(string y) {
name = y;
}
string Homo::GetName(void) {
return name;
}
void Homo::SetSurname(string y) {
surname = y;
}
string Homo::GetSurname(void) {
return surname;
}
void Homo::SetPat(string y) {
pat = y;
}
string Homo::GetPat(void) {
return pat;
}
void Homo::SetMof(string y) {
mof = y;
}
string Homo::GetMof(void) {
return mof;
}
void Homo::SetPlaceb(string y) {
placeb = y;
}
string Homo::GetPlaceb(void) {
return placeb;
}
void Homo::SetNumber(string y) {
number = y;
}
string Homo::GetNumber(void) {
return number;
}
void Homo::SetPassportp(string y) {
passportp = y;
}
string Homo::GetPassportp(void) {
return passportp;
}
void Homo::SetPassportg(string y) {
passportg = y;
}
string Homo::GetPassportg(void) {
return passportg;
} |
|
3)Homo.h
| C++ |
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
| #pragma once
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
class Homo
{
public:
Homo();
~Homo();
int age(int y, int m);
void SetYearb(int y);
int GetYearb(void);
void SetDayb(int y);
int GetDayb(void);
void SetMounthb(int y);
int GetMounthb(void);
void SetYearg(int y);
int GetYearg(void);
void SetName(string y);
string GetName(void);
void SetSurname(string y);
string GetSurname(void);
void SetPat(string y);
string GetPat(void);
void SetMof(string y);
string GetMof(void);
void SetPlaceb(string y);
string GetPlaceb(void);
void SetNumber(string y);
string GetNumber(void);
void SetPassportg(string y);
string GetPassportg(void);
void SetPassportp(string y);
string GetPassportp(void);
private:
string name, surname, pat, mof, placeb, number, passportp, passportg;
int dayb, mounthb, yearb, yearg;
}; |
|
4)Student.cpp
| C++ |
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
| #include "Student.h"
#include <stdio.h>
#include <iostream>
Student::Student()
{
}
void Student::rate() {
setlocale(LC_ALL, "RUS");
cout << "Введите оценки:"<<endl<<"Компьютерные науки: ";
cin >> CS;
cout << "Дискретная математика: ";
cin >> DM;
cout << "Алгебра: ";
cin >> A;
cout << "Геометрия: ";
cin >> G;
cout << "Английский: ";
cin >> E;
salary = ((CS + DM + A + G + E) / 5.)*400;
}
void Student::SetYear(int y) {
year = y;
}
int Student::GetYear(void) {
return year;
}
void Student::SetUniversity(string y) {
University = y;
}
string Student::GetUniversity(void) {
return University;
}
void Student::SetFaculty(string y) {
Faculty = y;
}
string Student::GetFaculty(void) {
return Faculty;
}
void Student::SetSpeciality(string y) {
Speciality = y;
}
string Student::GetSpeciality(void) {
return Speciality;
}
void Student::SetSalary(float y) {
salary = y;
}
float Student::GetSalary(void) {
return salary;
}
Student::~Student()
{
} |
|
5)Student.h
| C++ |
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
| #pragma once
#include <string>
#include <iostream>
#include "Homo.h"
using namespace std;
class Student:public Homo
{
public:
Student();
~Student();
void rate();
void SetYear(int y);
int GetYear(void);
void SetUniversity(string y);
string GetUniversity(void);
void SetFaculty(string y);
string GetFaculty(void);
void SetSpeciality(string y);
string GetSpeciality(void);
void SetSalary(float y);
float GetSalary(void);
private:
string University, Faculty, Speciality;
int year;
float CS, DM, A, G, E, salary;
}; |
|
6)Doctor.h
| C++ |
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
| #include "Doctor.h"
Doctor::Doctor()
{
}
Doctor::Doctor(int exp) {
this->exp = exp;
}
Doctor::~Doctor()
{
}
void Doctor::SetExp(int y) {
exp = y;
salary = exp * 2000;
}
int Doctor::GetExp(void) {
return exp;
}
void Doctor::SetSalary(int y) {
salary = y;
}
int Doctor::GetSalary(void) {
return salary;
} |
|
7)Doctor.cpp
| C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| #pragma once
#include "Homo.h"
class Doctor:public Homo
{
public:
Doctor();
Doctor(int exp);
~Doctor();
void SetExp(int y);
int GetExp(void);
void SetSalary(int y);
int GetSalary(void);
private:
int exp, salary;
}; |
|
8)Dealer.h
| C++ |
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
| #include "Dealer.h"
Dealer::Dealer()
{
}
Dealer::Dealer(int noc) {
this->noc = noc;
}
Dealer::~Dealer()
{
}
void Dealer::SetNoc(int y) {
noc = y;
salary = noc * 500;
}
int Dealer::GetNoc(void) {
return noc;
}
void Dealer::SetSalary(int y) {
salary = y;
}
int Dealer::GetSalary(void) {
return salary;
} |
|
9)Dealer.cpp
| C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #pragma once
#include "Homo.h"
class Dealer:public Homo
{
public:
Dealer();
Dealer(int noc);
~Dealer();
void SetNoc(int y);
int GetNoc(void);
void SetSalary(int y);
int GetSalary(void);
private:
int noc, salary;
}; |
|
Программа рабочая, вопросов никаких нет. Просто сливаю в инет свои лабы, может кому-то пригодится.