![]() |
| ||
| Problems in Address book programming My code for address book is as follows: #include <iostream>The problems I face are: 1> In input one of the entries is overlapped with another, as in if employee.postal==570306 employee. address== employee.postal 2> In outputting (printing) what happens is that one of the data is not printed. Same with gets(). I used it twice, otherwise it was inputting only 4 things. I think 1 and 2 might have a connection. Can someone suggest me what to do, so that I can debug other numerous problems? Thanks. |
| ||
| Re: Problems in Address book programming Well, postal is a character array, as is address, so you can't use the == operator to do comparisons. strcmp should do it though. I assume you don't realise that you can pass a structure directly into a function as a parameter. struct thing{which should save all those parameters going into your function. A structure, basically, is a type which tidies up all that messy parameter passing. And as it's a defined type you can pass it into a function.You might also consider using the std::string (from <string>). It allows == comparison which character arrays do not. Again, tidy way of doing things. There are also better alternatives to system("pause") |
| ||
| Re: Problems in Address book programming Hey I'm writing an address program as well. If anyone could help me with it i'd greatly appreciate it. I'm aware of how terrible looking it is but if someone can decipher what's going on in my program and try to help me that'd be much appreciated. These are the requierments: ************Read “AddressBook.txt” file (if the file exists) Module: Insert each entry into the array of structures by name a. First record (line) contains the number of entries b. Entry consists of the following information Name (maximum 30 characters) BirthDate (mm/dd/yyyy) Address Information Type (maximum 8 characters: Friend, Family, Business) c. Address Information consists of the following information: Street (maximum 35 characters) City (maximum 20 characters) State (2 characters) Zip (5 characters) Phone (14 characters) 4) User can choose the following options: a. List all entries. This option will result in an alphabetic list. b. Look up a specific entry by Name (use binary search). Ask user for the desired name. Output error message if the name is not found otherwise output the information. c. List all the entries for a specific Type. Ask user for the desired type (Friend, Family, Business). Output the type followed by all the entries that match this type (i.e. Friend). This will also result in an alphabetic listing.*********************** Unfortunately this i sall i have so far... cplusplus Syntax (Toggle Plain Text) int NAME_LENGTH; int BIRTHDAY_LENGTH; int ADDRESS_LENGTH; int MAX_LISTING; char relation [relation_+1]; struct addressType { string street; string city; string state; string zip; string phone; }; struct contactType { char name[NAME_LENGTH]; int Bday; addressType address; char relation; }; contactType newContact; contactType contacts[100]; void inputName (ifstream &, char , nameType &);void inputBday (ifstream &, int , BdayType &); void inputAddress (ifstream &, int , addressType &);void inputRelation (ifstream &, char , relationType &); int extern search (const nameType [], char, const char *);int NAME_LENGTH; int BIRTHDAY_LENGTH; int ADDRESS_LENGTH; int MAX_LISTING; char relation [relation_+1]; struct addressType { string street; string city; string state; string zip; string phone; }; struct contactType { char name[NAME_LENGTH]; int Bday; addressType address; char relation; }; contactType newContact; contactType contacts[100]; void inputName (ifstream &, char , nameType &); void inputBday (ifstream &, int , BdayType &); void inputAddress (ifstream &, int , addressType &); void inputRelation (ifstream &, char , relationType &); int extern search (const nameType [], char, const char *); This is the main Help with Code Tags cplusplus Syntax (Toggle Plain Text) int main (){ int numNames, numBdays, numAdds, index, location; char searchArg[birthday_LENGTH+1]; ifstream infile; ofstream outfile; contactType allcontact[MAX_CONTACTS] infile.open (".AddressBook.txt"); assert (!infile.fail()); outfile.open ("./contacts.txt"); assert (!outfile.fail()); inputName (); inputBday (); searchArg[birthday_LENGTH] = '\0'; while (true) { cout << "\n\nEnter a Birthday(mm/dd/yyyy) or 0000000 to end: "; cin >> searchArg; if (strcmp (searchArg, "0000000") == 0) break;} infile.close(); And this one I think is the input for (int j = 0; j < 100; j++) cin >> contacts[j].name.first >> contacts[j].name.middle >> contacts[j].name.last; for (int j = 0; j < 100; j++) cin >> contacts[j].Bday.month >> contacts[j].Bday.day >> contacts [j].Bday.year; for (int j = 0; j < 100; j++) cin >> contacts[j].address.street >> contacts[j].name.state >> contacts[j].address.zip >> contacts[j].address.phone; for (int j = 0; j < 100; j++) cin >> contacts[j].relation.Friend >> contacts[j].relation.Family >> contacts[j].relation.business; I know that this needs a lot of changes.I also have an example of binary coding so if sum1 could show me where my information would go that would be appreciated as well. int search (const studentType list[], int length, const char * searchArg){ bool found = false; int low = 0, high = length-1, mid; while (!found && low <= high) { mid = (low + high) / 2; if (strcmp(searchArg, list[mid].ID) == 0) found = true; else if (strcmp(searchArg, list[mid].ID) < 0) high = mid - 1; else low = mid + 1; } if (found) return mid; else return -1;} int main () { int numNames, numBdays, numAdds, index, location; char searchArg[birthday_LENGTH+1]; ifstream infile; ofstream outfile; contactType allcontact[MAX_CONTACTS] infile.open (".AddressBook.txt"); assert (!infile.fail()); outfile.open ("./contacts.txt"); assert (!outfile.fail()); inputName (); inputBday (); searchArg[birthday_LENGTH] = '\0'; while (true) { cout << "\n\nEnter a Birthday(mm/dd/yyyy) or 0000000 to end: "; cin >> searchArg; if (strcmp (searchArg, "0000000") == 0) break; } infile.close(); And this one I think is the input for (int j = 0; j < 100; j++) cin >> contacts[j].name.first >> contacts[j].name.middle >> contacts[j].name.last; for (int j = 0; j < 100; j++) cin >> contacts[j].Bday.month >> contacts[j].Bday.day >> contacts[j].Bday.year; for (int j = 0; j < 100; j++) cin >> contacts[j].address.street >> contacts[j].name.state >> contacts[j].address.zip >> contacts[j].address.phone; for (int j = 0; j < 100; j++) cin >> contacts[j].relation.Friend >> contacts[j].relation.Family >> contacts[j].relation.business; I know that this needs a lot of changes. I also have an example of binary coding so if sum1 could show me where my information would go that would be appreciated as well. int search (const studentType list[], int length, const char * searchArg) { bool found = false; int low = 0, high = length-1, mid; while (!found && low <= high) { mid = (low + high) / 2; if (strcmp(searchArg, list[mid].ID) == 0) found = true; else if (strcmp(searchArg, list[mid].ID) < 0) high = mid - 1; else low = mid + 1; } if (found) return mid; else return -1; } It is greatly apreciated if this is at least looked at. If for any reason this doesn't look like what programs posted should I can't figure out why because i copied a version that someone modified for me to model mine after when posting. Thanks again. |
| ||
| Re: Problems in Address book programming Thanks for the advice. I am working on it. |
| All times are GMT -4. The time now is 3:24 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC