35657

Untitled

May 15th, 2023
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_WARNINGS
  3.  
  4. #include <iostream>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. struct contact {
  10.     char name[100];
  11.     char mobile_phone[20];
  12.     char home_phone[20];
  13.     char work_phone[20];
  14. };
  15.  
  16.  
  17.  
  18. class phone_book {
  19.  
  20. public:
  21.  
  22.     phone_book();
  23.  
  24.     phone_book(int max_number);
  25.  
  26.     phone_book(contact arr[], int arr_size);
  27.  
  28.     void AddContact(const char name[], const char mobile_phone[], const char home_phone[], const char work_phone[]) {
  29.         if (contact_number == max_contact_number) {
  30.             cout << "The contact cannot be added" << endl;
  31.             return;
  32.         }
  33.         store[contact_number] = new contact{};
  34.         strcpy(store[contact_number]->name, name);
  35.         strcpy(store[contact_number]->mobile_phone, mobile_phone);
  36.         strcpy(store[contact_number]->home_phone, home_phone);
  37.         strcpy(store[contact_number]->work_phone, work_phone);
  38.         contact_number++;
  39.     }
  40.  
  41.     void DelContact(const char name[]);
  42.  
  43.     void FindContactName(const char name[]);
  44.  
  45.     void ShowAllContacts();
  46.  
  47.     ~phone_book();
  48.    
  49.  
  50. private:
  51.     contact** store;
  52.     int contact_number;
  53.     int max_contact_number;
  54. };
  55.  
  56. int main() { // для проверки функционала
  57.  
  58.     phone_book my_store; // для проверки конструктора по умолчанию
  59.  
  60.     //phone_book my_store(50); // для проверки конструктора для одного параметра
  61.  
  62.     //contact some_contacts[]{ {"Ivan", "+79111111111", "111111", "121212"}, {"Zhenya", "+79111111333", "111133", "121233"}}; // для проверки конструктора для двух параметров (закомментировать первые два добавления контакта)
  63.  
  64.     //phone_book my_store(some_contacts, 2); // для проверки конструктора для двух параметров
  65.  
  66.     my_store.AddContact("Ivan", "+79111111111", "111111", "121212");
  67.     my_store.AddContact("Zhenya", "+79111111333", "111133", "121233");
  68.     my_store.AddContact("Galya", "+79115511333", "166133", "127733");
  69.     my_store.AddContact("Olya", "+79115511333", "166133", "127733");
  70.  
  71.     my_store.ShowAllContacts();
  72.  
  73.     my_store.DelContact("Zhenya");
  74.  
  75.     my_store.ShowAllContacts();
  76.  
  77.     my_store.AddContact("Zhenya", "+79111111333", "111133", "121233");
  78.  
  79.     my_store.FindContactName("Galya");
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment