1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <string>
using namespace std;
class ContactsClass {
private:
string recordNumber;
string fn;
string ln;
string age;
string phone;
public:
ContactsClass() = default;
ContactsClass(const string& aRn, const string& aFn, const string& aLn, const string& aAge, const string& aPhone) : recordNumber(aRn), fn(aFn), ln(aLn), age(aAge), phone(aPhone) {}
//Get Information functions.
void inputRecord() {
getline(cin, recordNumber);
}
void inputFirstName() {
getline(cin, fn);
}
void inputLastName() {
getline(cin, ln);
}
void inputAge() {
getline(cin, age);
}
void inputPhone() {
getline(cin, phone);
}
void displayInfo() {
cout << "Record Number: " << recordNumber << endl;
cout << "First Name: " << fn << endl;
cout << "Last Name: " << ln << endl;
cout << "Age: " << age << endl;
cout << "Phone Number: " << phone << endl;
}
};
int main()
{
const size_t maxcon {5};
ContactsClass list[maxcon];
size_t choice {};
do {
//Main Menu - run this until choice 3 is picked.
cout << "1. Add New Record\n";
cout << "2. Display all records\n";
cout << "3. Exit Program\n";
cout << "Enter Menu Number:\n";
cin >> choice;
cin.ignore();
switch (choice) {
case 1:
{
size_t i {};
string add;
//Enter information
do {
cout << "Enter record number: ";
list[i].inputRecord();
cout << "Enter First Name: ";
list[i].inputFirstName();
cout << "Enter Last Name: ";
list[i].inputLastName();
cout << "Enter Age: ";
list[i].inputAge();
cout << "Enter Phone Number: ";
list[i].inputPhone();
if (++i < maxcon) {
cout << "Add another record? Enter 'yes' or 'no': ";
cin >> add;
cin.ignore();
} else
add = "no";
} while (add == "yes");
}
break;
case 2:
{
string exit;
//record information display.
//header
cout << " Record Information \n";
cout << "--------------------------\n";
//loop to cycle through all records and display.
for (int i = 0; i < maxcon; ++i) {
list[i].displayInfo();
cout << "--------------------------\n";
}
//user input for exit.
cout << "Enter 'exit' to return to main menu.\n";
cin >> exit;
cin.ignore();
}
break;
case 3:
break;
default:
cout << "Invalid option\n";
break;
}
} while (choice != 3);
}
|