Advertisement
sidex15

3/11/2019 C++ Assignment

Mar 7th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <iomanip.h>
  7.  
  8. char name[100][100],sect[100][100],cont[100][100];
  9. int cnt=0;
  10. void add(),view(),search(),del();
  11.  
  12.  
  13. void main(){
  14.  clrscr();
  15.  int opt;
  16.  cout<<"menu: \n";
  17.  cout<<"1. add\n2. view\n3. search\n4. delete\n5. exit\n";
  18.  cin>>opt;
  19.  switch (opt){
  20.   case 1: add(); break;
  21.   case 2: view(); break;
  22.   case 3: search(); break;
  23.   case 4: del(); break;
  24.   default: exit(0);
  25.  }
  26. }
  27.  
  28. void add(){
  29.  clrscr();
  30.  cout<<"Name: ";
  31.  gets(name[cnt]);
  32.  cout<<"section: ";
  33.  gets(sect[cnt]);
  34.  cout<<"contact number: ";
  35.  gets(cont[cnt]);
  36.  cout<<"added success!";
  37.  cnt++;
  38.  getch();
  39.  main();
  40. }
  41.  
  42. void view(){
  43.  clrscr();
  44.  cout<<"\tName\tcourse/section\tcontact\n";
  45.  for (int i=0;i<cnt;i++){
  46.   cout<<"["<<i<<"]\t"<<name[i]<<"\t"<<sect[i]<<"\t"<<cont[i]<<endl;
  47.  }
  48.  getch();
  49.  main();
  50. }
  51.  
  52. void search(){
  53.  clrscr();
  54.  char sname[100];
  55.  int opt=0,index=0,trig=0;
  56.  cout<<"search for:\n1. Index\n2. name\n";
  57.  cin>>opt;
  58.  switch (opt){
  59.   case 1:
  60.     cout<<"search for index: ";
  61.     cin>>index;
  62.     for(int i=0;i<cnt;i++){
  63.     if(index==i){
  64.     cout<<"["<<i<<"]\t"<<name[i]<<"\t"<<sect[i]<<"\t"<<cont[i]<<endl;
  65.     trig=1;
  66.     }
  67.     }
  68.     if(trig==0){
  69.      cout<<"no records found...";
  70.     }
  71.     break;
  72.   case 2:
  73.     cout<<"search for name: ";
  74.     gets(sname);
  75.     for (int j=0;j<cnt;j++){
  76.      if(!strcmp(sname,name[j])){
  77.       cout<<"["<<j<<"]\t"<<name[j]<<"\t"<<sect[j]<<"\t"<<cont[j]<<endl;
  78.      trig=1;
  79.      }
  80.     }
  81.     if(trig==0){
  82.      cout<<"no records found...";
  83.     }
  84.     break;
  85.   default: main();
  86.  }
  87.  getch();
  88.  main();
  89. }
  90.  
  91. void del(){
  92.  clrscr();
  93.  char dname[100];
  94.  int opt=0,index=0,trig=0;
  95.  cout<<"search for:\n1. Index\n2. name\n";
  96.  cin>>opt;
  97.  switch (opt){
  98.   case 1:
  99.     cout<<"search for index: ";
  100.     cin>>index;
  101.     for(int i=0;i<cnt;i++){
  102.     if(index==i){
  103.      for(int k=i;k<cnt;k++){
  104.       strcpy(name[k],name[k+1]);
  105.       strcpy(sect[k],sect[k+1]);
  106.       strcpy(cont[k],cont[k+1]);
  107.       }
  108.      trig=1;
  109.      cout<<"delete successful...";
  110.      }
  111.     }
  112.     if(trig==0){
  113.      cout<<"no records found...";
  114.     }
  115.     break;
  116.   case 2:
  117.     cout<<"search for name: ";
  118.     gets(dname);
  119.     for (int j=0;j<cnt;j++){
  120.      if(!strcmp(dname,name[j])){
  121.        for(int l=j;l<cnt;l++){
  122.       strcpy(name[l],name[l+1]);
  123.       strcpy(sect[l],sect[l+1]);
  124.       strcpy(cont[l],cont[l+1]);
  125.       }
  126.      trig=1;
  127.      cout<<"delete successful...";
  128.      }
  129.     }
  130.     if(trig==0){
  131.      cout<<"no records found...";
  132.     }
  133.     break;
  134.   default: main();
  135.  }
  136.  getch();
  137.  cnt--;
  138.  main();
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement