Exemplo n.º 1
0
int main(int argc, char** argv) {
	
const int Sentinel = 0;  //The value 0 Exits the program if entered by the user.

int input = 1; //Variable 'input' is where the value entered by the user is stored.

string name; //This value stores the name of a contact. 
//It is meant to be instantiated by the askName() function


ContactList clientList;

cout << "This program is designed to maintain contact information" << endl;


 
		while(input != Sentinel) //Loop structure. Loop will only exit when 0 is entered.
			{
				menu();          //display menu and choices
				cin >> input;    //User inputs a choice. Choice is saved in 'input'
				                 
				                 //Perform appropriate operation pending on the input value.
				if(input == 1)
					{ cout <<"(Add Contact)"<< endl;
					  clientList.addToHead(getContact());
					}
					
		   else if(input == 2)
					{ 
						if(clientList.empty())
							{ cout <<"Error:Cannot delete from empty contact list" << endl; }
					
						else
					  		{
								cout <<"(Delete Contact)" << endl;
					  			name = askName();
								if(clientList.verify(name))
								{clientList.delete_ByName(name);}
								else{ cout << "Error:Contact '" << name << "' not found in the contact list" << endl;}
							} 		
					}
					
		   else if(input == 3)
		   				if(clientList.empty())
							{ cout <<"Error:Cannot display empty contact list" << endl; }
						
						else{
							cout << "(Display all Contacts)"<< endl; 
					        clientList.displayList();
							}
					
		   else if(input == 4)
		   			
		   			if(clientList.empty())
						{ cout <<"Error:Cannot display specific contact from empty contact list" << endl; }
					
					else{
						cout <<"(Display Specific Contact)"<< endl;
					 	name = askName();
						if(clientList.verify(name))
						{clientList.get_ByName(name)->display();}
						
						else
					    {cout << "Error: Contact '" << name << "' not found in the contact list" << endl;}
					}
					
		
			}	
		
	return 0;
}