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";
}
}

New Topic/Question
Reply



MultiQuote






|