Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- class Book
- {
- public:
- std::string name;
- std::string mobile_number;
- public:
- Book()
- {
- name = "";
- mobile_number = "";
- }
- bool add(std::string pName, std::string pMobile_number)
- {
- if (name == "")
- {
- name = pName;
- mobile_number = pMobile_number;
- return 1;
- }
- else
- return 0;
- };
- };
- int main()
- {
- std::string temp_name;
- std::string temp_mobile;
- Book person[2];
- bool condition = true;
- int choice;
- bool added = false;
- while (condition == true)
- {
- std::cout << "****************************" << std::endl;
- std::cout << "1. Add contact" << std::endl;
- std::cout << "2. Show contacts" << std::endl;
- std::cout << "3. Exit program" << std::endl;
- std::cout << "Enter your choice and press enter: ";
- std::cin >> choice;
- switch (choice)
- {
- case 1:
- std::cout << "Give contact name: " << std::endl;
- std::cin >> temp_name;
- std::cout << "Give the mobile number: " << std::endl;
- std::cin >> temp_mobile;
- for (int i = 0; i < 2; i++) {
- if (person[i].add(temp_name, temp_mobile))
- {
- std::cout << "Contact added successfully" << std::endl;
- added = true;
- break;
- }
- }
- if (added == false)
- {
- std::cout << "Memory full! Delete some contacts first" << std::endl;
- break;
- }
- break;
- case 2:
- for (int i = 0; i < 2; i++)
- {
- std::cout << "Name: " << person[i].name << " - " << "Mobile number: " << person[i].mobile_number << std::endl;
- }
- break;
- case 3:
- std::cout << "Ending program." << std::endl;
- condition = false;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement