#include #include //#include #include #include #include #include #define SIZE 30 //Add existance of city check //returnType (*functionName)(paramType1, paramType2, ...) using namespace std; bool hyphen(char *zip); int convert(char); void enter(char places[][30],int &effective); //E,0 void search(char places[][30],int &effective); //S,1 void display(char places[][30],int &effective);//D,2 void clear(char places[][30],int &effective); //C,3 int menu(); int password(); void selection(char **,int); bool validity(char *city,char cities[][30],int effective); bool notDuplicate (char *city,char *&accessZip,int effective,char cities[][30]); bool letterCheck (char *zip,char *&accessZip,int effective,char cities[][30]); bool numberCount1 (char *zip,char *&accessZip,int effective,char cities[][30]); bool numberCount2(char *last,char *&a,int effective,char cities[][30]); bool comma(char *city, char *&comma_locus, int b,char cities[][30]); bool zipComparison(char *input, char *key); bool citComparison(char *input, char *key); int main(){ int (*startUp[])()={password,menu}; void (*actions[])(char [][30],int &)={enter,search,display,clear}; int choice; char places[6][30]={'\0'}; int effective=0; bool exit=false; //E=0,S=1,D=2,C=3,Q=4 //startUp[0](); do{ choice=startUp[1](); if(choice==4){ cout<<"Good Bye"<=0) actions[choice](places,effective); }while(!exit); system("pause"); } /******************************************************************************* purpose: takes in an menu choice and outputs the function pointer array element. input: (char)input Menu choice output: (int) pointer array element number. *******************************************************************************/ int convert(char input){ //E=0,S=1,D=2,C=3,Q=4 int output; if(input=='E') output=0; else if(input=='S') output=1; else if(input=='D') output=2; else if(input=='C') output=3; else if(input=='Q') output=4; else output=5; return output; } /******************************************************************************* purpose: if effective<6 gets the city, does this until city is valid, then increments effective. input: char cities[][30] array containing all cities int &effective number of validated elements in the array output: void *******************************************************************************/ void enter(char cities[][30],int &effective){//hereistheplace if(effective<6){ do{ cout<<"Enter Location: "; fgets(cities[effective],30,stdin); fflush(stdin); strtok(cities[effective],"\n"); }while(!validity(cities[effective],cities,effective)); effective++; } else cout<<"Array Full"<0 gets and formats a search key then searches for the string in formatted array elements input: char cities[][30] array containing all cities int &effective number of validated elements in the array output: void *******************************************************************************/ void search(char places[][30],int &effective){ bool found=false; char key[30]={'\0'}; char element[30]={'\0'}; int write=0; if(effective==0) cout<<"Nothing to Search"<0 sorts and displays data in the array input: char cities[][SIZE] array containing all cities int &effective number of validated elements in the array output: void *******************************************************************************/ void display(char places[][SIZE],int &effective){ char *sort[6]; if(effective>0){ cout<<"The cities are: "<>selection; selection=toupper(selection); cout< 0;limit--){ index_of_largest=0; for (index=1;index<=limit;index++) { if(strcmpi(*(array+index_of_largest),*(array+index))<0) index_of_largest=index; } if (limit!=index_of_largest){ temp=array[limit]; array[limit]=array[index_of_largest]; array[index_of_largest]=temp; } } } /******************************************************************************* purpose: detirmines if enter string is valid input: char *city city to be validated char cities[][SIZE] array containing all cities int effective effective size of array output: bool result of validity check *******************************************************************************/ bool validity(char *city,char cities[][SIZE],int effective){ bool(* func[])(char *, char*&,int, char [][SIZE])={comma,letterCheck,numberCount1, numberCount2,notDuplicate}; char *commaLocus; char *accessZip; bool valid; //caseunsensitive city match 95678==95674-1234 valid= func[0](city,commaLocus,effective,cities)&& //return func[1](commaLocus+1,accessZip,effective,cities)&& func[2](commaLocus+1,accessZip,effective,cities); if(valid&&*accessZip=='-') valid=func[3](accessZip+1,accessZip,effective,cities); if(valid) valid=func[4](city,accessZip,effective,cities); if(!valid) strset(city,'\0'); return valid; } /********************************************************************** purpose: detirmines checks if city has a common then modifies the location in the function that called it input: char *city city to be checked char *&comma_locus pointer to the location of the comma int c not used char d[][SIZE] not used output: bool result: true if comma is present false otherwise **********************************************************************/ bool comma(char *city, char *&comma_locus, int c,char d[][SIZE]){ bool valid=true; comma_locus=strchr(city,','); if(comma_locus==0){ cout<<"Comma needed"<4) cout<<"fewer digits"<