Advertisement
yousif199

Untitled

Oct 18th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.69 KB | None | 0 0
  1.  
  2. #include<iostream.h>
  3.  
  4. #include<string.h>
  5.  
  6. #include<conio.h>
  7.  
  8. #include <stdlib.h>
  9.  
  10. struct phone
  11.  
  12. {
  13.  
  14. char name[50];
  15.  
  16. char address[20];
  17.  
  18. long  number;
  19.  
  20. }x[50];
  21.  
  22. //All Rights Reserved I: Wael Adel Alselwi ©
  23.  
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25.  
  26. int a,b=0,c=1,q=0;
  27.  
  28.  
  29. void input()
  30.  
  31. {
  32.  
  33.     int s;
  34.  
  35.       do
  36.  
  37.       {
  38.  
  39.           b=b+1;
  40.  
  41.           c=c+1;
  42.  
  43.  
  44.     for( a=b;a<c;a++)
  45.  
  46.     { q=q+a;
  47.  
  48.       cout<<"name ["<<a<<"]=";
  49.  
  50.       cin>>x[a].name;
  51.  
  52.       cout<<"address ["<<a<<"]=";
  53.  
  54.       cin>>x[a].address;
  55.  
  56.       cout<<"phone ["<<a<<"]=";
  57.  
  58.       cin>>x[a].number;
  59.  
  60.         cout<<"---------------------------------------------\n";
  61.  
  62.  
  63.              }
  64.  
  65.          cout<<"\nPlease press [1] to add another user\nPlease press [0] to return to the main menu \n";
  66.  
  67.             cin>>s;
  68.  
  69.  
  70.       } while(s==1);
  71.  
  72.  }
  73.  
  74.  
  75. //All Rights Reserved I: Wael Adel Alselwi ©
  76.  
  77. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78.  
  79. void SearchName()
  80.  
  81. {int r;
  82.  
  83.  char ser[20];
  84.  
  85. cin>>ser;
  86.  
  87.  for(int j=0;j<q+1;j++)
  88.  
  89.   {r=strcmp(ser,x[j].name);
  90.  
  91.  
  92.     //by:With regards to the programmer: Wael Adel Alselwi ©
  93.  
  94.     if(r==0)
  95.  
  96.   { cout<<"ok\n";
  97.  
  98.   cout<<"name          address       number\n";
  99.  
  100.   cout<<x[j].name<<"            ";
  101.  
  102.   cout<<x[j].address<<"           ";
  103.  
  104.   cout<<x[j].number<<"  \n";
  105.  
  106.     }
  107.  
  108.   }
  109.  
  110. }
  111.  
  112. //All Rights Reserved I: Wael Adel Alselwi ©
  113.  
  114. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  115.  
  116. void SearchTitle()
  117.  
  118. { int g;
  119.  
  120. char serr[20];
  121.  
  122. cin>>serr;
  123.  
  124.  for(int h=0;h<q+1;h++)
  125.  
  126.  {g=strcmp(serr,x[h].address);
  127.  
  128.   if(g==0)
  129.  
  130.   {cout<<"#######\n";
  131.  
  132.     cout<<"   ok  \n";
  133.  
  134.     cout<<"########\n\n";
  135.  
  136.     cout<<"address              name                number\n";
  137.  
  138.     cout<<x[h].address<<"                    "<<x[h].name<<"                   "<<x[h].number<<"\n\n";
  139.  
  140.     }
  141.  
  142.   }
  143.  
  144. }
  145.  
  146.  
  147. //All Rights Reserved I: Wael Adel Alselwi ©
  148.  
  149. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  150.  
  151. void DataShow()
  152.  
  153.  {
  154.  
  155.  
  156.   for(int a=0;a<q+1;a++)
  157.  
  158.  {cout<<x[a].name<<"               ";
  159.  
  160.   cout<<x[a].address<<"             ";
  161.  
  162.   cout<<x[a].number;
  163.  
  164.   cout<<"\n------------------------------------------";
  165.  
  166.   cout<<"\n\n";
  167.  
  168.   }
  169.  
  170. }
  171.  
  172. //All Rights Reserved I: Wael Adel Alselwi ©
  173.  
  174. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  175.  
  176. void MainMenu()
  177.  
  178. { cout<<"       by:All Rights Reserved I: Wael Adel Alselwi ©\n";
  179.  
  180. cout<<"          You are welcome to phone program   \n";
  181.  
  182. cout<<"             << Main Menu >>                 \n";
  183.  
  184. cout<<"********************************************\n";
  185.  
  186. cout<<"* 1-Add a new user                      *\n";
  187.  
  188. cout<<"* 2-To search for users                    *\n";
  189.  
  190. cout<<"* 3-Show all users                         *\n";
  191.  
  192. cout<<"* 4-Edit user data                         *\n";
  193.  
  194. cout<<"* 5-Delete user data                       *\n";
  195.  
  196. cout<<"********************************************\n";
  197.  
  198.  
  199. cout<<"Please enter the number[1-or-2-or-3-or-4-or-5] ";
  200.  
  201. }
  202.  
  203.  
  204. //All Rights Reserved I: Wael Adel Alselwi ©
  205.  
  206. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  207.  
  208. void edit()
  209.  
  210.  {int u;
  211.  
  212.  
  213.   cin>>u;
  214.  
  215.  
  216.   for(a=u;a<u+1;a++)
  217.  
  218.     {cout<<"name old= (* "<<a<<"  "<<x[a].name<<" *) new name  = ";
  219.  
  220.      cin>>x[a].name;
  221.  
  222.      cout<<"address old= (* "<<a<<"  "<<x[a].address<<" *) new address = ";
  223.  
  224.      cin>>x[a].address;
  225.  
  226.      cout<<"numbre phone old= (* "<<a<<"  "<<x[a].number<<" \n*) new numbre phone = ";
  227.  
  228.      cin>>x[a].number;
  229.  
  230.      }
  231.  
  232.  }
  233.  
  234.  
  235. //All Rights Reserved I: Wael Adel Alselwi ©
  236.  
  237. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  238.  
  239. void MessageBack()
  240.  
  241. {cout<<"Back to the main menu press the number (0)\n";
  242.  
  243. }
  244.  
  245. //by:With regards to the programmer: Wael Adel Alselwi ©
  246.  
  247. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  248.  
  249. void ForDelete()
  250.  
  251. { cout<<"Select the User ID you want to delete \n";
  252.  
  253. int m;
  254.  
  255. cin>>m;
  256.  
  257. for(a=m;a<q;a++)
  258.  
  259. {strcpy(x[a].name,x[a+1].name);
  260.  
  261.  strcpy(x[a].address,x[a+1].address);
  262.  
  263.  x[a].number=x[a+1].number;
  264.  
  265.  }
  266.  
  267.  }
  268.  
  269.  
  270. //All Rights Reserved I: Wael Adel Alselwi ©
  271.  
  272. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  273.  
  274.  main()
  275.  
  276. {  int p;
  277.  
  278.  
  279.      do
  280.  
  281.     {
  282.  
  283.      int i,t,w;
  284.  
  285.      MainMenu();
  286.  
  287.      int g;
  288.  
  289. cin>>g;
  290.  
  291.  if(g!=1&&g!=2&&g!=3&&g!=4&&g!=5)
  292.  
  293.   {cout<<"error\nExiting The program"<<endl;
  294.  
  295.  
  296.   exit(1);
  297.  
  298.     }
  299.  
  300.  
  301.   switch(g)
  302.  
  303. {case 1:
  304.  
  305. clrscr();
  306.  
  307. cout<<"Please enter data\n";
  308.  
  309. input();
  310.  
  311. MessageBack();
  312.  
  313. cin>>p;
  314.  
  315. if(p!=0)
  316.  
  317. {cout<<"error\nExiting The program"<<endl;
  318.  
  319.  exit(1);
  320.  
  321.  }
  322.  
  323.  
  324. break;
  325.  
  326.  
  327.  case 2:
  328.  
  329. clrscr();
  330.  
  331. cout<<"search users \n";
  332.  
  333. cout<<"To Search by Name Press [1]\nTo search by address Press [2]\n";
  334.  
  335. cout<<"plese enter number [1-or-2]";
  336.  
  337. int o;
  338.  
  339. cin>>o;
  340.  
  341. if(o==1)
  342.  
  343. {cout<<"Please enter the name you want that you're looking for \n";
  344.  
  345. SearchName();
  346.  
  347.  MessageBack();
  348.  
  349. cin>>p;
  350.  
  351.  }
  352.  
  353. else if(o==2)
  354.  
  355. {cout<<"Please enter the address you want that you're looking for \n";
  356.  
  357. SearchTitle();
  358.  
  359. MessageBack();
  360.  
  361. cin>>p;
  362.  
  363.  }
  364.  
  365. else if(o<0||o>2)
  366.  
  367. {cout<<"not found\?";
  368.  
  369. MessageBack();
  370.  
  371. cin>>p;
  372.  
  373.  }
  374.  
  375.  
  376. break;
  377.  
  378.  
  379.  case 3:
  380.  
  381. clrscr();
  382.  
  383. cout<<"\n\n";
  384.  
  385. cout<<"name            address         number\n";
  386.  
  387. DataShow();
  388.  
  389. MessageBack();
  390.  
  391. cin>>p;
  392.  
  393.  
  394. break;
  395.  
  396.  
  397.  case 4:
  398.  
  399. clrscr();
  400.  
  401. cout<<"\n\n";
  402.  
  403. cout<<"name          address       number\n";
  404.  
  405. DataShow();
  406.  
  407. cout<<"Modify the data user to select User ID number and then press\n";
  408.  
  409. edit();
  410.  
  411. MessageBack();
  412.  
  413. cin>>p;
  414.  
  415.  
  416. break;
  417.  
  418.  
  419.  
  420.  case 5:
  421.  
  422. cout<<"name          address       number\n";
  423.  
  424. DataShow();
  425.  
  426. ForDelete();
  427.  
  428. cout<<"\n";
  429.  
  430. cout<<"name          address       number\n";
  431.  
  432. DataShow();
  433.  
  434. MessageBack();
  435.  
  436. cin>>p;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement