hye..can somebody help me with these problems as soon as possible?? really need your guys help
Create a phone book program that allows users to enter names and phone numbers of friends and acquaintances. Create a structure to hold contact information .The user should be able to add phone book entries through a menu in a loop. Your structure should hold first name, last name, email address, and phone number.

Hint: Your main program should create a structure in by using example below.

typedef struct contact {
char first_name[20];
char last_name[20];
char email[20];
char phone[10];
} c;


2. Create the ability to edit contact information for a person (Add it to your menu). Ask the user for the first name, last name of the contact to edit. Search through your array and find the item. If the person is not in the list, then print a message to the user saying that. If the person is in the list, ask them for the new email address and phone number and update the structure accordingly.


3. Add the ability (another menu option) to save your contact information to a file. The data should be stored as name email address phone number

No effort == no help.

kthxbye.

Put $5,000.00 USD in my PayPal account and I'll write it for you.

please help me.i am the first year student in the programming course.i am absolutely not understand it.please give me a hint?

If you don't understand the requirements, ask a specific question instead of vague requests for "hints" and "help".

i am the first year student in the programming course.i am absolutely not understand it.

Teachers don't give an assignment without first covering the necessary material in class for completing the assignment. If you didn't pay attention in class and are now clueless as to how to do your homework, that's your own damn problem.

Rather than complaining about what you don't know, let's look at what you do know, and start with that.

  • You need to write a main() function.
  • You need to define a structure type that holds a person's contact information. An example of what this should look like was given to you by the teacher.
  • You need to declare at least one variable of said struct type. Again, an example of this was included in the sample code.
  • You need to present a menu for the user to choose from.
  • You need to be able to read in a person's contact information from the console, and put it into the Contact structure.
  • You need to put the menu in a loop so that it repeats the menu.

All of these things should have been covered in your classwork. Is there any part of it you are having trouble with?

it is like this?

#include <iostream>
using namespace std;
int main ()

{
struct phonebook

string firs_name
string last_name
char email
char phone_no

}

what should i do next?

Close -- read the instructions more carefully

#include <iostream>
using namespace std;

struct phonebook
{
    char firs_name[20];
    char last_name[20];
    char email[20];
    char phone_no[10];
};


int main ()

{ 

}

what do (20) stands for?i'm still confused with these

The '[20]' values (note the square brackets, as opposed to parentheses, that's important) are the array sizes. When you write

char myArray[20];

what you are declaring is an array of size 20. When you then write

char ch = myArray[4];

you are then assigning the 5th value in the array (not fourth - array indices start at 0) to the character variable ch .

The reason you use character arrays for the character strings is because a plain char value can only hold one character at a time. So if you need to store the name 'John', you need to have an array capable of holding each of the letters in the name, plus one for the NULL Marker (a special character used to indicate the end of the string). By declaring the array to have size 20, you are giving it enough room for most personal names.

#include<iostream>
using namespace std;
void showSelection()
void selectItem()
int main()

{
 int choice;
 showSelection();
 cin>>choice;
 
 while (choice !=9)
 {
       switch (choice)
 {
       case 1:
            selectItem (list);
       case 2:
            selectItem (edit);
       case 3:
            selectItem (search);
       case 4:
            selectItem (exit);
       
            break;
            default:
                    cout<<"Invalid selection."<<endl;
 }
 showSelection();
 cin>> choice;
}
return 0;
}     
              
       char first_name[20];
       char last_name[20];
       char email[20];
       char phone_no[20];
}


void showSelection()
{
     cout<<"*** welcome to my phonebook system ***"<<endl;
     cout<<"To select an item, enter "<<endl;
     cout<<"1 for list : "<<endl;
     cout<<"2 for edit "<<endl;
     cout<<"3 for search "<<endl;
     cout<<"9 for exit "<<endl;
     
     system("pause");
     return 0
}

does it look like this?
i'm still confused about how and where should i put the struct to hold the contact info.Can you guys help me a little bit??

You want to put the struct declaration before the main() function. Then, inside the main() or just before it, you want to declare a variable of the struct type to use.

BTW, you also need to put semi-colons at the end of the function prototypes. That, and your indentation needs work. And you don't want to return a value at the end of a void function.

#include<iostream>
using namespace std;

void showSelection();
void selectItem();

struct Contact
{
    char first_name[20];
    char last_name[20];
    char email[20];
    char phone_no[20];
}


int main()
{
    Contact person;

    int choice;
    showSelection();
    cin>>choice;

    while (choice !=9)
    {
        switch (choice)
        {
        case 1:
            selectItem (list);
        case 2:
            selectItem (edit);
        case 3:
            selectItem (search);
        case 4:
            selectItem (exit);

            break;
        default:
            cout<<"Invalid selection."<<endl;
        }
        showSelection();
        cin>> choice;
    }
    return 0;
}


void showSelection()
{
    cout<<"*** welcome to my phonebook system ***"<<endl;
    cout<<"To select an item, enter "<<endl;
    cout<<"1 for list : "<<endl;
    cout<<"2 for edit "<<endl;
    cout<<"3 for search "<<endl;
    cout<<"9 for exit "<<endl;

}
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <iomanip.h>

//Start with maximun 100 entries
#define MaxNum 100  

//Define some types
typedef char NameStr[31];
typedef char AddrStr[101];
typedef char Phone[11];

//Define the structure 

typedef struct Entry
{
	NameStr Name;
	AddrStr Address;
	Phone   HomeTel, HandPhone;
} PhEntry;

typedef PhEntry* PhoneList[MaxNum]; 

//Function Prototypes
void Display_menu(void);				//Display the Menu
void AddEntries(PhoneList, int&);		//Add Entries to the Phone Book
void DelEntry(PhoneList, int&);			//Delete an entry from Phone Book
void DispEntries(PhoneList, int);			//List out all Entries one by one
void Search(PhoneList, int);				//Show an Entry of a given name
int  Locate(const NameStr&, PhoneList, int);	//Locate the Entry by Name
void Read(ifstream&, PhoneList, int&);			//Read Phone Book from File
void Write(ofstream&, PhoneList, int);			//Write Phone Book to File
void Trim(char*);						//Remove trailing spaces

int main(void)
{
	PhoneList PhoneBook;	//Declare an array of Pointers

	char FileName[]="Phonebook.dat";
	ifstream Fin;
	ofstream Fout;
	char option;
	int Size = 0;

	// Read Phone Book from File
	Fin.open(FileName, ios::nocreate);	//Open an existing file
	if (Fin.fail())						//File not exist
	{ 
		cout << "File not exist, creating a new phone book..." << endl;
	}
	else
	{
		cout << "Phone Book read in from File...." << endl;
		Read(Fin, PhoneBook, Size);
		Fin.close();
	}
	cout << "Press a key.....";
	cin.get(option).ignore();
	do
	{
		Display_menu();
		cin.get(option).ignore();

		switch (option)
		{
			case 'a':
			case 'A': AddEntries(PhoneBook, Size);		break;
			case 'd':
			case 'D': DelEntry(PhoneBook, Size);		break;
			case 'l':
			case 'L': DispEntries(PhoneBook, Size);		break;
			case 's':
			case 'S': Search(PhoneBook, Size);			break;
		}

	} while (option != 'q' && option != 'Q');

	//Write Phone Book back to File
	if (Size>0)
	{
		Fout.open(FileName);
		cout << "Write Entries to file..." << endl;
		Write(Fout, PhoneBook, Size);
		cout << Size << " Entries written to file." << endl;
		Fout.close();
		for (int i=0; i<Size; i++)
		{
			delete PhoneBook[i];	//deallocate spaces
			PhoneBook[i] = NULL;
		}
	}

	return 0;
}

//Implementations
void Display_menu(void)
{
	system("CLS");
	cout << "    Electronic Phone Book" << endl;
	cout << "    =====================" << endl << endl;
	cout << "(a) Add new Entries"       << endl;
	cout << "(d) Delete an Entry"       << endl;
	cout << "(l) List all Entries"      << endl;
	cout << "(s) Search by Name"        << endl;
	cout << "(q) Call it a Day"			<< endl;
	cout << "Choose an Option: ";
}

void AddEntries(PhoneList PK, int& Size)
{
	char Ans;
	PhEntry Temp;    //Declare a temporary structure

	int  Count = 0, i;

	do
	{
		i = Size;
		system("CLS");
		cout << "Add Entries to Phone Book..." << endl;
		cout << "Enter Name: ";
		cin.getline(Temp.Name, 30, '\n');
		cout << "Enter Address Below:" << endl;
		cin.getline(Temp.Address, 100, '\n');
		cout << "Enter Home Tel: ";
		cin.getline(Temp.HomeTel, 10, '\n');
		cout << "Enter Hand Phone: ";
		cin.getline(Temp.HandPhone, 10, '\n');
		while ((i>0) && (strcmp(Temp.Name, PK[i-1]->Name) < 0))
		{
			PK[i] = PK[i-1];
			i--;
		}
		PK[i]=&Temp;
		Count++; Size++;
		cout << Count << " Entries Added." << endl << endl;
		cout << "Any more (y/n): ";
		cin.get(Ans).ignore();
	} while (Ans != 'n' && Ans != 'N');
}

void DelEntry(PhoneList PK, int& Size)
{
	NameStr Temp;
	int i;
	char Ans[10], C;

	system("CLS");
	cout << "Delete an entry from Phone Book..." << endl << endl;
	cout << "Enter Name to Delete: ";
	cin.getline(Temp, 30);

	i = Locate(Temp, PK, Size);		//Call Locate function to find where is it
	if (i >= 0)					//Fount it
	{
		cout << endl << PK[i]->Name << " to be Deleted." << endl;
		cout << endl << "Sure (y/n)? ";
		cin.get(C).ignore();
		if (C == 'y' || C == 'Y')
		{
			delete PK[i];       //deallocate memory
			for (int j=i+1; j < Size; j++)
				PK[j-1] = PK[j];
			Size--;
			PK[Size] = NULL;
			cout << Temp << " Deleted." << endl;
		}
		else
			cout << Temp << " Not Deleted." << endl;
	}
	else
		cout << endl << "Name not in the Phone Book." << endl;

	cout << "Press Enter to continue....";
	cin.getline(Ans, 9);
}

void DispEntries(PhoneList PK, int Size)
{
	char Ans[10];
	system("CLS");
	cout << "List of Entries in the Phone Book....." << endl << endl;
	for (int i=0; i<Size; i++)
	{
		cout << "Entry " << i+1 << ": " << endl;
		cout << PK[i]->Name << endl;
		cout << PK[i]->Address << endl;
		cout << "Tel: " << PK[i]->HomeTel << "(Home), ";
		cout << PK[i]->HandPhone << "(HP)" << endl << endl;
		cout << "Press Enter to continue....";
		cin.getline(Ans, 9);
	}
}

void Search(PhoneList PK, int Size)
{
	NameStr Temp;
	int i;
	char Ans[10];

	system("CLS");
	cout << "Search Entry by Name..." << endl << endl;
	cout << "Enter Name to Search: ";
	cin.getline(Temp, 30);

	i = Locate(Temp, PK, Size);		//Call Locate function to find where is it
	if (i >= 0)					//Fount it
	{
		cout << endl;
		cout << PK[i]->Name << endl;
		cout << PK[i]->Address << endl;
		cout << "Tel: " << PK[i]->HomeTel << "(Home), ";
		cout << PK[i]->HandPhone << "(HP)" << endl << endl;
	}
	else
		cout << endl << "Name not in the Phone Book." << endl;

	cout << "Press Enter to continue....";
	cin.getline(Ans, 9);
}

int  Locate(const NameStr& SName, PhoneList PK, int Size)
{
	int i=0;
	while (i < Size)
	{
		if (strcmp(SName, PK[i]->Name) == 0)	//Found it
			return i;		
		if (strcmp(SName, PK[i]->Name) < 0)	//Not in the list
			return -1;
		i++;
	}
	return -1;		//Reach the end of list, still din't find it
}

void Read(ifstream& IN, PhoneList PK, int& Size)
{
	char Buffer[201]={0};     //Read Buffer
	
	while(IN.getline(Buffer, 200))     //if read success
	{
		PK[Size] = new PhEntry;		//allocate space
		strncpy(PK[Size]->Name, Buffer, 30); 
		PK[Size]->Name[30]='\0';
		Trim(PK[Size]->Name);
		strncpy(PK[Size]->Address, &Buffer[30], 100);
		PK[Size]->Address[100]='\0';
		Trim(PK[Size]->Address);
		strncpy(PK[Size]->HomeTel, &Buffer[130], 8);
		PK[Size]->HomeTel[8] = '\0';
		strncpy(PK[Size]->HandPhone, &Buffer[139], 8);
		PK[Size]->HandPhone[8] = '\0';
		Size++;
	}
}

void Write(ofstream& OUT, PhoneList PK, int Size)
{
	for (int i=0; i<Size; i++)
	{
		OUT << setiosflags(ios::left);
		OUT << setw(30) << PK[i]->Name;
		OUT << setw(100) << PK[i]->Address;
		OUT << setw(9) << PK[i]->HomeTel;
		OUT << setw(9) << PK[i]->HandPhone << endl;
	}
}

void Trim(char* S)
{
	int L = strlen(S) - 1;
    while (L > 0 && S[L] == ' ')
		S[L--] = 0;
}

this is just an example..but i can't compile it.is there any mistakes in these codes?thanks guys

this is just an example..but i can't compile it.is there any mistakes in these codes?

