Создайте класс SatelliteTV (спутниковое телевидение). В классе должны быть представлены поля: идентификационный номер абонента, фамилия-имя-отчество, город, номер паспорта, серия паспорта, наименование пакета спутниковых программ, цена пакета спутниковых программ, дата регистрации. Доступ к полям класса организовать посредством соответствующих методов. Разработать программу, в которой создается массив объектов данного класса. В программе организовать:
- добавление абонента в группу пользователей;
- удаление абонента из группы пользователей;
- поиск абонента по номеру паспорта (фамилии-имени-отчеству);
- сортировка по идентификационному номеру.
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
| #include "stdafx.h"
const int l_IdNum = 30;
const int l_family = 30;
const int l_city = 20;
const int l_NumPas = 10;
const int l_SerPas = 10;
const int l_NamePack = 20;
const int l_price = 10;
const int l_date = 10;
const int l_buf = l_IdNum + l_family + l_city + l_NumPas + l_SerPas + l_NamePack + l_price + l_date;
class SatelliteTV{
public:
SatelliteTV(int family=30); // конструктор
~SatelliteTV();
bool Comparefamily(const char*) const;
char GetIdNum() const {return IdNum[30];}
char Getcity() const {return city[20];}
int GetNumPas() const {return NumPas[10];}
int GetSerPas() const {return SerPas[10];}
char GetNamePack() const {return NamePack[20];}
float Getprice() const {return price[10];}
char Getdate() const {return date[10];}
char* Getfamily() const {return pfamily[30];}
void print() const;
void SetIdNum(const char*);
void Setfamily(const char*);
void Setcity(const char*);
void SetNumPas(const char*);
void SetSerPas(const char*);
void SetNamePack(const char*);
void Setprice(const char*);
void Setdate(const char*);
private:
char IdNum[30]; // идентификационный номер абонента
char *pfamily[30]; // фамилия-имя-отчество
char city[20]; // город
int NumPas[10]; //номер паспорта
int SerPas[10]; //серия паспорта
char NamePack[20]; //наименование пакета
float price[10]; //цена
char date[10]; // дата регистрации
};
//////////////////////////////////////////////////////////////////////////
//Satellite.cpp
#include <iostream>
#include <cstring>
using namespace std;
SatelliteTV ::SatelliteTV(int lIdNum) {
cout << "Constructor is working" << endl;
pfamily[30]=new char[lIdNum+1];
}
SatelliteTV :: ~SatelliteTV() {
cout << "Destructor is working" << endl;
delete [] pfamily;
}
void SatelliteTV :: SetIdNum(const char* fromBuf){
strncpy(pfamily[30], fromBuf, l_IdNum);
pfamily[l_IdNum] = 0;
}
void SatelliteTV :: Setfamily(const char* fromBuf){
IdNum[30] = atoi(fromBuf + l_IdNum);
}
void SatelliteTV :: Setcity(const char* fromBuf){
city[20] = atof(fromBuf + l_IdNum + l_family);
}
void SatelliteTV :: SetNumPas(const char* fromBuf){
NumPas[10] = atoi(fromBuf + l_IdNum + l_family + l_city);
}
void SatelliteTV :: SetSerPas(const char* fromBuf){
SerPas[10] = atoi(fromBuf + l_IdNum + l_family + l_city + l_NumPas);
}
void SatelliteTV :: SetNamePack(const char* fromBuf){
NamePack[20] = atof(fromBuf + l_IdNum + l_family + l_city + l_NumPas + l_SerPas);
}
void SatelliteTV :: Setprice(const char* fromBuf){
price[10] = atof(fromBuf + l_IdNum + l_family + l_city + l_NumPas + l_SerPas + l_NamePack);
}
void SatelliteTV :: Setdate(const char* fromBuf){
date[10] = atof(fromBuf + l_IdNum + l_family + l_city + l_NumPas + l_SerPas + l_NamePack + l_price);
}
bool SatelliteTV :: Comparefamily (const char* family) const {
if ((strstr(*pfamily, family)) && (pfamily[30][strlen(IdNum)] == ' '))
return true;
else
return false;
}
void SatelliteTV::print() const {
cout << pfamily << IdNum << city << NumPas << SerPas << ' ' << NamePack << price << date << endl;
}
#include <fstream>
const char filename[] = "dbase.txt";
int main() {
setlocale (LC_ALL, "russian");
const int maxn_record = 10;
SatelliteTV satelliteTV[maxn_record];
char buf [l_buf +1];
char family[l_family + 1];
ifstream fin(filename);
if (!fin) {
cout << "Нет файла " << filename << endl; return 1;
}
int i = 0;
while (fin.getline(buf, l_buf)) {
if (i >= maxn_record) {
cout << "Слишком длинный файл" ; return 1; }
satelliteTV[i].SetIdNum(buf);
satelliteTV[i].Setfamily(buf);
satelliteTV[i].Setcity(buf);
satelliteTV[i].SetNumPas(buf);
satelliteTV[i].SetSerPas(buf);
satelliteTV[i].SetNamePack(buf);
satelliteTV[i].Setprice(buf);
satelliteTV[i].Setdate(buf);
i++;
}
int n_record = i, n_satelliteTV = 0;
float mean_price = 0;
while (true) {
cout << "Введите или слово end: ";
cin >> family;
if(0 == strcmp(family, "end")) break;
bool not_found = true;
for (i=0; i<n_record; ++i){
if (satelliteTV[i].Comparefamily(family)){
satelliteTV[i].print();
n_satelliteTV++; mean_price += satelliteTV[i].Getprice();
not_found = false;
break;
}
}
if (not_found) cout << "Такого абонента нет" << endl;
}
if (n_satelliteTV) cout << "ghgh" << mean_price / n_satelliteTV << endl;
return 0;
} |
|