asmanhaikal

Program C++ Input dan Hapus Data dalam Array

Dec 9th, 2020
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <conio.h>
  2. #include <iostream>
  3. using namespace std;
  4. //mendeklarasikan tipe data.
  5. struct data{
  6. char nama[20];};
  7. data batas[100];
  8. int a,b,c,d;
  9. //bismillah, yo bisa yo
  10. void inputdata()
  11. {    cout<<"\nJumlah data yang akan diinput [1 - 100++] : ";cin>>b;
  12.    d=0;
  13.    for(c=0;c<b;c++){
  14.    d=d+1;
  15.    cout<<"\nData ke-"<<d<<endl;
  16.    cout<<"Nama\t: ";cin>>batas[a].nama;
  17.    //input data tidak support spasi, maaf belum nemu solusinya. hh
  18.    
  19.    a++;}system("cls");}
  20.  
  21.  
  22.  
  23. void lihatdata()
  24. {int i,j;
  25.  cout<<"\n================================= Lihat Data =================================\n\n";
  26.  cout<<"-------------------------------------------------------------------------------\n";
  27.  cout<<"||\tData ke-\t|||\tNama\t\t||\n";
  28.  j=0;
  29.  for(i=0;i<a;i++)
  30.  {j=j+1;
  31.   cout<<"..............................................................................\n";
  32.   cout<<"||\t"<<j<<"\t\t||\t";
  33.   cout<<batas[i].nama<<"\t\t||"; cout<<endl;
  34.   }
  35.   cout<<".............................................................................. ";getch();system("cls");}
  36.  
  37. void caridata()
  38. {
  39. int n,l;
  40. cout<<"-------------------------------------------------------------------------------\n";
  41. cout<<"\tCari Data Indeks ke- : ";cin>>n;
  42.  cout<< "\tHasil = " << batas[n].nama; cout<<endl;
  43.  
  44. }
  45.  
  46. void hapusdata()
  47. {int x,y;
  48.  cout<<"Hapus data ke-";cin>>x;
  49.  y=x-1;
  50.  a--;
  51.  for(int i=y;i<a;i++)
  52.  {batas[i]=batas[i+1];}
  53.  system("cls");
  54.  cout<<"\n\n\n\n\n\n\n\n\n++++++++++++++++++++++++++++++ Hore.. Data ke-"<<x<<" Berhasil dihapus ++++++++++++++++++++++++++++++";
  55.  getch();system("cls");
  56. }
  57.  
  58. void editdata(){
  59. int k,l;
  60. cout<<"Mau edit data yang ke- : ";cin>>k;
  61. l=k-1;
  62. cout<<"Nama\t: ";cin>>batas[l].nama;
  63.  
  64. lihatdata();
  65. }
  66. //semangat kall
  67. int main(){
  68.      int pilih;
  69.      char w;
  70.     cout<<"\t----------------------------------------------------------------\n";
  71.     cout<<"\t-----------------......... Bismillah ..........------------------\n";
  72.     cout<<"\t------------------Code by : www.idnpedia.com----------------------\n";
  73.     cout<<"\t----------------------------------------------------------------\n";
  74.     getch ();
  75.     system("cls");
  76.  
  77.     //bismillah, smgt kall,, yoo bisa yo..
  78.   awal:
  79.   cout<<"\n================================ MENU PILIHAN12 =================================";
  80.   cout<<"\n1. Masukkan data";
  81.   cout<<"\n2. Tampilkan Data";
  82.   cout<<"\n3. Edit Data";
  83.   cout<<"\n4. Hapus Data";
  84.   cout<<"\n5. Cari Data";
  85.   cout<<"\n6. Keluar";
  86.   cout<<"\n\nMasukkan Pilihan : ";
  87.   cin>>pilih;
  88.   if(pilih==1)
  89.    {system("cls");inputdata();goto awal;}
  90.   if(pilih==2)
  91.    {system("cls");lihatdata();goto awal;}
  92.   if(pilih==3)
  93.    {system("cls");editdata();goto awal;}
  94.   if(pilih==4)
  95.    {system("cls");hapusdata();goto awal;}
  96.   if(pilih==5)
  97.    {system("cls");caridata();goto awal;}
  98.   if(pilih==6)
  99.    {system("cls");
  100.     //membuat menu pilihan keluar
  101.     cout<<"\nYakin kak mau keluar dari Program? {Y / N] : \n" ; cin >> w;
  102.     if(w=='y'||w=='Y')
  103.     {system("cls");
  104.      cout<<"\n\n\n\n\n............................ Hore Selesai ............................... \n";}
  105.     if(w=='n'||w=='N')
  106.            {system("cls");goto awal;}}
  107.   else
  108.    {system("cls");cout<<"Pilihan 1-6";getch();system("cls");goto awal;}
  109. }
RAW Paste Data