Advertisement
agusbd

responsi plug 8

Dec 6th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. //constant for login with nim and passwddeclared
  6. const int id= 123160064;
  7. const char passwd[30]= "agus@123";
  8. //public array to store data
  9. int harga[100],jumlah[100],total[100];
  10. char namabarang[][30]={};
  11.  
  12. //declaration of function
  13. void baliknama();
  14. void inputdata(int *a);
  15. void rekapdata(int a);
  16. void tambahdata(int *a);
  17. void matriks();
  18.  
  19. //storing of total shoping
  20. int totalbelanja=0;
  21.  
  22.  
  23. //main begin
  24. main()
  25. {
  26.  
  27. int nim;
  28. char password[30];
  29. cout<<"Selamat datang di responsi"<<endl;
  30. cout<<"masukan nim      : ";cin>>nim;
  31. cin.ignore();
  32. cout<<"masukan password : ";cin.getline(password,30);
  33. while(1)
  34. {
  35.     if(nim==id&&strcmp(passwd,password)==0)
  36.         break;
  37.     if(nim!=id)
  38.     {
  39.         cout<<"nim salah"<<endl;
  40.     }
  41.     else
  42.     if(strcmp(passwd,password)==1)
  43.     {
  44.         cout<<"password salah"<<endl;
  45.     }
  46.     else
  47.     if(strcmp(passwd,password)==1&&nim!=id)
  48.     {
  49.         cout<<"nim &password salah"<<endl;
  50.     }
  51.  
  52.     cout<<"masukan nim      : ";cin>>nim;
  53.     cin.ignore();
  54.     cout<<"masukan password : ";cin.getline(password,30);
  55. }
  56.  
  57. char y;
  58. int menu,jml;
  59. //do while for show menu multiple times
  60. do{
  61.  
  62.     cout<<"Menu"<<endl;
  63.     cout<<"1. Balik nama"<<endl;
  64.     cout<<"2. Input Data"<<endl;
  65.     cout<<"3. Rekap Data"<<endl;
  66.     cout<<"4. Tambah Data"<<endl;
  67.     cout<<"5. Matriks"<<endl;
  68.     cout<<"pilih : ";cin>>menu;
  69.  
  70.     // get your switch here
  71.     switch(menu)
  72.     {
  73.     case 1:
  74.         baliknama();
  75.         cout<<"kembali ke menu utama? y/n";cin>>y;
  76.         break;
  77.     case 2 :
  78.         inputdata(&jml);
  79.         cout<<"kembali ke menu utama? y/n";cin>>y;
  80.         break;
  81.     case 3 :
  82.         rekapdata(jml);
  83.         cout<<"kembali ke menu utama? y/n";cin>>y;
  84.         break;
  85.     case 4:
  86.         tambahdata(&jml);
  87.         cout<<"kembali ke menu utama? y/n";cin>>y;
  88.         break;
  89.     case 5:
  90.     matriks();
  91.     cout<<"kembali ke menu utama? y/n";cin>>y;
  92.     break;
  93.     }
  94.  
  95.  
  96. }
  97.  
  98. while(y=='y');
  99. }
  100.  
  101. //print your name backwards
  102. void baliknama()
  103. {
  104.     char nama[30];int x;
  105.     cin.ignore();
  106.     cout<<"masukan nama : ";cin.getline(nama,30);
  107.     x=strlen(nama);
  108.     for(int i=x-1;i>=0;i--)
  109.     {
  110.         cout<<nama[i];
  111.  
  112.     }
  113.     cout<<endl;
  114.  
  115.  
  116. }
  117.  //input to our arrays
  118. void inputdata(int *a)
  119. {   int x=total[1],y=jumlah[1],z=jumlah[1],posx,posy,posz;
  120.     cout<<"masukan jumlah barang : ";cin>>*a;
  121.   for(int i=1;i<=*a;i++)
  122.   {
  123.       cout<<"data ke "<<i<<endl;
  124.       cout<<"masukan nama barang :";cin.ignore();cin.getline(namabarang[i],30);
  125.       cout<<"masukan harga :";cin>>harga[i];
  126.       cout<<"masukan jumlah :";cin>>jumlah[i];
  127.  
  128.       total[i]=jumlah[i]*harga[i];
  129.  
  130.   }
  131.  
  132. }
  133.  
  134. //print our arrays
  135. void rekapdata(int a)
  136. {
  137.   for(int i=1;i<=a;i++)
  138.   {
  139.  
  140.       cout<<"data ke "<<i<<endl;
  141.       cout<<"nama barang : "<<namabarang[i]<<endl;
  142.       cout<<"++++++++++++++++++++++++++++++"<<endl;
  143.       cout<<"|harga   : "<<harga[i]<<endl;
  144.       cout<<"|jumlah  : "<<jumlah[i]<<endl;
  145.       cout<<"|total   : "<<total[i]<<endl;
  146.       cout<<"++++++++++++++++++++++++++++++"<<endl<<endl;
  147.   }
  148.  
  149.   //get max,min value
  150.   int x=0,y=0,z=999999999,posx,posy,posz;
  151.   for(int i=1;i<=a;i++)
  152.   {
  153.       if(x<harga[i])
  154.         {
  155.             x=harga[i];
  156.             posx=i;
  157.  
  158.         }
  159.        if(y<total[i])
  160.         {
  161.             y=total[i];
  162.             posy=i;
  163.  
  164.         }
  165.         if(z>total[i])
  166.         {
  167.             z=total[i];
  168.             posz=i;
  169.  
  170.         }
  171.       totalbelanja+=total[i];
  172.  
  173.   }
  174.   cout<<"total belanja         = " <<totalbelanja<<endl;
  175.   cout<<"harga termahal        = " <<namabarang[posx]<<endl;
  176.   cout<<"total terbesar        = " <<namabarang[posy]<<endl;
  177.   cout<<"total terkecil        = " <<namabarang[posz]<<endl;
  178.  
  179.  
  180.  
  181. }
  182.  
  183. //add datain arrays
  184. void tambahdata(int *a){
  185. int tambah;
  186. cout<<"masukan jumlah data tambahan : ";cin>>tambah;
  187. for(int i = *a+1;i<=*a+tambah;i++)
  188. {
  189.       cout<<"data ke "<<i<<endl;
  190.       cout<<"masukan nama barang :";cin.ignore();cin.getline(namabarang[i],30);
  191.       cout<<"masukan harga :";cin>>harga[i];
  192.       cout<<"masukan jumlah :";cin>>jumlah[i];
  193.  
  194.       total[i]=jumlah[i]*harga[i];
  195.  
  196. }
  197. *a+=tambah;
  198.  
  199.  
  200. }
  201. //logic matrix procedure start here
  202. void matriks(){
  203.     int angka,limit;
  204.     cout<<"masukan angka : ";cin>>angka;
  205.     limit = angka;
  206.     for(int i=0;i<angka;i++)
  207.     {
  208.         for(int j=0;j<angka;j++)
  209.         {
  210.                 cout<<(limit-1)*(j-1)<<" \t ";
  211.         }
  212.     limit--;
  213.    cout<<endl;
  214.     }
  215.  
  216. }
  217.  
  218. //end of code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement