Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Language. Create a class that holds the name and email address.

ID: 3843396 • Letter: C

Question

C++ Programming Language.

Create a class that holds the name and email address.

Create an array of 8 objects of the class type to hold the data.

The class should have a member that prompts for, and collects the name and email address.

The class should have a member that displays the name and email address.

Also, the program should immediately terminate when Q is entered (do not pause).

Read the problem.

Create a program that keeps track of up to 8 contacts. The user should be able to add and display entries by selecting which operation to perform from a menu. The program should perform the following operations: 1. A menu should appear prompting the user to enter A to add an entry; P to print the entries; Q to quit.

The menu should repeat continuously until the user enters Q (upper or lower case). 2. When the user enters A, they should be prompted for the name and email address of a contact.

If 8 contacts are already being stored, display an error message and redisplay the menu.

Name and email address should be strings. Do not format either entry (any input should be acceptable).

After collecting and storing the name and email address redisplay the menu. 3. When the user enters P, all of the stored names and email addresses should display.

After the names and email addresses display, the menu should redisplay. 4. When the user enters something other than A, P, or Q, the menu should redisplay. 5.

Create a class that holds the name and email address.

Create an array of 8 objects of the class type to hold the data.

The class should have a member that prompts for, and collects the name and email address.

The class should have a member that displays the name and email address.

Also, the program should immediately terminate when Q is entered (do not pause).

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class Contact {
   public:
       void setName() {
           cout<<"Enter name: ";
           cin >> name;
       }

       void setEmail() {
           cout << "Enter email: ";
           cin >> email;
       }

       string getName() {
           return name;
       }

       string getEmail() {
           return email;
       }
   private:
       string email;
       string name;
};

int count;
Contact* list;
char menu() {
   char ch;
   cout << "A Create a new contact ";
   cout << "P Print all contacts ";
   cout << "Q Quit ";
   cin >> ch;
   return ch;
}

int main() {
   count = 0;
   list = new Contact[8];
   char input;
   while ((input = menu())!='Q') {
       switch(input) {
           case 'A':
               if (count == 8) {
                   cout << "Contact list full. Cannot create contacts. ";
                   break;
               }
               list[count] = Contact();
               list[count].setName();
               list[count].setEmail();
               count ++;
               break;
           case 'P':
               cout << "Name Email ";
               for (int i = 0; i < count; i++)  
               cout << list[i].getName() << " " << list[i].getEmail() << endl;
               break;
           default:
               cout << "Wrong entry" << endl;
              
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote