Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- //constant for login with nim and passwddeclared
- const int id= 123160064;
- const char passwd[30]= "agus@123";
- //public array to store data
- int harga[100],jumlah[100],total[100];
- char namabarang[][30]={};
- //declaration of function
- void baliknama();
- void inputdata(int *a);
- void rekapdata(int a);
- void tambahdata(int *a);
- void matriks();
- //storing of total shoping
- int totalbelanja=0;
- //main begin
- main()
- {
- int nim;
- char password[30];
- cout<<"Selamat datang di responsi"<<endl;
- cout<<"masukan nim : ";cin>>nim;
- cin.ignore();
- cout<<"masukan password : ";cin.getline(password,30);
- while(1)
- {
- if(nim==id&&strcmp(passwd,password)==0)
- break;
- if(nim!=id)
- {
- cout<<"nim salah"<<endl;
- }
- else
- if(strcmp(passwd,password)==1)
- {
- cout<<"password salah"<<endl;
- }
- else
- if(strcmp(passwd,password)==1&&nim!=id)
- {
- cout<<"nim &password salah"<<endl;
- }
- cout<<"masukan nim : ";cin>>nim;
- cin.ignore();
- cout<<"masukan password : ";cin.getline(password,30);
- }
- char y;
- int menu,jml;
- //do while for show menu multiple times
- do{
- cout<<"Menu"<<endl;
- cout<<"1. Balik nama"<<endl;
- cout<<"2. Input Data"<<endl;
- cout<<"3. Rekap Data"<<endl;
- cout<<"4. Tambah Data"<<endl;
- cout<<"5. Matriks"<<endl;
- cout<<"pilih : ";cin>>menu;
- // get your switch here
- switch(menu)
- {
- case 1:
- baliknama();
- cout<<"kembali ke menu utama? y/n";cin>>y;
- break;
- case 2 :
- inputdata(&jml);
- cout<<"kembali ke menu utama? y/n";cin>>y;
- break;
- case 3 :
- rekapdata(jml);
- cout<<"kembali ke menu utama? y/n";cin>>y;
- break;
- case 4:
- tambahdata(&jml);
- cout<<"kembali ke menu utama? y/n";cin>>y;
- break;
- case 5:
- matriks();
- cout<<"kembali ke menu utama? y/n";cin>>y;
- break;
- }
- }
- while(y=='y');
- }
- //print your name backwards
- void baliknama()
- {
- char nama[30];int x;
- cin.ignore();
- cout<<"masukan nama : ";cin.getline(nama,30);
- x=strlen(nama);
- for(int i=x-1;i>=0;i--)
- {
- cout<<nama[i];
- }
- cout<<endl;
- }
- //input to our arrays
- void inputdata(int *a)
- { int x=total[1],y=jumlah[1],z=jumlah[1],posx,posy,posz;
- cout<<"masukan jumlah barang : ";cin>>*a;
- for(int i=1;i<=*a;i++)
- {
- cout<<"data ke "<<i<<endl;
- cout<<"masukan nama barang :";cin.ignore();cin.getline(namabarang[i],30);
- cout<<"masukan harga :";cin>>harga[i];
- cout<<"masukan jumlah :";cin>>jumlah[i];
- total[i]=jumlah[i]*harga[i];
- }
- }
- //print our arrays
- void rekapdata(int a)
- {
- for(int i=1;i<=a;i++)
- {
- cout<<"data ke "<<i<<endl;
- cout<<"nama barang : "<<namabarang[i]<<endl;
- cout<<"++++++++++++++++++++++++++++++"<<endl;
- cout<<"|harga : "<<harga[i]<<endl;
- cout<<"|jumlah : "<<jumlah[i]<<endl;
- cout<<"|total : "<<total[i]<<endl;
- cout<<"++++++++++++++++++++++++++++++"<<endl<<endl;
- }
- //get max,min value
- int x=0,y=0,z=999999999,posx,posy,posz;
- for(int i=1;i<=a;i++)
- {
- if(x<harga[i])
- {
- x=harga[i];
- posx=i;
- }
- if(y<total[i])
- {
- y=total[i];
- posy=i;
- }
- if(z>total[i])
- {
- z=total[i];
- posz=i;
- }
- totalbelanja+=total[i];
- }
- cout<<"total belanja = " <<totalbelanja<<endl;
- cout<<"harga termahal = " <<namabarang[posx]<<endl;
- cout<<"total terbesar = " <<namabarang[posy]<<endl;
- cout<<"total terkecil = " <<namabarang[posz]<<endl;
- }
- //add datain arrays
- void tambahdata(int *a){
- int tambah;
- cout<<"masukan jumlah data tambahan : ";cin>>tambah;
- for(int i = *a+1;i<=*a+tambah;i++)
- {
- cout<<"data ke "<<i<<endl;
- cout<<"masukan nama barang :";cin.ignore();cin.getline(namabarang[i],30);
- cout<<"masukan harga :";cin>>harga[i];
- cout<<"masukan jumlah :";cin>>jumlah[i];
- total[i]=jumlah[i]*harga[i];
- }
- *a+=tambah;
- }
- //logic matrix procedure start here
- void matriks(){
- int angka,limit;
- cout<<"masukan angka : ";cin>>angka;
- limit = angka;
- for(int i=0;i<angka;i++)
- {
- for(int j=0;j<angka;j++)
- {
- cout<<(limit-1)*(j-1)<<" \t ";
- }
- limit--;
- cout<<endl;
- }
- }
- //end of code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement