#include #include #include #include #include #include #include #include #include #include #include #include #include struct info { char name[50], hphone[50], wphone[50], cellphone[50], beeper[50], zip[50]; char street[50], city[50], state[50], company[50], email[50], fax[50]; }; void add(info[], int &end); void del(info[], int &end); void display(info[], int end); void alpha(info[], int end); void edit(info[], int end); void saveit2(info[], char name[30], int end); //This is the main function of the program void main() { clrscr(); char name[30],dummy[50],dummy2[50],tempnum[50]; int x,end,ans; info file[100]; cout<<"\nWelcome to Jason and Scott's Address Book !!"; cout<<"\n********************************************"; cout<<"\n\nPlease enter your name:(IN CAPS) "; cin>>name; strcat(name,".TXT"); strcpy(dummy2,"A:"); strcat(dummy2,name); ifstream thefile; thefile.open (dummy2,ios::in); if (thefile) { x = 0; thefile.getline(dummy,50); thefile.getline(file[x].name,50); thefile.getline(file[x].street,50); thefile.getline(file[x].city,50); thefile.getline(file[x].state,50); thefile.getline(file[x].zip,50); thefile.getline(file[x].hphone,50); thefile.getline(file[x].wphone,50); thefile.getline(file[x].fax,50); thefile.getline(file[x].cellphone,50); thefile.getline(file[x].beeper,50); thefile.getline(file[x].email,50); thefile.getline(file[x].company,50); //Loads from textfile while (!thefile.eof()) { x = x + 1; thefile.getline(file[x].name,50); thefile.getline(file[x].street,50); thefile.getline(file[x].city,50); thefile.getline(file[x].state,50); thefile.getline(file[x].zip,50); thefile.getline(file[x].hphone,50); thefile.getline(file[x].wphone,50); thefile.getline(file[x].fax,50); thefile.getline(file[x].cellphone,50); thefile.getline(file[x].beeper,50); thefile.getline(file[x].email,50); thefile.getline(file[x].company,50); } thefile.close(); end = x; } else { ofstream outfile; //declares a file to be written end = -1; outfile.open (dummy2, ios::out); //note ios::out if (outfile) { outfile<> ans; switch(ans) { case(1): add(file, end); break; case(2): del(file, end); break; case(3): display(file, end); break; case(4): alpha(file, end); break; case(5): edit(file, end); break; } } while (ans != 99); saveit2(file, name, end); } //This function adds a name into the address book void add(info file[], int &end) { int x; end = end + 1; x = end; clrscr(); cout<<"\n\nEnter '/' if not available. "; cout<<"\nName: "; gets(file[x].name); cout<<"Address: "; gets(file[x].street); cout<<"City: "; gets(file[x].city); cout<<"State: "; gets(file[x].state); cout<<"Zip: "; cin>>file[x].zip; cout<<"Home Phone: "; gets(file[x].hphone); cout<<"Work Phone: "; gets(file[x].wphone); cout<<"Fax: "; gets(file[x].fax); cout<<"Cell Phone: "; gets(file[x].cellphone); cout<<"Beeper: "; gets(file[x].beeper); cout<<"E-Mail: "; gets(file[x].email); cout<<"Company: "; gets(file[x].company); if ((strcmp("/", file[x].name)==0)) strcpy(file[x].name, "N/A"); if ((strcmp("/", file[x].street)==0)) strcpy(file[x].street, "N/A"); if ((strcmp("/", file[x].city)==0)) strcpy(file[x].city, "N/A"); if ((strcmp("/", file[x].state)==0)) strcpy(file[x].state, "N/A"); if ((strcmp("/", file[x].zip)==0)) strcpy(file[x].zip, "N/A"); if ((strcmp("/", file[x].hphone)==0)) strcpy(file[x].hphone, "N/A"); if ((strcmp("/", file[x].wphone)==0)) strcpy(file[x].wphone, "N/A"); if ((strcmp("/", file[x].fax)==0)) strcpy(file[x].fax, "N/A"); if ((strcmp("/", file[x].cellphone)==0)) strcpy(file[x].cellphone, "N/A"); if ((strcmp("/", file[x].beeper)==0)) strcpy(file[x].beeper, "N/A"); if ((strcmp("/", file[x].email)==0)) strcpy(file[x].email, "N/A"); if ((strcmp("/", file[x].company)==0)) strcpy(file[x].company, "N/A"); } //This function deletes a name from the address book void del(info file[], int &end) { int x; int choice; clrscr(); for(x=0;x<=end;x++) { cout<>choice; clrscr(); for(x=(choice-1);x<=end;x++) { file[x]=file[x+1]; } end = end - 1; } //This function displays all the info in the address book void display(info file[], int end) { int x; for (x=0;x<=end;x++) { clrscr(); cout<<"\nName: "<0) { temp2=file[x]; file[x]=file[y]; file[y]=temp2; } } } clrscr(); getch(); } //This function edits any info you want in the address book void edit(info file[], int end) { int whatever,x,answer; char name[50]; clrscr(); cout<<"\n\nPlease enter a name you would like to edit: "; gets(name); for (x=0; x<=end; x++) { if (strcmp(name,file[x].name) == 0) whatever = x; } cout<<"\n1.)Name: "<>answer; if (answer == 1) { cout<<"\nName: "; gets(file[whatever].name); } if (answer == 2) { cout<<"\nAddress: "; gets(file[whatever].street); } if (answer == 3) { cout<<"\nCity: "; gets(file[whatever].city); } if (answer == 4) { cout<<"\nState: "; gets(file[whatever].state); } if (answer == 5) { cout<<"\nZip Code: "; gets(file[whatever].zip); } if (answer == 6) { cout<<"\nHome Phone: "; gets(file[whatever].hphone); } if (answer == 7) { cout<<"\nWork Phone: "; gets(file[whatever].wphone); } if (answer == 8) { cout<<"\nFax Number: "; gets(file[whatever].fax); } if (answer == 9) { cout<<"\nCellphone: "; gets(file[whatever].cellphone); } if (answer == 10) { cout<<"\nBeeper: "; gets(file[whatever].beeper); } if (answer == 11) { cout<<"\nEmail: "; gets(file[whatever].email); } if (answer == 12) { cout<<"\nCompany: "; gets(file[whatever].company); } } //This function saves the address book void saveit2(info file[], char name[30], int end) { int x; char dummy[50], dummy2[50]; strcpy(dummy, name); strcpy(dummy2,"A:"); strcat(dummy2,name); ofstream outfile; outfile.open (dummy2, ios::out); if (outfile) { outfile<