Hey I was looking online for a solution to a program I'm trying to write and came accross this message. I'm taking a programming class and it's getting pretty tough. I barely understand what's going on anymore. Anyway, i've been writing a program that has to be seperated into different files and i'll show you guys what i have so far. Btw, these are the requirements.
************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.***********************
With that being said I don't have much coding done because of how there's so many different approaches to this program. Just to warn whoever looks at this i'm aware that a lot of this is incomplete and a little sloppy.
This is the header file
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
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;
} Thanks for whoever looks at and helps me with my poor programming.