//richard hankins
//A Simple/Advanced Word Processor
//includes
#include
#include
#include
#include
#include
/* NO I WILL NOT SEND YOU this HEADER */
//structs
struct AddressRecord{
char firstName[21];
char lastName[21];
char address[51];
char city[31];
char state[3];
char zip[11];
char homePhone[14];
//I changed this to a char
//you said to do it as an int but
//a char takes up 1 byte per char and a int takes up 4
//so if i do a integer it is 4+4+4 = 12
//whereas a string2 + 2 + 4 = 8 so I am saving memory (or i think i am)
//plus it works better for me this way.
char birthMonth[3];
char birthDay[3];
char birthYear[5];
};
//prototypes
void deleteRecord();
void searchIT(int);
short showMenu();
void closeProgram();
void showRecord(int);
void addNewRecord();
void write2file(AddressRecord);
void viewRecord();
void loadArray(AddressRecord[],int);
int countRec();
void printRecord(int);
void printOptions();
void resaveALL();
void splashScreen();
void showMainMenu();
//set up some globals that you OKed
int count = 0;
AddressRecord addBook[50];
char locFile[14] = "D:ADDRESS.DAT";
short bookStyle = 3;
//programmer defined stuff
void main(){
InitConsole(); //start up the cool stuff you gave us
//start loading arrays
count = countRec();
loadArray(addBook,count);
//show the start sequence
splashScreen();
//start the loop
short choice = 0;
do{
choice = showMenu();
//switch here
switch(choice){
case 1:addNewRecord();break;
case 2:viewRecord();break;
case 3:deleteRecord();break;
case 4:printOptions();break;
case 5:showMainMenu();break;
}//end switch
}while(choice != 0);
closeProgram();
}//end main
short showMenu(){
short choice=0;
clrscr();
//cout << showMainMenu();
cout << "********************************************************************************";
cout << " ************************ MAIN MENU ************************\n";
cout << " ****************************************************************************\n";
cout << "********************** 1) Enter new Address Record **********************\n";
cout << "********************* 2) View And Existing Record *********************\n";
cout << " ******************** 3) delete an Existing Record ********************\n";
cout << " ******************* 4) Print Options *******************\n";
cout << "****************** 5) Change Book Style ******************\n";
cout << "***************** 0) Close Record Book *****************\n";
cout << " **************************************************************\n";
cout << " Make your selection now: ";
cin >> choice;
return choice;
}//end showMenu
void addNewRecord(){
AddressRecord theRec;//for the struct
int count1 = 0;//for the count in the loop
cout << "How many records would you like to add: ";
cin >> count1;
while (count1 != 0){
cin.ignore(100,'\n');
cout << "First Name: ";
cin.get(theRec.firstName,21,'\n');
cin.ignore(100,'\n');
cout << "Last Name: ";
cin.get(theRec.lastName ,21,'\n');
cin.ignore(100,'\n');
cout << "Street Address: ";
cin.get(theRec.address ,51,'\n');
cin.ignore(100,'\n');
cout << "City: ";
cin.get(theRec.city,31,'\n');
cin.ignore(100,'\n');
cout << "State[example: TX, AL, OK]: ";
cin.get(theRec.state,3,'\n');
cin.ignore(100,'\n');
cout << "Zip Code: ";
cin.get(theRec.zip,11,'\n');
cin.ignore(100,'\n');
cout << "Home Phone Number[example: (XXX)XXX-XXXX]: ";
cin.get(theRec.homePhone ,14,'\n');
cin.ignore(100,'\n');
cout << "Birth Month[example: 01 for January, 10 for October]: ";
cin.get(theRec.birthMonth ,3,'\n');
cin.ignore(100, '\n');
cout << "Birth Day: ";
cin.get(theRec.birthDay,3,'\n');
cin.ignore(100,'\n');
cout << "Four Digit Birth Year: ";
cin.get(theRec.birthYear,5,'\n');
cin.ignore(100,'\n');
//call write file
write2file(theRec);
count1= count1 -1;
if(count1 != 0)
cout << "\n **Press Enter To Input the Next Contact** \n";
//end if
count++;
}//end while
count = countRec();
loadArray(addBook,count);
}//end addNewRecord
void viewRecord(){
int choice = 1;
while(choice != 0){
clrscr();
cout << "********************************************************************************";
cout << " ************************* VIEW MENU ************************\n";
cout << " ****************************************************************************\n";
cout << "*********************** 1) View Record By First Name**********************\n";
cout << "********************** 2) View Record By Last Name *********************\n";
cout << " ********************* 3) View Record By State ********************\n";
cout << " ******************** 4) View Record By City *******************\n";
cout << "******************* 5) View Record By Zip******************\n";
cout << "****************** 0) Cancel View and Return*****************\n";
cout << " **************************************************************\n";
cout << " Make your selection now: ";
cin >> choice;
switch(choice){
case 1: searchIT(1);break;
case 2: searchIT(2);break;
case 3: searchIT(4);break;//i got city and state backward
case 4: searchIT(3);break;//so these got switched to correct it
case 5: searchIT(5);break;
case 0: ;break;
default: cout << "Invalid Option";break;
}//end switch
}//end while
//go main
return;//go back into main
}//end viewRecs
void write2file(AddressRecord theRec){
ofstream outFile;
outFile.open(locFile,ios::app);
if(!outFile.fail())//it is all good so far
outFile << theRec.firstName << "#" << theRec.lastName << "#" << theRec.address << "#" << theRec.city << "#" << theRec.state<< "#" << theRec.zip<< "#" << theRec.homePhone << "#" << theRec.birthMonth<< "#" << theRec.birthDay<< "#" << theRec.birthYear << "\n";
else //what to do on a fail
cout << "File Error - Data Was Not Saved";
//end else and if
outFile.close();//close the file
}//end that
void loadArray(AddressRecord theRec[],int size){
ifstream inFile;
inFile.open(locFile,ios::in);
if(!inFile.fail()){//what to do on load
for(int x = 0; x < size ; x++){
inFile.getline(theRec[x].firstName,21,'#');
inFile.get(theRec[x].lastName,21,'#');
inFile.ignore (1);
inFile.get(theRec[x].address,51,'#');
inFile.ignore (1);
inFile.get(theRec[x].city,31,'#');
inFile.ignore (1);
inFile.get(theRec[x].state,3,'#');
inFile.ignore (1);
inFile.get(theRec[x].zip,11,'#');
inFile.ignore (1);
inFile.get(theRec[x].homePhone,14,'#');
inFile.ignore (1);
inFile.get(theRec[x].birthMonth,3,'#');
inFile.ignore (1);
inFile.get(theRec[x].birthDay,3,'#');
inFile.ignore (1);
inFile.get(theRec[x].birthYear,5,'\n');
inFile.ignore (1);
}//end for
}//end while !fail
else{
clrscr();
cout << "There was an error encountered while trying" << endl
<< "to open the address book database.\n\n\n" << endl;
}//end else of the if
inFile.close();
}//end the whole thing
void searchIT(int theCode){
//this is the variable for the string to search for
char strStrin[51] = " ";
int x = 0;
short aryNums[50] = {0};
short cnt = 0;
char choice = ' ';
//do a switch to see what we are looking for
switch(theCode){
case 1:
cout << "Please enter the First Name you would like to search for: ";
cin.ignore(100,'\n');
cin.getline(strStrin,20,'\n');
for (x=0; x < count; x++){
if(stricmp(strStrin, addBook[x].firstName) == 0){
aryNums[cnt] = x;
cnt++;
}//end if
}//end for
break;
case 2:
cout << "Please enter the Last Name you would like to search for: ";
cin.ignore(100,'\n');
cin.getline(strStrin,20,'\n');
for (x=0; x < count; x++){
if(stricmp(strStrin, addBook[x].lastName) == 0){
aryNums[cnt] = x;
cnt++;
}//end if
}//end for
//do an if to see if there is only 1 matching record
break;
case 3:
cout << "Please enter the City you would like to search for: ";
cin.ignore(100,'\n');
cin.getline(strStrin,20,'\n');
for (x=0; x < count; x++){
if(stricmp(strStrin, addBook[x].city ) == 0){
aryNums[cnt] = x;
cnt++;
}//end if
}//end for
break;
case 4:
cout << "Please enter the State Abbreviation you would like to search for: ";
cin.ignore(100,'\n');
cin.getline(strStrin,20,'\n');
for (x=0; x < count; x++){
if(stricmp(strStrin, addBook[x].state) == 0){
aryNums[cnt] = x;
cnt++;
}//end if
}//end for
break;
case 5:
cout << "Please enter the Zip Code you would like to search for: ";
cin.ignore(100,'\n');
cin.getline(strStrin,20,'\n');
for (x=0; x < count; x++){
if(stricmp(strStrin, addBook[x].zip ) == 0){
aryNums[cnt] = x;
cnt++;
}//end if
}//end for
break;
case 0: /* do nothing */;break;
default: /* do nothing */;break;
}//end switch
//do an if to see if there is only 1 matching record
if(cnt == 0){
clrscr();//clear the screen
cout << "Sorry No Records Match Your Criteria\n";
cin.ignore(0);
getch();
cin.ignore(100,'\n');
}//end if
else{
if(cnt == 1)
showRecord(aryNums[0]);
else{
clrscr();//clear the screen
cout << "There were multiple records matching your criteria!\n"
<< "please select one of the following records to view.\n";
//do a for loop to go thru the records
for(x = 0; x < cnt; x++)
cout << x + 1 << ") " << addBook[aryNums[x]].lastName << ", " << addBook[aryNums[x]].firstName << endl;
//end that one liner (for)
}//end else
}//end the big mother else
// ok since we are done with the variable cnt I am going to make it useful
// memory recycling even
if(cnt > 0){
if(cnt > 1){
cout << "\nWhich Record Would You Like To View(0 for none): ";
cin >> cnt;
if(cnt != 0)
showRecord(aryNums[cnt - 1]);
//end if
}//end if > 0
}//end if > 0
}//end void searchIT
void showRecord(int x){
char choice = ' ';
switch(bookStyle){//start a select case of the book styles
case 1: {
cout << "\n " << addBook[x].lastName << ", " << addBook[x].firstName << " \t" << addBook[x].homePhone << endl;
}break;
case 2: {
cout << "\n First Name: " << addBook[x].firstName;
cout << "\n Last Name: " << addBook[x].lastName;
cout << "\n Street Address: " << addBook[x].address;
cout << "\nCity: " << addBook[x].city;
cout << "\n State: " << addBook[x].state;
cout << "\nZip Code: " << addBook[x].zip;
}break;
case 3:{
cout << "\n First Name: " << addBook[x].firstName;
cout << "\n Last Name: " << addBook[x].lastName;
cout << "\n Street Address: " << addBook[x].address;
cout << "\nCity: " << addBook[x].city;
cout << "\n State: " << addBook[x].state;
cout << "\nZip Code: " << addBook[x].zip;
cout << "\nPhone Number: " << addBook[x].homePhone;
cout << "\nBirthDay: " << addBook[x].birthMonth <<"/"< }break; }//END THE switch //see if they want to print this out cout << "\nWould you like to print this Contact Information(enter a Y to print): "; cin >> choice; if(toupper(choice) == 'Y') printRecord(x); //end if }//end showRecord int countRec(){ //this is just a sub i made to count the records on load that way //i can easily call the load array function int x = 0; ifstream inFile; inFile.open(locFile,ios::in); if(!inFile.fail()){ while(!inFile.eof()){ inFile.ignore(1000,'\n'); inFile.ignore(1); x = x + 1; }//end while }//end if inFile.close();//close the infile return x; }//end sub void printOptions(){ //this here is all the options that you can print int choice = 0; //ofstream prn("PRN"); int x = 0; do{ clrscr(); // clear that darned screen cout << "*******************************************************************************\n"; cout << " ************************ PRINT MENU ************************\n"; cout << " ***************************************************************************\n"; cout << "********************** 1) Phone List**********************\n"; cout << "********************* 2) Names List*********************\n"; cout << " ******************** 3) Birthday List********************\n"; cout << " ******************* 4) Address List *******************\n"; cout << "****************** 0) return To Main Menu ******************\n"; cout << "***************************************************************\n"; cout << " Make your selection now: "; cin >> choice; switch(choice){ case 1: //change to print for(x = 0; x cout << addBook[x].firstName << " " < << addBook[x].homePhone << " " << endl; }//end for cin.ignore(0); getch(); cin.ignore(100,'\n'); break; case 2: //change to print for(x = 0; x cout << addBook[x].firstName << " " < }//end for cin.ignore(0); getch(); cin.ignore(100,'\n'); break; case 3: //change to print for(x = 0; x cout << addBook[x].firstName << " " < << addBook[x].birthMonth << "/" << addBook[x].birthDay << "/" << addBook[x].birthYear; }//end for cin.ignore(1); getch(); cin.ignore(100,'\n'); break; case 4: //change to print for(x = 0; x cout << addBook[x].firstName << " " < << addBook[x].address << "\n\t" << addBook[x].city << ", " << addBook[x].state << " " << addBook[x].zip << "\n\n"; }//end for cin.ignore(0); getch(); cin.ignore(100,'\n'); break; }//end switch }while(choice != 0); //do until 0 //when enters a zero return; //go main }//end print options void printRecord(int x){ //this here prints a record of your choice //be sure and change me to print ofstream prn("PRN"); prn << addBook[x].firstName << " " << addBook[x].lastName << endl; prn << addBook[x].address << endl; prn << addBook[x].city << ", " << addBook[x].state << " " << addBook[x].zip << endl; prn << "\nHome Phone: " << addBook[x].homePhone; prn << "\n Birthday: " << addBook[x].birthMonth << "/" << addBook[x].birthDay << "/" << addBook[x].birthYear << endl; prn << "\f";//send the spit paper out command }//end print void deleteRecord(){ short recNum =0; cout << "Which Record Would You Like To Delete?\n"; if(count < 21){//see if there is more than 20 lines{ for(short i = 0; i < count; i++){ cout << i + 1 << ") " << addBook[i].firstName << " " << addBook[i].lastName << endl; }//end for }//end the if count less than 21 else{ char isIT = ' '; for(short x = 0; x < 20;x++) cout << x + 1 << ") " << addBook[x].firstName << " " << addBook[x].lastName << endl; //end for cout << "Is the record you wish to delete in this set(Y or N): "; cin >> isIT; if(toupper(isIT) != 'Y'){ for(x;x cout << x + 1 << ") " << addBook[x].firstName << " " << addBook[x].lastName << endl; }//end for }//end if }//end else //see what we want to delete cout << "\n Which Record Would You Like To Delete(0 for none): "; cin >> recNum; if(recNum != 0){ recNum--;//set back one since index starts at 0 //I find it much easier to move the last record to the deleted spot then //to go throught the process time to move all of em strcpy(addBook[recNum].firstName,addBook[count -1].firstName); strcpy(addBook[recNum].lastName , addBook[count -1].lastName); strcpy(addBook[recNum].address , addBook[count -1].address); strcpy(addBook[recNum].city , addBook[count -1].city); strcpy(addBook[recNum].state , addBook[count -1].state); strcpy(addBook[recNum].zip , addBook[count -1].zip); strcpy(addBook[recNum].birthDay , addBook[count -1].birthDay); strcpy(addBook[recNum].birthMonth , addBook[count -1].birthMonth); strcpy(addBook[recNum].birthYear , addBook[count -1].birthYear); strcpy(addBook[recNum].homePhone , addBook[count -1].homePhone); count--; //set the count back one since we just deleted }//end if return; }//end sub void resaveALL(){ //'delete the file //this was the hardest thing to figure out :o ofstream clrFile; clrFile.open(locFile,ios::out); clrFile.clear(); clrFile.close(); //save it for(int i = 0; i < count; i++){ write2file(addBook[i]); }//end for }//end void save all void splashScreen(){ char i = ' '; cout << "\n\n"; cout << ".?;;;;;? .?.? \n"; cout << ";;;¡ä¡ä ¡ä¡ä¡ä ;;: ;;: \n"; cout << " .;; .?;;;;?. ;;?;;;;?.;;;;;..?;;;??;; .?;;;;?.;;;;;\n"; cout << " ;;:.;;¡ä ¡ä;;. ;;::;; ;;: .;;¡ä ¡ä;;; .;;¡ä ¡ä¡ä ;;: \n"; cout << " ¡ä;;;;::;; ;;::;; ;;: ;;::;; ;;:;;: \n"; cout << "¡ä;;?. .?? ¡ä;;? ?;;¡ä ;;::;; ;;: ¡ä;;? ?;;; ¡ä;;? .?. ;;: \n"; cout << "¡ä¡ä::;::¡ä ¡ä¡ä:;;:¡ä¡ä :;¡ä¡ä;: :;¡ä ¡ä¡ä:;:¡ä¡ä;: ¡ä¡ä:;;:¡ä :;¡ä \n"; cout << endl; cout << " ;;.\n"; cout << " ;;:\n"; cout << " ;;: .?;;;;?. .?;;;??;;\n"; cout << " ;;:.;;¡ä ¡ä;;..;;¡ä ¡ä;;;\n"; cout << " ;;:;;::;;;;::;;\n"; cout << " ;;:¡ä;;? ?;;¡ä¡ä;;? ?;;;\n"; cout << " ¡ä;;;;;: ¡ä¡ä:;;:¡ä¡ä ¡ä:;;:¡ä:;;\n"; cout << " .??. ?;;¡ä\n"; cout << "¡ä:;;;:¡ä¡ä\n"; cout << endl; cout << " Coded By Richard Hankins "; cout << "\n ** Press Enter To continue **\n"; cin.ignore(0); // just so the getch does not kill the previous cout getch(); cin.ignore(100,'\n'); clrscr(); }//end splash void closeProgram(){ clrscr();//this messed up on me 3 times where it would not clear clrscr();// so i do it 2 times to make sure resaveALL(); cout << " ? ?\n"; cout << " ;;;;;;;;? ;;:;;: \n"; cout << " ;;:;;:;;: \n"; cout << " ;;:;;;;;;;? .?;;;??;; ;;?;;;;? ;;: ?;. \n"; cout << " ;;:;;::;;.;;¡ä ¡ä;;; ;;::;; ;;;?;:¡ä \n"; cout << " ;;:;;::;;;;::;; ;;::;; ;;:;;?\n"; cout << " ;;:;;::;;¡ä;;? ?;;; ;;::;; ;;: ¡ä;;. \n"; cout << " :;¡ä:;¡ä¡ä;: ¡ä¡ä:;:¡ä¡ä;: :;¡ä¡ä;: :;¡ä ¡ä:; \n"; cout << "\n"; cout << ".;;.;;\n"; cout << ":;; .;;¡ä\n"; cout << " ¡ä;;;;;¡ä.?;;;;?. ;;..;; \n"; cout << " ¡ä;;:.;;¡ä ¡ä;;. ;;::;; \n"; cout << ";;:;;::;; ;;::;; \n"; cout << ";;:¡ä;;? ?;;¡ä :;;;;: \n"; cout << ":;¡ä ¡ä¡ä:;;:¡ä¡ä¡ä:;;;:¡ä\n"; }//end close splash void showMainMenu(){ short choice = 0; clrscr(); // clear that darned screen cout << "*******************************************************************************\n"; cout << " ************************ BOOK MENU ************************\n"; cout << " ***************************************************************************\n"; cout << "********************** 1) Phone Book**********************\n"; cout << "********************* 2) Address Book *********************\n"; cout << " ******************** 3) All Info ********************\n"; cout << " ******************* 0) return To Main Menu *******************\n"; cout << "*****************************************************************\n"; cout << "Make your selection now: "; //get their choice cin.ignore(100,'\n'); cin >> choice;