If it doesn't compile, there are mistakes. That's axiomatic. If it doesn't compile, there are also compilation errors. Use them to fix the mistakes or post the errors so that others can help you fix the mistakes if you're incapable of doing so by yourself.

Umm...dude, dont take me the wrong way.. But if u dont know what [20] stands for, u shouldnt be looking to create a phonebook program from the start... I think it'd be better u expand ur knowledge about the following topics :
Basic Data Types - int,void,char,float,double
Functions
Arrays
File Handling - To permanently store the phone numbers
Structures

(Even though the program can be done without structures... It'll be a lot harder)

commented: agree :) +17
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <iomanip.h>

//Start with maximun 100 entries
#define MaxNum 100  

//Define some types
typedef char NameStr[31];
typedef char AddrStr[101];
typedef char Phone[11];

//Define the structure 

typedef struct Entry
{
	NameStr Name;
	AddrStr Address;
	Phone   HomeTel, HandPhone;
} PhEntry;

typedef PhEntry* PhoneList[MaxNum]; 

//Function Prototypes
void Display_menu(void);				//Display the Menu
void AddEntries(PhoneList, int&);		//Add Entries to the Phone Book
void DelEntry(PhoneList, int&);			//Delete an entry from Phone Book
void DispEntries(PhoneList, int);			//List out all Entries one by one
void Search(PhoneList, int);				//Show an Entry of a given name
int  Locate(const NameStr&, PhoneList, int);	//Locate the Entry by Name
void Read(ifstream&, PhoneList, int&);			//Read Phone Book from File
void Write(ofstream&, PhoneList, int);			//Write Phone Book to File
void Trim(char*);						//Remove trailing spaces

int main(void)
{
	PhoneList PhoneBook;	//Declare an array of Pointers

	char FileName[]="Phonebook.dat";
	ifstream Fin;
	ofstream Fout;
	char option;
	int Size = 0;

	// Read Phone Book from File
	Fin.open(FileName, ios::nocreate);	//Open an existing file
	if (Fin.fail())						//File not exist
	{ 
		cout << "File not exist, creating a new phone book..." << endl;
	}
	else
	{
		cout << "Phone Book read in from File...." << endl;
		Read(Fin, PhoneBook, Size);
		Fin.close();
	}
	cout << "Press a key.....";
	cin.get(option).ignore();
	do
	{
		Display_menu();
		cin.get(option).ignore();

		switch (option)
		{
			case 'a':
			case 'A': AddEntries(PhoneBook, Size);		break;
			case 'd':
			case 'D': DelEntry(PhoneBook, Size);		break;
			case 'l':
			case 'L': DispEntries(PhoneBook, Size);		break;
			case 's':
			case 'S': Search(PhoneBook, Size);			break;
		}

	} while (option != 'q' && option != 'Q');

	//Write Phone Book back to File
	if (Size>0)
	{
		Fout.open(FileName);
		cout << "Write Entries to file..." << endl;
		Write(Fout, PhoneBook, Size);
		cout << Size << " Entries written to file." << endl;
		Fout.close();
		for (int i=0; i<Size; i++)
		{
			delete PhoneBook[i];	//deallocate spaces
			PhoneBook[i] = NULL;
		}
	}

	return 0;
}

//Implementations
void Display_menu(void)
{
	system("CLS");
	cout << "    Electronic Phone Book" << endl;
	cout << "    =====================" << endl << endl;
	cout << "(a) Add new Entries"       << endl;
	cout << "(d) Delete an Entry"       << endl;
	cout << "(l) List all Entries"      << endl;
	cout << "(s) Search by Name"        << endl;
	cout << "(q) Call it a Day"			<< endl;
	cout << "Choose an Option: ";
}

void AddEntries(PhoneList PK, int& Size)
{
	char Ans;
	PhEntry Temp;    //Declare a temporary structure

	int  Count = 0, i;

	do
	{
		i = Size;
		system("CLS");
		cout << "Add Entries to Phone Book..." << endl;
		cout << "Enter Name: ";
		cin.getline(Temp.Name, 30, '\n');
		cout << "Enter Address Below:" << endl;
		cin.getline(Temp.Address, 100, '\n');
		cout << "Enter Home Tel: ";
		cin.getline(Temp.HomeTel, 10, '\n');
		cout << "Enter Hand Phone: ";
		cin.getline(Temp.HandPhone, 10, '\n');
		while ((i>0) && (strcmp(Temp.Name, PK[i-1]->Name) < 0))
		{
			PK[i] = PK[i-1];
			i--;
		}
		PK[i]=&Temp;
		Count++; Size++;
		cout << Count << " Entries Added." << endl << endl;
		cout << "Any more (y/n): ";
		cin.get(Ans).ignore();
	} while (Ans != 'n' && Ans != 'N');
}

void DelEntry(PhoneList PK, int& Size)
{
	NameStr Temp;
	int i;
	char Ans[10], C;

	system("CLS");
	cout << "Delete an entry from Phone Book..." << endl << endl;
	cout << "Enter Name to Delete: ";
	cin.getline(Temp, 30);

	i = Locate(Temp, PK, Size);		//Call Locate function to find where is it
	if (i >= 0)					//Fount it
	{
		cout << endl << PK[i]->Name << " to be Deleted." << endl;
		cout << endl << "Sure (y/n)? ";
		cin.get(C).ignore();
		if (C == 'y' || C == 'Y')
		{
			delete PK[i];       //deallocate memory
			for (int j=i+1; j < Size; j++)
				PK[j-1] = PK[j];
			Size--;
			PK[Size] = NULL;
			cout << Temp << " Deleted." << endl;
		}
		else
			cout << Temp << " Not Deleted." << endl;
	}
	else
		cout << endl << "Name not in the Phone Book." << endl;

	cout << "Press Enter to continue....";
	cin.getline(Ans, 9);
}

void DispEntries(PhoneList PK, int Size)
{
	char Ans[10];
	system("CLS");
	cout << "List of Entries in the Phone Book....." << endl << endl;
	for (int i=0; i<Size; i++)
	{
		cout << "Entry " << i+1 << ": " << endl;
		cout << PK[i]->Name << endl;
		cout << PK[i]->Address << endl;
		cout << "Tel: " << PK[i]->HomeTel << "(Home), ";
		cout << PK[i]->HandPhone << "(HP)" << endl << endl;
		cout << "Press Enter to continue....";
		cin.getline(Ans, 9);
	}
}

void Search(PhoneList PK, int Size)
{
	NameStr Temp;
	int i;
	char Ans[10];

	system("CLS");
	cout << "Search Entry by Name..." << endl << endl;
	cout << "Enter Name to Search: ";
	cin.getline(Temp, 30);

	i = Locate(Temp, PK, Size);		//Call Locate function to find where is it
	if (i >= 0)					//Fount it
	{
		cout << endl;
		cout << PK[i]->Name << endl;
		cout << PK[i]->Address << endl;
		cout << "Tel: " << PK[i]->HomeTel << "(Home), ";
		cout << PK[i]->HandPhone << "(HP)" << endl << endl;
	}
	else
		cout << endl << "Name not in the Phone Book." << endl;

	cout << "Press Enter to continue....";
	cin.getline(Ans, 9);
}

int  Locate(const NameStr& SName, PhoneList PK, int Size)
{
	int i=0;
	while (i < Size)
	{
		if (strcmp(SName, PK[i]->Name) == 0)	//Found it
			return i;		
		if (strcmp(SName, PK[i]->Name) < 0)	//Not in the list
			return -1;
		i++;
	}
	return -1;		//Reach the end of list, still din't find it
}

void Read(ifstream& IN, PhoneList PK, int& Size)
{
	char Buffer[201]={0};     //Read Buffer
	
	while(IN.getline(Buffer, 200))     //if read success
	{
		PK[Size] = new PhEntry;		//allocate space
		strncpy(PK[Size]->Name, Buffer, 30); 
		PK[Size]->Name[30]='\0';
		Trim(PK[Size]->Name);
		strncpy(PK[Size]->Address, &Buffer[30], 100);
		PK[Size]->Address[100]='\0';
		Trim(PK[Size]->Address);
		strncpy(PK[Size]->HomeTel, &Buffer[130], 8);
		PK[Size]->HomeTel[8] = '\0';
		strncpy(PK[Size]->HandPhone, &Buffer[139], 8);
		PK[Size]->HandPhone[8] = '\0';
		Size++;
	}
}

void Write(ofstream& OUT, PhoneList PK, int Size)
{
	for (int i=0; i<Size; i++)
	{
		OUT << setiosflags(ios::left);
		OUT << setw(30) << PK[i]->Name;
		OUT << setw(100) << PK[i]->Address;
		OUT << setw(9) << PK[i]->HomeTel;
		OUT << setw(9) << PK[i]->HandPhone << endl;
	}
}

void Trim(char* S)
{
	int L = strlen(S) - 1;
    while (L > 0 && S[L] == ' ')
		S[L--] = 0;
}

this is just an example..but i can't compile it.is there any mistakes in these codes?thanks guys

Forgive me, but that is certainly not your own effort... It just shows...
( You used a return statement for void.. WTF??)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.