pacman32689
asked on
Having trouble starting to code c++ address book
Hey guys, I am having a bit of trouble starting to write a contact book program in c++. I need to use an array on structures on this one, one for every contact. I plan to have an array of integers consisting of 1s and 0s, so that when I write the file out to a binary file, I can check whether the contact at that point in the array has a 1 for write or a 0 for don't add when writing.
My questions so far are how would I be able to find what position in the array I am contact wise if I were to read in a previous contact book. ie contact[20] or contact [11] so that I would not override perviously entered contacts. Also, am I even reading in the information right? Thanks for your help
My questions so far are how would I be able to find what position in the array I am contact wise if I were to read in a previous contact book. ie contact[20] or contact [11] so that I would not override perviously entered contacts. Also, am I even reading in the information right? Thanks for your help
#include <iostream>
#include <fstream>
using namespace std;
void addContact();
void updateContact();
void deleteContact();
void printContacts();
void searchContact();
int main()
{
string fileName;
int menuChoice;
fstream fileData;
struct birthdate
int writeOrNot[250];
int counter = 0;
{
int date;
int month;
int year;
};
struct contactParameter
{
char name[50];
char cellPhoneNumber[50];
char emailAddress[50];
birthdate birthday;
enum personalOrBusiness
{
personal,
business
};
personalOrBusiness pOrBType;
};
contactParameter contact[250];
cout << "Please enter the name of the file holding your address book.\n\n";
cin >> fileName;
fileData.open(fileName.c_str());
cout << "Welcome to the address book application. Please select a task from the menu.\n\n"
<< "1) Add a new contact \n\n2) Update a contact's informantion \n\n3) Delete a contact \n\n"
<< "4) Search for a contact by name or address \n\n5) Print personal or business contacts in"
<< " aplphabetical order by name\n\n 6) Exit the Program";
cin >> menuChoice;
switch(menuChoice)
{
case 1:
addContact();
break;
case 2:
updateContact();
break;
case 3:
deleteContact();
break;
case 4:
searchContact();
break;
case 5:
printContacts();
break;
case 6:
exit(1);
break;
default:
cout << "You have entered an invalid choice, please enter a valid integer based on your menu choice.";
main();
break;
}
}
void addContact()
{
cout << "To create a new contact, enter the appropriate information as you are prompted. If you are unsure of something,"
<< " just press enter.\n\n";
cout << "Name?\n\n";
cin.getline(contact[counter].name,50);
cout << "Cellphone number?\n\n";
cin.getline(contact[counter].cellPhoneNumber,50);
cout << "Email address?\n\n";
cin.getline(contact[0].emailAddress,50);
cout << "Birthday day?\n\n";
cin.getline(contact.birthday.date,50);
cout << "Birthday month?\n\n";
cin.getline(contact.birthday.month,50);
cout << "Birthday year?\n\n";
cin.getline(contact.birthday.year,50);
cout << "Contact type?\n\n";
cin.getline(contact.contactType,50);
contact++;
}
void updateContact()
{
}
void deleteContact()
{
}
void searchContact()
{
}
void printContact()
{
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
ASKER
Open in new window