Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Subscriber{
  5. private:
  6.     string name, number_from;
  7.     int count_calls;
  8. public:
  9.     Subscriber(){};
  10.     Subscriber(string name, string number_from, int count_calls);
  11.     string get_name(){
  12.         return name;
  13.     }
  14.     string get_number_from(){
  15.         return number_from;
  16.     }
  17.     int get_count_calls(){
  18.         return count_calls++;
  19.     }
  20.  
  21.     void show();
  22.     ~Subscriber(){};
  23.  
  24. };
  25.  
  26. class Catalog{
  27. private:
  28.     Subscriber *array;
  29.     int size = 0;
  30. public:
  31.     Catalog(){
  32.         array = new Subscriber[100];
  33.     }
  34.     void to_call(string number_to);
  35.     void add(Subscriber a){
  36.         array[size++] = a;
  37.     }
  38.     ~Catalog(){
  39.         delete[] array;
  40.     }
  41. };
  42. Subscriber::Subscriber(string name, string number_from, int count_calls) {
  43.     this->name = name;
  44.     this->number_from = number_from;
  45.     this->count_calls = count_calls;
  46. }
  47.  
  48. void Catalog::to_call(string number_to) {
  49.     for (int i = 0; i < size; i++){
  50.         if (array[i].get_number_from() == number_to){
  51.             array[i].get_count_calls();
  52.             array[i].show();
  53.         }
  54.     }
  55. }
  56. void Subscriber :: show(){
  57.     cout << name << ' ' << number_from << ' ' << count_calls << '\n';
  58. }
  59. int main() {
  60.     Catalog directory;
  61.     int n;
  62.     string name, number_from, number_to;
  63.     int count_calls;
  64.     cout << "Введите количество абонентов:";
  65.     cin >> n;
  66.     cout << '\n';
  67.     for (int i = 0; i < n; i++){
  68.         cout << "Введите нового абонента" << '\n';
  69.         cout << "Введите имя абонента: ";
  70.         cin >> name;
  71.         cout <<'\n' << "Введите номер абонента: ";
  72.         cin >> number_from;
  73.         cout << '\n' << "Введите количество звонков: ";
  74.         cin >> count_calls;
  75.         Subscriber a(name, number_from, count_calls);
  76.         directory.add(a);
  77.     }
  78.     cout << '\n' << "Введите ваше имя: ";
  79.     cin >> name;
  80.     cout << '\n' << "Введите ваш номер: ";
  81.     cin >> number_from;
  82.     cout << '\n' << "Введите номер, на который надо позвонить: ";
  83.     cin >> number_to;
  84.     directory.to_call(number_to);
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement