Solved

Having trouble starting to code c++ address book

Posted on 2007-12-01
3
1,236 Views
Last Modified: 2010-05-02
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

#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()
{
 
}

Open in new window

0
Comment
Question by:pacman32689
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:pacman32689
ID: 20389879
Would a statement like this find what is the next blank spot in the address book?
	for(int i = 0; i< 250; i++)
	{
		if(contact[i].name == 0)
		{
			count = i;
		}
	}

Open in new window

0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 20390025
you should put the struct declaration outside the main() function.
Inside your main struct, you can use a boolean value to determine if the struct data is valid or should be saved:

      struct contactParameter
      {
                                bool validData;    // <------------- add this
            char name[50];
            char cellPhoneNumber[50];
            char emailAddress[50];
            birthdate birthday;
            enum personalOrBusiness {personal, business};
            personalOrBusiness pOrBType;
      };            

so you can evaluate as:
                 for (int i = 0; i< 250; i++)
      {
            if (!contact[i].validData)
            {
                  count = i;
                  break;   // don't continue searching
            }
      }
0
 

Author Closing Comment

by:pacman32689
ID: 31412148
Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question