In main function, we will start the program by showing outputs 1. Add Contact 2. View Contacts 3. Search Contact 4. Delete Contact 5. Exit
Selecting option 1 will add contacts, option 2 will view existing contacts, option 3 will search in the existing contacts, option 4 will delete a contact and option 5 will exit the program. Incase if someone enter any other number, it will show output "Invalid input, please try again."
The program can perfectly handle all the edge cases and show a proper output for each cases.
First, we will declare a class named Student and make this a public class. There, we will declare which types of inputs and how many inputs we want to take.
Here, we have used strings to take input of Name; Number; email of the student and then create a constructor named Student.
We will create a function here to add new contacts of the students. We will take inputs of Name, Number and email.
At first we will show output "Enter Name: ". The cin.ignore() will ignore any extra spaces left earlier and getline(cin, Name) will take input the name. Likewise, we will take input the phone number and email as well.
After the process is done, we will show output "Contact Added!"
in viewContacts function, we will show output "No Contacts Available" if there are no contacts saved earlier or all of the contacts are already deleted.
Otherwise, we will show output as following-
Student's Name:
Student's phone number:
Student's email:
in searchContacts function, we will take inputs of student's name as a string and show output if it matches with any student's name. In case if we can't find any student with same name, we willshow output "Contact Not Found".
If we find the contact, we will show output as following-
Student's Name:
Student's phone number:
Student's email:
In deleteContacts function, we will take inputs of student's name as a string and iterate through the vector students to find the contact with the same name. If iterator is equal address of the end of the vector, it means we couldn't find that contact and it will show output "Contacts Not Found"
If we find the contact, we will erase that contact from the vector and show output "Contact Deleted!"