Sisco
Sisco
#include<conio.h>
#include<string>
using namespace std;
const int size=10;
int good=0;
class contacts_log{
private:
string name;
int number;
string address;
int age;
public:
contacts_log(){
name = "name";
number = 0;
address = " ";
age = 0;
}
contacts_log(string name, int number, string address, int age)
:name(name), number(number), address(address), age(age) {}
void printed_info() {
cout <<"-----------------------------------" <<endl;
cout << "name is :" << name<<endl;
cout << "number is :" << number<<endl;
cout << "address is :" << address<<endl;
cout << "age is :" << age<<endl;
cout<<"-----------------------------------"<<endl;
}
string get_name() {
return name;
}
int get_number() {
return number;
}
string get_address() {
return address;
}
int get_age() {
return age;
}
void update_name(string new_name) {
name = new_name;
}
void update_number(int new_number) {
number = new_number;
}
void update_address(string new_address) {
address = new_address;
}
void update_age(int new_age) {
age = new_age;
}
};
class record_communication {
}
int saerch_n(int number,int op) {
int n=-1;
for (int i = 0; i < index; i++)
{
if (number == a[i].get_number())
{ if(op==2)
a[i].printed_info();
n=i;}
}
return n;
}
int saerch_a(string address,int op) {int n=-1;
for (int i = 0; i < index; i++)
{
if (address == a[i].get_address())
{ if(op==2)
a[i].printed_info();
n=i;}
}
return n;
}
int saerch_a(int age,int op) {int n=-1;
for (int i = 0; i < index; i++)
{
if (age== a[i].get_age())
{ if(op==2)
a[i].printed_info();
n=i;}
}
return n;
}
};
int main(){
record_communication r1;
string name,address,na_old,na_new,ad_old,ad_new;
int number, age,i, nu_old, nu_new, op, n,a_old,a_new;
cout<<"\n\n \t\t\t ***************************** \n";
cout<<" \t\t\t *** Welcome to my program *** \n";
cout<<" \t\t\t ***************************** \n\n\n";
cout<<" \t 01- to add contact \n";
cout<<" \t 02- to update name.\n";
cout<<" \t 03- to update number.\n";
cout<<" \t 04- to update address.\n";
cout<<" \t 05- to update age.\n";
cout<<" \t 06- to search name.\n";
cout<<" \t 07- to search number.\n";
cout<<" \t 08- to search address.\n";
cout<<" \t 09- to search age.\n";
cout<<" \t 10- to print information of contacts.\n";
cout<<" \t 11- Exit.\n";
start_menu:
do{ cout<<"\t\t\t ***************************** \n\n\n";
cout<<"enter number:";
cin>>n;
if(n!=1 && good!=1)
n=12;
switch (n)
{
case 1:
cout<<"\t\t\t *******************\n";
cout<<"\t\t\t *** add contact ***\n";
cout<<"\t\t\t *******************\n";
cout<<"\n enter the number :";
cin>>number;
cout<<"\n enter the age :";
cin>>age;
cout<<"\n enter the name :";
cin>>name;
cout<<"\n enter the address :";
cin>>address;
r1.insert(name,number,address,age);
good=1;
break;
case 2:
cout<<"\t\t\t **********************************\n";
cout<<"\t\t\t *** update name. ***\n";
cout<<"\t\t\t **********************************\n";
cout<<"\n enter the old name :";
cin>>na_old;
cout<<"\n enter the new name :";
cin>>na_new;
cout<<"\n Do you want to print the data after and before
modification?\n if you want to print,press 1 or 0 if you do not want
to print. \n";
repeat_1:
cin>>op;
switch(op)
{case 0:
i=r1.saerch_n(na_old,1);
if(i!=-1)
r1.a[i].update_name(na_new);
else
cout<<"\n this is name not found \n";
break;
case 1:
i=r1.saerch_n(na_old,2);
if(i!=-1)
{r1.a[i].update_name(na_new);
r1.a[i].printed_info();}
else
cout<<"\n this is name not found \n";
break;
default:
cout<<"error? enter again\n\n";
goto repeat_1;}
break;
case 3:
cout<<"\t\t\t ***********************\n";
cout<<"\t\t\t *** update number. ***\n";
cout<<"\t\t\t **********************\n";
cout<<"\n enter the old number :";
cin>>nu_old;
cout<<"\n enter the new number :";
cin>>nu_new;
cout<<"\n Do you want to print the data after and before
modification?\n if you want to print,press 1 or 0 if you do not want
to print. \n";
repeat_2:
cin>>op;
switch(op)
{case 0:
i=r1.saerch_n(nu_old,1);
if(i!=-1)
r1.a[i].update_number(nu_new);
else
cout<<"\n this is number not found \n";
break;
case 1:
i=r1.saerch_n(nu_old,2);
if(i!=-1)
{r1.a[i].update_number(nu_new);
r1.a[i].printed_info();}
else
cout<<"\n this is number not found \n";
break;
default:
cout<<"error? enter again\n\n";
goto repeat_2;}
break;
case 4:
cout<<"\t\t\t ***********************\n";
cout<<"\t\t\t *** update address. ***\n";
cout<<"\t\t\t ***********************\n";
cout<<"\n enter the old address :";
cin>>ad_old;
cout<<"\n enter the new address :";
cin>>ad_new;
cout<<"\n Do you want to print the data after and before
modification?\n if you want to print,press 1 or 0 if you do not want
to print. \n";
repeat_3:
cin>>op;
switch(op)
{case 0:
i=r1.saerch_a(ad_old,1);
if(i!=-1)
r1.a[i].update_address(ad_new);
else
cout<<"\n this is address not found \n";
break;
case 1:
i=r1.saerch_a(ad_old,2);
if(i!=-1)
{r1.a[i].update_address(ad_new);
r1.a[i].printed_info();}
else
cout<<"\n this is address not found \n";
break;
default:
cout<<"error? enter again\n\n";
goto repeat_3;}
break;
case 5:
cout<<"\t\t\t *******************\n";
cout<<"\t\t\t *** update age. ***\n";
cout<<"\t\t\t *******************\n";
cout<<"\n enter the old age :";
cin>>a_old;
cout<<"\n enter the new age :";
cin>>a_new;
cout<<"\n Do you want to print the data after and before
modification?\n if you want to print,press 1 or 0 if you do not want
to print. \n";
repeat_4:
cin>>op;
switch(op)
{case 0:
i=r1.saerch_a(a_old,1);
if(i!=-1)
r1.a[i].update_age(a_new);
else
cout<<"\n this is age not found \n";
break;
case 1:
i=r1.saerch_a(a_old,2);
if(i!=-1)
{r1.a[i].update_age(a_new);
r1.a[i].printed_info();}
else
cout<<"\n this is age not found \n";
break;
default:
cout<<"error? enter again\n\n";
goto repeat_4;}
break;
case 6:
cout<<"\t\t\t ********************\n";
cout<<"\t\t\t *** search name. ***\n";
cout<<"\t\t\t ********************\n";
cout<<"\n enter the name :";
cin>>name;
i=r1.saerch_n(name,2);
if(i==-1)
cout<<"\n this is name not found \n";
break;
case 7:
cout<<"\t\t\t **********************\n";
cout<<"\t\t\t *** search number. ***\n";
cout<<"\t\t\t **********************\n";
cout<<"\n enter the number :";
cin>>number;
i=r1.saerch_n(number,2);
if(i==-1)
cout<<"\n this is number not found \n";
break;
case 8:
cout<<"\t\t\t ***********************\n";
cout<<"\t\t\t *** search address. ***\n";
cout<<"\t\t\t ***********************\n";
cout<<"\n enter the address :";
cin>>address;
i=r1.saerch_a(address,2);
if(i==-1)
cout<<"\n this is address not found \n";
break;
case 9:
cout<<"\t\t\t *******************\n";
cout<<"\t\t\t *** search age. ***\n";
cout<<"\t\t\t *******************\n";
cout<<"\n enter the age :";
cin>>age;
i=r1.saerch_a(age,2);
if(i==-1)
cout<<"\n this is age not found \n";
break;
case 10:
cout<<"\t\t\t **************************************\n";
cout<<"\t\t\t *** print information of contacts. ***\n";
cout<<"\t\t\t **************************************\n";
r1.printed_all();
break;
case 11:return 0;
break;
default:
cout<<"error? enter again\n\n";
goto start_menu;}}while(n!=11);
_getch();
return 0;
}