Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Subscriber{
- private:
- string name, number_from;
- int count_calls;
- public:
- Subscriber(){};
- Subscriber(string name, string number_from, int count_calls);
- string get_name(){
- return name;
- }
- string get_number_from(){
- return number_from;
- }
- int get_count_calls(){
- return count_calls++;
- }
- void show();
- ~Subscriber(){};
- };
- class Catalog{
- private:
- Subscriber *array;
- int size = 0;
- public:
- Catalog(){
- array = new Subscriber[100];
- }
- void to_call(string number_to);
- void add(Subscriber a){
- array[size++] = a;
- }
- ~Catalog(){
- delete[] array;
- }
- };
- Subscriber::Subscriber(string name, string number_from, int count_calls) {
- this->name = name;
- this->number_from = number_from;
- this->count_calls = count_calls;
- }
- void Catalog::to_call(string number_to) {
- for (int i = 0; i < size; i++){
- if (array[i].get_number_from() == number_to){
- array[i].get_count_calls();
- array[i].show();
- }
- }
- }
- void Subscriber :: show(){
- cout << name << ' ' << number_from << ' ' << count_calls << '\n';
- }
- int main() {
- Catalog directory;
- int n;
- string name, number_from, number_to;
- int count_calls;
- cout << "Введите количество абонентов:";
- cin >> n;
- cout << '\n';
- for (int i = 0; i < n; i++){
- cout << "Введите нового абонента" << '\n';
- cout << "Введите имя абонента: ";
- cin >> name;
- cout <<'\n' << "Введите номер абонента: ";
- cin >> number_from;
- cout << '\n' << "Введите количество звонков: ";
- cin >> count_calls;
- Subscriber a(name, number_from, count_calls);
- directory.add(a);
- }
- cout << '\n' << "Введите ваше имя: ";
- cin >> name;
- cout << '\n' << "Введите ваш номер: ";
- cin >> number_from;
- cout << '\n' << "Введите номер, на который надо позвонить: ";
- cin >> number_to;
- directory.to_call(number_to);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement