6 Replies - 415 Views - Last Post: 07 February 2012 - 05:29 PM Rate Topic: -----

Topic Sponsor:

#1 sololy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-January 12

a phone/address book class

Posted 07 February 2012 - 02:31 PM

hello everyone
I have a project in c2 language
a phone/address book class


Your project contains the following main menu:
1. Add new participant.
2. Search for a participant (By ID).
3. Search for a participant (BY Full Name)
4. Delete a participant.
5. Modify a participant object.
6. Make work phone call for a participant.
7. Print all the E-Mail's for a participant.
8. Search a bout work phone number.
9. Add E-Mail for a participant.
10. Search for E-Mail.
11. Delete E-Mail for a participant.
12. Exchange two participant's information.
13. Print all information of a participant.
14. Print all participants in the list. (the result should be stored in a text file)
15. Quit.


Notes:

• AddressBok object has the following attributes:
ID : int
Fname : string
Family: string
HomePhone: long
WorkPhone: long
Mobile: long
E_Mail Pointer : it points to array of strings (this array contains all E-mails for the participant)
- Note that some participants have no E-mails and others may have one or two or more E-mails.
- Also you should validate that the entered E-Mail that it is in the E-Mail format (xxx@yy.zz)
• You can't add a participant if the phone/book is full
• You can't delete a participant if the phone/book is empty.




I solved most of the project but I couldn't solve some of them like


Print all the E-Mail's for a participant.
9. Add E-Mail for a participant.
10. Search for E-Mail.
11. Delete E-Mail for a participant.
14. Print all participants in the list. (the result should be stored in a text file)


and this is my code

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<cstring.h>
const int s=10;
class addressBok
{
    int Id;
    string Fname ;
string family ;
 long int homePhone;
long int workPhone;
long int mobile;

 int m;
public :
void set(int id,string fname,string Family,long int Mobile,long int homephone,long int workphone)
{
 Id=id;
 Fname=fname;
 Family=family;
 mobile=Mobile;
 homePhone=homephone;
 workPhone=workphone;





}

int get_id (){return Id;}
long int get_work(){return workPhone;}
long int get_home(){return homePhone;}
long int get_mobile (){return mobile;}
string get_fName (){return Fname;}
string get_family (){return family;}

void set_Id (int id){Id=id;}
void set_w (long int work){ workPhone=work;}
void set_h (long int home){ homePhone=home;}
void set_m (long int m){ mobile=m;}
void set_f (string name){Fname=name;}
void set_family (string f){family=f;}

string fullName ()
{
    string first=Fname;
    string second =family;
    string full = first + " "+second;
   return full;

}


void print ()
{
    cout<<"\nThis participant his name is : "<<fullName()<<endl;
    cout<<"\nHis Id is : "<<Id<<endl;
    cout<<"His work phone : "<<workPhone;
    cout<<"\nHis home phone : "<<homePhone;
    cout<<"\nHis mobile : "<<mobile; }

};

class stack {
    private :
    addressBok list[s];
	int  top,id,dp;

	addressBok  b;
    addressBok box_address[s];
	  public:
	  stack()
	{
	    top=-1;
	    dp=-1 ;
	}

	void add_participant (addressBok B)
	 {
	     if(dp==s-1)
	 cout<<"box adderss is full";
	 else
	 {
	     dp++;
	 box_address[dp]=b;

	 }
	 }

	 void print_d()
	  {
	      if(dp==-1)
          cout << "the address box is empty ";

	else
         for(int i=0;i<=dp;i++)
	{
	     	 box_address[i].print();

	}

	}

	  void delete_par( )
	{
	     int y=0,s=0;
	      addressBok b;
	if (top==-1)
	cout <<"the stack is empty you can't delete\n ";
	else
	{
	     int id;
			cout<<"enter the id of participant that you want to delete\n";
		    cin>>id;
	for(int i=0;i<=top;i++)

	 if(id==list[i].get_id())
	  {
	      y++;
	      s=i;
	  }

	  if(y==0)
		cout<<"participant not found\n";
	  else

  {
      if(id==list[top].get_id())
			{
			 add_participant(list[top]);
		 cout<<"\ninf of deleted participant is: ";
		 list[top].print();
			top--;
			cout<<"\n";
	 }

	else
	{
		 addressBok t=list[top];
		list[top]=list[s];
		list[s]=t;
		  b=list[top];
		  add_participant(B);
			cout<<"\ninf of deleted participant is: ";
			list[top].print();
		    top--;

	}

  }
	}
	}

void add(addressBok n)
{

	if (top==s-1)
	{cout << "the stack is full "; }
		else
		{
		top++;
		list[top]=n ;
		}
}

  void  print_top()
		 {if(top==-1)
				 cout << "\nthe stack is empty\n ";

	else
	for(int i=0;i<=top;i++)
	{

	    list [i].print ();
	}
	}

	void search()

	{
	    if(top==-1)
	cout<<"\naddress phone is empty\n";
	else
	{
	     int id;
		cout<<"enter the id of participant\n";
		cin>>id;
	 int y=0;
	for(int i=0;i<=top;i++)
	if(id==list[i].get_id())
	 {
	      y=i;
	 //cout<<"participant is found in # "<<y+1<<"and His inf is : \n";
	 list[y].print();
	 }

	  else

	  cout<<"not found\n";

				 }
	 }

	 void search2 ()
	 {
	     if(top==-1)
	cout<<"\naddress phone is empty\n";
	else
	{
	    string full,fname,family;
		cout<<"enter the First name of participant\n";
		cin>>fname;
		cout<<"enter the family name of participant\n";
		full=fname+" "+family;
	 int y=0;
	for(int i=0;i<=top;i++)
	if(full==list[i].fullName())
	 {
	      y=i;
	// cout<<"participant is found in # "<<y+1<<"and His inf is : \n";
	 list[y].print();
	 }

	  else

	  cout<<"not found\n";

				 }
	 }


	 void modify()
	 {
	 string pn,nn,pa,na;
	 int x,pid,nid;
	 long int w,h,m,m2,h2,w2;
	 if(top==-1)
	 cout<<"\nthe lib is empty you can't modify\n";
	 else
	 {
	 cout<<"\nEnter 1.to modify id\n2.to modify name\n 3.to modify family Name\n4-to modify mobile\n5-to modify work phone\n6-to modify home phone\n";
	 cin>>x;
	 if(x==1)
	{ cout<<"enter privious id \n";
	 cin>>pid;
	 int p=0,y=0; addressBok b;
	 for(int i=0;i<=top;i++)


	if(pid==list[i].get_id())
  {

	y++;
  p=i;
  }
  if(y==0)
  cout<<"\nparticipant not in phone book you can't modify\n";
  else
  { cout<<"\nparticipant is found enter new id\n";
	  cin>>nid;
	  list[p].set_Id(nid);
  cout<<"\nthe participant after modify";list[p].print(); }
	cout<<"\n";
	}
	if(x==2)
	{ cout<<"enter privious name \n";
	 cin>>pn;
	 int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(pn==list[i].get_fName())
  {

	y++;
  p=i;}
  if(y==0)
  cout<<"\nparticipant not in phone book you can't modify\n";
  else
  { cout<<"\nparticicpant is found enter new name\n";
	  cin>>nn;
	  list[p].set_f(nn);
  cout<<"the participant after modify";
  list[p].print(); }
	cout<<"\n";
	}

	if (x==4)
	{
	   cout<<"\nenter privious mobile  \n";
	 cin>>m;
	 int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(m==list[i].get_mobile())
  {

	y++;
  p=i;}
  if(y==0)
  cout<<"\nparticipant not in phone book you can't modify\n";
  else
  { cout<<"\nparticicpant is found enter new mobile\n";
	  cin>>m2;
	  list[p].set_m(m2);
  cout<<"the participant after modify";
  list[p].print(); }
	cout<<"\n";
	}
	if (x==6)
	{
	   cout<<"\nenter privious home phone\n";
	 cin>>h;
	 int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(h==list[i].get_home())
  {

	y++;
  p=i;}
  if(y==0)
  cout<<"\nparticipant not in phone book you can't modify\n";
  else
  { cout<<"\nparticicpant is found enter new mobile\n";
	  cin>>h2;
	  list[p].set_m(h2);
  cout<<"the participant after modify";
  list[p].print(); }
	cout<<"\n";
	}
	if (x==5)
	{
	   cout<<"\nenter privious work phone  \n";
	 cin>>w;
	 int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(m==list[i].get_work())
  {

	y++;
  p=i;}
  if(y==0)
  cout<<"\nparticipant not in phone book you can't modify\n";
  else
  { cout<<"\nparticicpant is found enter new mobile\n";
	  cin>>w2;
	  list[p].set_w(w2);
  cout<<"the participant after modify";
  list[p].print(); }
	cout<<"\n";
	}
	if(x==3)
	{
	    cout<<"enter privious family name\n";
	 cin>>pa;
	 int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(pa==list[i].get_family())
  {

	y++;
  p=i;}
  if(y==0)
  cout<<"participant not in phone book you can't modify\n";
  else
  { cout<<"\nparticipant is found enter new family name\n";
	  cin>>na;
	  list[p].set_family(na);
  cout<<"the participant after modify";list[p].print(); }
	cout<<"\n";
	}
	}}


void call_phone()
{
    long int c;
    cout<<"\nEnter the phone work number : ";
    cin>>c;
    int p=0,y=0;
	 for(int i=0;i<=top;i++)


	if(c==list[i].get_mobile())
  {

	y++;
  p=i;
  }
  if(y==0)
  cout<<"\nparticipant not in phone book you can't make a call \n";

  else
  { cout<<"\ntoooot  tooooot tooooot\n";
  }
}

 void search_w ()
 {
     if(top==-1)
	cout<<"\naddress phone is empty\n";
	else
	{
	     long int w;
		cout<<"enter the work phone of participant\n";
		cin>>w;
	 int y=0;
	for(int i=0;i<=top;i++)
	if(w==list[i].get_work())
	 {
	      y=i;
	 //cout<<"\nwork phone  is found in # "<<y+1;

	 }

	  else

	  cout<<"\nnot found\n";

				 }
 }


 void print_Ontext()
 {
     ofstream a;
     a.open ("print.text");
     for (int i=0;i<=top;i++)
     {
    a<<"\nThis participant his name is : "<<list[i].fullName()<<endl;
    a<<"\nHis Id is : "<<list[i].get_id()<<endl;
    a<<"His work phone : "<<list[i].get_work();
    a<<"\nHis home phone : "<<list[i].get_home();
    a<<"\nHis mobile : "<<list[i].get_mobile();
    a<<"\nHis e_mail : ";



     }
     a.close ();
 }












};
void exchange ( addressBok *a, addressBok *B)
{
   addressBok t=*a;
   *a=*b;
   *b=t;
}
void menu ()
{
    cout<<"\nEnter you choice from the menu\n";
    cout<<"\n1.	Add new participant \n";
    cout<<"\n2.	Search for a participant (By ID). \n";
    cout<<"\n3.	Search for a participant (BY Full Name) \n";
    cout<<"\n4.	Delete a participant. \n";
    cout<<"\n5.	Modify a participant object. \n";
    cout<<"\n6.	Make work phone call for a participant. \n";
    cout<<"\n7.	Print all the E-Mail's for a participant. \n";
    cout<<"\n8.	Search a bout work phone number. \n";
    cout<<"\n12. Exchange two participant's information. \n";
    cout<<"\n13. Print all information of a participant. \n";
    cout<<"\n14. Print all participants(the result should be stored in a text file) \n";
    cout<<"\n15. Quit. \n";

}
main ()
{
    stack phoneBook;

     addressBok a;
     addressBok b;


    int ch;
    while (ch!=15)
    {
    menu ();
		cin>>ch;
        if (ch==1)
        {
            int Id;
    string Fname ;
string family ;
 long int homePhone;
long int workPhone;
long int mobile;


    cout<<"\nEnter Id for participants\n";
    cin>>Id;
    cout<<"\nEnter the First Name\n";
    cin>>Fname;
    cout<<"\nEnter The Family Name\n";
    cin>>family;
    cout<<"\nEnter The mobile\n";
    cin>>mobile;
    cout<<"\nEnter Home Phone\n";
    cin>>homePhone;
    cout<<"\nEnter work Phone\n";
    cin>>workPhone;

    a.set(Id,Fname,family,mobile,homePhone,workPhone);
    phoneBook.add (a);
        }

        if (ch==2)
        phoneBook.search ();
        if (ch==3)
        phoneBook.search2 ();
        if (ch==4)
        phoneBook.delete_par ();
        if (ch==5)
        phoneBook.modify ();
        if (ch==6)
        phoneBook.call_phone();
        if (ch==8)
        phoneBook.search_w();
        if (ch==12)
        {
            cout<<"\nThe exchange of 2 obj\n";
            exchange(&a ,& B);
            cout<<"The first obj after swaping : ";
            b.print ();
            cout<<"\n\nThe second obj after swaping : ";
            a.print ();

        }
        if (ch==13)
        phoneBook.print_top ();
        if (ch==14)
        phoneBook.print_Ontext();
        if (ch==15)
        cout<<"\n\nThat was The final project Finally";

    }

}



Is This A Good Question/Topic? 0
  • +

Replies To: a phone/address book class

#2 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,039
  • Joined: 31-December 10

Re: a phone/address book class

Posted 07 February 2012 - 02:59 PM

Is there a specific question you have?

Just a little tip, the headers you're including are the outdated version of the standard C++ headers. Any header from the standard C++ library that used to be written as "name.h" like "iostream.h" becomes just "name". So "iostream.h" becomes "iostream", the C standard library headers are the same except you add a 'c' to the beginning of the header name. So "stdio.h" becomes "cstdio".

Last thing, whoever is teaching you to use "conio.h" is wrong, conio.h is an old outdated, and non-portable 16-bit header. When you use that header, your program will need to be changed if you try to compile it on most machines because most computers nowadays do not have the conio.h header file. There are libraries out there that do similar things that the conio.h header does.

This post has been edited by vividexstance: 07 February 2012 - 03:00 PM

Was This Post Helpful? 0
  • +
  • -

#3 sololy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-January 12

Re: a phone/address book class

Posted 07 February 2012 - 03:38 PM

View Postvividexstance, on 07 February 2012 - 02:59 PM, said:

Is there a specific question you have?

Just a little tip, the headers you're including are the outdated version of the standard C++ headers. Any header from the standard C++ library that used to be written as "name.h" like "iostream.h" becomes just "name". So "iostream.h" becomes "iostream", the C standard library headers are the same except you add a 'c' to the beginning of the header name. So "stdio.h" becomes "cstdio".

Last thing, whoever is teaching you to use "conio.h" is wrong, conio.h is an old outdated, and non-portable 16-bit header. When you use that header, your program will need to be changed if you try to compile it on most machines because most computers nowadays do not have the conio.h header file. There are libraries out there that do similar things that the conio.h header does.


Thanks very much for your comment ^_^
but we use these library in our class and I want to do what the doctor said but your information very useful so thanks very much

so could you help my in my question about how to add and delete an email
like what I'm asked above please ??!!

and thanks again
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon

Reputation: 1892
  • View blog
  • Posts: 5,681
  • Joined: 25-December 09

Re: a phone/address book class

Posted 07 February 2012 - 03:40 PM

Show what you have tried.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 sololy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-January 12

Re: a phone/address book class

Posted 07 February 2012 - 03:50 PM

View Postjimblumberg, on 07 February 2012 - 03:40 PM, said:

Show what you have tried.

Jim


The above code was without adding the email as attribute
but I have another solution with the email pointer

  #include<iostream.h>
#include<cstring.h>
#include<fstream.h>
const int s=10;


 class phoneinfo{
 int id;
 string fname;
 string family;
 long homephone;
 long workphone;
 long mobile;
 string *email;
 int c;
   public:

			phoneinfo()
			{
			 c=0;
			 id=0;
			 fname=" ";
			 family=" ";
			 homephone=0;
			 workphone=0;
			 mobile=0;
			 email=new string[1000];
			}


	 void setinfo()
	 {

		int pid; string  fn; string fm; long hp; long wp; long mob;
		cout<<"Enter your ID :"<<endl;
		cin>>pid;
		cout<<"Enter your first name:"<<endl;
		cin>>fn;
		cout<<"Enter your family name:"<<endl;
		cin>>fm;
		cout<<"Enter your home phone numbar:"<<endl;
		cin>>hp;
		cout<<"Enter your work phone number:"<<endl;
		cin>>wp;
		cout<<"Enter your mobile number:"<<endl;
		cin>>mob;
		id=pid; fname=fn; family=fm; homephone=hp; workphone=wp; mobile=mob;
		setemail();
    }


				void setemail()
				{
				  int num;
				  cout<<"enter the number of emails that you wana to enter:"<<endl;
				  cin>>num;
				  for(int i=0;i<num;i++)
				  {
					 string y;
					 cout<<"Enter the email:"<<endl;
					 cin>>y;
							 if( compair(y)==1 )
							  email[i]=y;
							  else
							  cout<<"ERROR you have stored this email,enter another email"<<endl;
				  }
				 c+=num;
				 email+=num;
				}


			int compair(string u)
			{
			  string *y=email-c;
			  for(int i=0;i<c;i++)
				 if(u==y[i])
				 return 0;
			  return 1;
			}


	 void setid(int pid)
	 {
	  id=pid;
	 }

 void setfname(string fn)
 {
  fname=fn;
 }

 void setfamily(string fm)
 {
  family=fm;
 }

 void sethomephone(long hp)
 {
  homephone=hp;
 }

 void setworkphone(long wp)
 {
  workphone=wp;
 }

 void setmobile(long mob)
 {
  mobile=mob;
 }



		 int getid(){return id;}
		 string getfname(){return fname;}
		 string getfamily(){return family;}
		 long gethp(){return homephone;}
		 long getwp(){return workphone;}
		 long getmob(){return mobile;}

		 void getemail()
		 {
			cout<<"Your emails are :";
			string *y=email-c;
			for(int i=0;i<c;i++)
			 cout<<i+1<<"-"<<y[i]<<endl;
			 cout<<endl;
		 }

		 void email_set(int no)
		 {
			string *y=email-c;
			string roro;
			cout<<"Enter the new email that you wana:"<<endl;
			cin>>roro;
			y[no]= roro;
		 }

	  void print()
	  {
	  cout<<"ID: "<<getid()<<endl<<"first name: "<<getfname()<<endl<<"family: "<<getfamily()<<endl<<"home phone: "<<gethp()<<endl<<"work phone: "<<getwp()<<endl;
	  getemail();
	  }


	  void set_email()
	  {
		 int no;
		 cout<<"Enter the number of email that you wana to change:"<<endl;
		 getemail();
		 cin>>no;
		 email_set(--no);

	  }


		int findemail(string p)
		{
		 string *y=email-c;
		 for(int i=0;i<c;i++)
		  if(y[i]==p)
		  return 1;
		  return 0;
		}



		void delet_email()
		{
		  string *y=email-c;
		  if(c==0)
		  cout<<"Sorry you can't delete couse no email"<<endl;

			else
			{
			 string t;
			 cout<<"Enter the email that you wana to delet"<<endl;
			 cin>>t;
			 int no=findemail(t);

				 if(no==0)
				  cout<<"The email that you wana to delete is not found"<<endl;
				 else
				 {
					 if(t==y[c])
					  c--;
					 else
					 {
						string t=y[c];
						y[c]=y[no];
						y[c]=t;
						c--;
					 }
				 }
			}
		}

					void printtext()
					{
					  ofstream rudina;
					  rudina.open("phone.txt");
					  rudina<<"ID      fname        family        homep.           workp.       mobile"<<endl;
					  rudina<<id<<"   "<<fname<<"   "<<family<<"   "<<homephone<<"   "<<workphone<<"   "<<mobile;
					  rudina<<"emails:"<<endl;
                   string *y=email-c;
						 for(int i=0;i<c;i++)
						 rudina<<y[i]<<endl;
						 rudina<<endl;
					  rudina.close();
					}
};



class phoneadd{
phoneinfo list[s];
int top;
public:

  phoneadd()
  {
   top=-1;
  }

void add(phoneinfo p)
{
	  if(top==s-1)
		 cout<<"The phone-book is full"<<endl;
     else
     {
      int y=0;
      for(int i=0;i<=top;i++)
		  if( p.getid()==list[i].getid() )
			 y=1;
		  if(y==0)
        {
			top++;
         list[top]=p;
        }
        else
        cout<<"ERROR you can't enter this participant"<<endl;
     }
}



      int findhim(int idp)
			{
			  for(int i=0;i<=top;i++)
			  if(list[i].getid()==idp)
			  return i;
			  return -1;
			}


  void search_id()
	{
    if(top==-1)
    cout<<"The list is empty"<<endl;
    else
     {
		 int id;
       cout<<"Enter the ID that you want to search for:"<<endl;
		 cin>>id;
		 int pid=findhim(id);
		 if( pid !=-1)
		 {
		  cout<<"The participant found and it's info. is:";
		  list[pid].print();
		 }
		  else
		  cout<<"The participant not found ,try again using another ID"<<endl;
     }
   }



  int search_name()
	{
    if(top==-1)
    cout<<"The list is empty"<<endl;
    else
     {
		 string fn,fm;
		 int f=0;
		 cout<<"Enter the first name then the second name that you want to search for:"<<endl<<"first name: ";
		 cin>>fn;
		 cout<<"family name:"<<endl;
		 cin>>fm;
		 for(int i=0;i<=top;i++)
		  {
			  if(list[i].getfname()==fn && list[i].getfamily()==fm)
			  {
				 f=i;
				 cout<<"The participant found and it's info. is:";
				 list[i].print();
			  }

			  else
				cout<<"The participant not found ,try again using the correct name"<<endl;
		  }
	  }
	}



	void delet()
   {
	  if(top==-1)
	  cout<<"Sorry you can't delete from the list because it's empty"<<endl;

			else
			{
			 int rid,no;
			 cout<<"Enter the ID of the participant that you wana to delete"<<endl;
			 cin>>rid;
			 no=findhim(rid);

				 if(no==-1)
				  cout<<"The participant that you wana to delete is not found"<<endl;
				 else
				 {
					 if(rid==list[top].getid())
					  top--;
					 else
					 {
						phoneinfo t=list[top];
						list[top]=list[no];
						list[no]=t;
						top--;
					 }
				 }
			}
	 }

	 void modify()
	 {
		if(top==-1)
		cout<<"Sorry you can't modify any participant from the list because it's empty"<<endl;

		else
		 {
			int m,n;
			cout<<"Enter the ID of the participant that you wana to modify:"<<endl;
			cin>>m;
			int koko=findhim(m);
			cout<<"Enter the number of the thing you wana to modify:"<<endl;
				cout<<"1.ID"<<endl;
				cout<<"2.first name"<<endl;
				cout<<"3.family name"<<endl;
				cout<<"4.home phone"<<endl;
				cout<<"5.work phone"<<endl;
				cout<<"6.mobile"<<endl;
				cout<<"7.email"<<endl;
				cin>>n;
					if(n==1)
					{
					  int y;
					  cout<<"Enter the new ID"<<endl;
					  cin>>y;
					  list[koko].setid(y);
					}

						  if(n==2)
						  {
							 string f;
							 cout<<"Enter the new first name"<<endl;
							 cin>>f;
							 list[koko].setfname(f);
						  }

							 if(n==3)
							 {
								string t;
								cout<<"Enter the new family name"<<endl;
								cin>>t;
								list[koko].setfamily(t);
							 }


								if(n==4)
								{
								  long u;
								  cout<<"Enter the new home phone"<<endl;
								  cin>>u;
								  list[koko].sethomephone(u);
								}

									 if(n==5)
									 {
										 long h;
										 cout<<"Enter the new work phone"<<endl;
										 cin>>h;
										 list[koko].setworkphone(h);
									 }


					 if(n==6)
					 {
						long b;
						cout<<"Enter the new mobile"<<endl;
						cin>>b;
						list[koko].setmobile(B);
					 }

							if(n==7)
							{
							  list[koko].set_email();
							}
			 }
	  }


  void set_workphone()
  {
	  if(top==-1)
	  cout<<"Sorry you can't call any participant from the list because it's empty"<<endl;

	  else
		{
		  long phone;
		  cout<<"Enter the work phone for the participant that you wana to call"<<endl;
		  cin>>phone;
		  for(int i=0;i<=top;i++)
			  if(list[i].getwp()==phone)
			  cout<<"the number found and his owner is "<<list[i].getfname()<<"\n"<<"calling begin.........."<<endl;
		}
  }


	 void print_email()
	 {
		int pid;
		if(top==-1)
		cout<<"Sorry the list empty"<<endl;

		else
		{
		  cout<<"Enter the ID of the participant you wana to print it's email"<<endl;
		  cin>>pid;
		  int yy=findhim(pid);
		  list[yy].getemail();
		}
	 }


		void searchwp()
		{
			 long wp;
			 if(top==-1)
			 cout<<"Sorry the list empty"<<endl;
			 else
			 {
				 cout<<"Enter the work phone that you wana to search "<<endl;
				 cin>>wp;
				 for(int i=0;i<=top;i++)
					if(list[i].getwp()==wp)
					 {
                 cout<<"The work phone found:"<<endl;
					  int uu=i;
					  list[uu].print();
					 }
			 }
      }

	  void addemail()
		{
		 int pid;
			if(top==-1)
			cout<<"Sorry the list empty"<<endl;

			else
			{
				 cout<<"Enter the ID for the participant you wana to add email for him"<<endl;
				 cin>>pid;
				 int uu=findhim(pid);
				 if(uu==-1)
					cout<<"The Id not found"<<endl;
					else
			      list[uu].setemail();
			}
      }


			  void searchemail()
			  {    int c=0;
					string h;
                if(top==-1)
					 cout<<"Sorry the list empty"<<endl;
					 else
					 {
						cout<<"Enter the email that you wana to seach"<<endl;
						cin>>h;
						for(int i=0;i<=top;i++)
						  {
							 if(list[i].findemail(h))
							 list[i].print();
							 c=1;
						  }
						if(c==0)
						cout<<"not found"<<endl;
					 }
			  }



		void delemail()
		{  int pid,u;
			if(top==-1)
			cout<<"Sorry the list empty"<<endl;
			 else
			 {
			 cout<<"Enter the ID for the participant that u wana to delete email from"<<endl;
			 cin>>pid;
			 u=findhim(pid);
			 if(u==-1)
			 cout<<"this ID not found"<<endl;
				else
				{
				 list[u].delet_email();
				}
			 }
		}


			  void exchange()
			  {
				  int d1,d2,dd1,dd2;
				  if(top==-1)
				  cout<<"Sorry the list empty"<<endl;

					 else
					 {
						cout<<"Enter the ID of two participant that you wana to exchange it's info."<<endl;
						cin>>d1>>d2;
						dd1=findhim(d1);
						dd2=findhim(d2);
						if(dd1==-1 || dd2==-1)
						 cout<<"One of your participant that you entered it's ID not exist"<<endl;

						 else
						  {
							phoneinfo t=list[dd1];
							list[dd1]=list[dd2];
							list[dd2]=t;
						  }
					 }

			  }



			 void printpar()
			 {
				int t,idp;
            if(top==-1)
				cout<<"Sorry the list empty"<<endl;

				else
				{
				  cout<<"Enter the ID of the participant that you wana to print it's info."<<endl;
				  cin>>idp;
				  t=findhim(idp);
					 if(t==-1)
					 cout<<"No one have this ID"<<endl;
					 else
					 list[t].print();
				}
			 }

				void text()
				{
				 for(int i=0;i<=top;i++)
				 list[i].printtext();
				}
};
main()
{
cout<<"***********************( THE ADDRESS PHONE )****************************"<<endl;
phoneadd addressbok;
int num;
cout<<"*******Enter the number of the thing you wana do*******"<<endl;
	while(num !=15)
	{
	cout<<"1.Add new participant."<<endl;
	cout<<"2.Search for a participant (By ID)."<<endl;
	cout<<"3.Search for a participant (BY Full Name)"<<endl;
	cout<<"4.Delete a participant."<<endl;
	cout<<"5.Modify a participant object."<<endl;
	cout<<"6.Make work phone call for a participant."<<endl;
	cout<<"7.Print all the E-Mail's for a participant."<<endl;
	cout<<"8.Search a bout work phone number."<<endl;
	cout<<"9.Add E-Mail for a participant."<<endl;
	cout<<"10.Search for E-Mail."<<endl;
	cout<<"11.Delete E-Mail for a participant."<<endl;
	cout<<"12.Exchange two participant's information."<<endl;
	cout<<"13.Print all information of a participant."<<endl;
	cout<<"14.Print all participants in the list. (the result should be stored in a text file)"<<endl;
	cout<<"15.Quit."<<endl;
	cin>>num;
	  if(num==1)
	  {
		phoneinfo rudina;
		rudina.setinfo();
		addressbok.add(rudina);
	  }
	  if(num==2)
	  {
		addressbok.search_id();
	  }
	  if(num==3)
	  {
		addressbok.search_name();
	  }
	  if(num==4)
	  {
		addressbok.delet();
	  }
	  if(num==5)
	  {
		addressbok.modify();
	  }
	  if(num==6)
	  {
		addressbok.set_workphone();
	  }
	  if(num==7)
	  {
		 addressbok.print_email();
	  }

	  if(num==8)
	  {
		 addressbok.searchwp();
	  }
	  if(num==9)
	  {
		 addressbok.addemail();
	  }
	  if(num==10)
	  {
		 addressbok.searchemail() ;
	  }
	  if(num==11)
	  {
		addressbok.delemail();
	  }
	  if(num==12)
	  {
		addressbok.exchange();
	  }
	  if(num==13)
	  {
		 addressbok.printpar();
	  }
	  if(num==14)
	  {
       addressbok.text();
	  }

	}
}

























Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon

Reputation: 1892
  • View blog
  • Posts: 5,681
  • Joined: 25-December 09

Re: a phone/address book class

Posted 07 February 2012 - 04:17 PM

The first thing I am going to suggest is that you separate the class definition from the class implementation. Second most of your class functions don't make sense, they seem to be trying to work with multiple "addresses" but your member data will only hold one "address". So I really think you need to rethink your class.

Also you should investigate acquiring a newer compiler, your compiler is very outdated.

Jim
Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is offline

  • Programmer
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,084
  • Joined: 19-February 09

Re: a phone/address book class

Posted 07 February 2012 - 05:29 PM

Hi, not sure what you are trying to do with the pointer, string *y=email-c. It is not correct and not needed you can use email directly.

void getemail()
{
  cout << "Your emails are :";

  for(int i=0; i<c; i++)
    cout << i+1 << "-" << email[i] << endl;
			 
  cout<<endl;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1