#include <iostream>
//#include <conio>
using namespace std;
const int MAX_LIST_SIZE = 25;
const int PHONE_SIZE = 5;
const int MOBILE = 0;
const int HOME = 1;
const int WORK = 2;
const int FAX = 3;
const int OTHER = 4;
const int COM = 0;
const int EDU = 1;
const int GOV = 2;
const int NET = 3;
int lastList = 0;
struct Pnumber{
int areaCode;
int exchange;
int extention;
int pType;
};
struct Email{
string username;
string secondDomain;
int firstDomain;
};
struct Contact{
int lastNumberUsed;
string name;
Pnumber numbers[PHONE_SIZE];
Email address;
};
Contact phonebook[MAX_LIST_SIZE];
void addPhoneNumber(){
int numberOfPhones;
cout<<"How many phone numbers would you like to enter? (Max 5)"<<endl;
cin>>numberOfPhones;
for(int i=0; i<numberOfPhones; i++){
string phoneNumber;
cout<<"Please enter the phone number(###-###-####)"<<endl;
cin>>phoneNumber;
string tempArea= phoneNumber.substr(0,3);
string tempExchange= phoneNumber.substr(4,6);
string tempExtention= phoneNumber.substr(8,10);
phonebook[lastList].numbers[i].areaCode= atoi(tempArea.c_str());
phonebook[lastList].numbers[i].exchange= atoi(tempExchange.c_str());
phonebook[lastList].numbers[i].extention= atoi(tempExtention.c_str());
cout<<"What type of phone number is this:"<<endl;
cout<<"M-mobile"<<endl;
cout<<"H-home"<<endl;
cout<<"W-work"<<endl;
cout<<"F-fax"<<endl;
cout<<"O-other"<<endl;
char type;
cin>>type;
switch(type){
case 'M': phonebook[lastList].numbers[i].pType = MOBILE;
case 'W': phonebook[lastList].numbers[i].pType = WORK;
case 'H': phonebook[lastList].numbers[i].pType = HOME;
case 'F': phonebook[lastList].numbers[i].pType = FAX;
case 'O': phonebook[lastList].numbers[i].pType = OTHER;
default: cout<<"Please choose an option from the menu"<<endl;
}
cout<<phonebook[lastList].numbers[i].pType<<endl;
}
}
/*
FIGURE OUT HOW TO FIND THE END OF THE EMAIL STRING
*/
void addEmail(){
string tempEmail;
cout<<"Please enter the contact's email"<<endl;
cin>>tempEmail;
int locationOfAt = tempEmail.find('@');
int locationOfDot = tempEmail.rfind('.');
string tempUserName= tempEmail.substr(0,locationOfAt);
string tempSecondDomain= tempEmail.substr(locationOfAt,locationOfDot);
string tempFirstDomain= tempEmail.substr(locationOfDot+1,locationOfDot+4);
phonebook[lastList].address.username= atoi(tempUserName.c_str());
phonebook[lastList].address.secondDomain= atoi(tempUserName.c_str());
if(tempFirstDomain=="edu"||"EDU"){
phonebook[lastList].address.firstDomain= EDU;
}
if(tempFirstDomain=="gov"||"GOV"){
phonebook[lastList].address.firstDomain= GOV;
}
if(tempFirstDomain=="net"||"NET"){
phonebook[lastList].address.firstDomain= NET;
}
if(tempFirstDomain=="com"||"COM"){
phonebook[lastList].address.firstDomain= COM;
}
}
void addContact(){
char input;
string tempName;
cout<<"Please enter the name of the new contact"<<endl;
cin>>tempName;
phonebook[lastList].name=tempName;
cout<<"Would you like to add a phone number for this contact? (Y or N)"<<endl;
cin>>input;
switch(input){
case 'Y': addPhoneNumber();
case 'N': break;
default: cout<<"Please choose either 'Y' or 'N'"<<endl;
}
cout<<"Would you like to add an email address? (Y or N)"<<endl;
cin>>input;
switch(input){
case 'Y': addEmail();
case 'N': cout<<"Would you like to add another contact?"<<endl;
default: cout<<"Please choose either 'Y' or 'N'"<<endl;
}
lastList++;
char choice;
cin>>choice;
switch(choice){
case 'Y': addContact();
case 'N': exit(0);
}
}
/*
void addAnother(){
cout<<"Would you like to add another contact? ('Y' or'N'"<<endl;
char choice;
cin>>choice;
switch(choice){
case 'Y': addContact();
case 'N': exit(0);
}
}
*/
void printMenu(){
char menuChoice;
cout<<"Please Choose from one of the following 4 options:"<<endl;
cout<<"A-add a contact"<<endl;
cout<<"D-delete a contact"<<endl;
cout<<"S-save contact list to file"<<endl;
cout<<"Q-quit"<<endl;
cin>>menuChoice;
switch(menuChoice){
//if the user uses uppercase
case 'A': addContact(); break;
case 'D': cout<<"Feature coming soon!"<<endl; printMenu();
case 'S': cout<<"Feature coming soon!"<<endl; printMenu();
case 'Q': exit(0);
//if the user uses lowercase
case 'a': addContact(); break;
case 'd': cout<<"Feature coming soon!"<<endl; printMenu();
case 's': cout<<"Feature coming soon!"<<endl; printMenu();
case 'q': exit(0);
//in case the user can't read
default: cout<<"Please pick a choice from the menu"<<endl;
}
}
int main(){
printMenu();
}