Thursday 20 June 2024

Program Belanja

 #include <conio.h>

#include <stdio.h>

#include <iostream>

#include <iomanip>

#include <fstream>

#include <cmath>

using namespace std;


int main( )

{

   struct program{

    int hb;

    int jb;

    int t;

    int tb;

    int x;

    int y;

    int z;

    int w;

    float diskon;

    string nama;

    string ket;

    string nb;

    string  user, pass;

    char pa;

};

    program nil[20];

    char a;

    atas:

    int i;

   

    i=1;

do

{

system("cls");

cout<<"================== Login ===================="<<endl;

cout<<""<<endl;

cout<<"Silahkan Masukan Username Anda : ";getline(cin, nil[i].user);

cout<<"Silahkan Masukan Password Anda : ";//cin>>nil[i].pass;

nil[i].pa=_getch();

while(nil[i].pa !=13)

{

    nil[i].pass.push_back(nil[i].pa);

    cout<<'*';

    nil[i].pa=_getch();

}   

if(nil[i].user=="algo"&&nil[i].pass=="12345")

{

cout<<""<<endl;

cout<<""<<endl;

cout<<"Selamat Anda Berhasil Login...."<<endl;

cout<<endl;   

unsigned int pilihan;

    while(pilihan >= 0)

    {

cout << "MENU PILIHAN" << endl;

    cout << "------------------------------" << endl;

    cout << "1. Data Pelanggan             " << endl;

    cout << "2. Hitung x^2 < 40 ?          " << endl;

    cout << "3. Hitung x Kelipatan 2 ?     " << endl;

    cout << "4. Data Belanja               " << endl;

    cout << "5. Exit                       " << endl;

    cout << "------------------------------" << endl;

    cout << "Pilihan Anda (1-5)          : "; cin >> pilihan;

    cout<<endl;

   

if (pilihan == 1)

{

program dt[20];

int i, n;

char ulang;

do

{

system("cls");

cout<<"Masukkan Jumblah Pembeli : ";cin>>n;cin.ignore();

for(i=0;i<n;i++)

{

cout<< "Data ke-"<<i+1<<endl;

cout<< "Masukan Nama            : "; getline(cin, dt[i].nama);

cout<< "Masukan Nama barang     : "; cin>> dt[i].nb;

cout<< "Masukan Jumblah barang  : "; cin>> dt[i].jb;

cout<< "Masukan Harga barang    : "; cin>> dt[i].hb;cin.ignore();

dt[i].t = dt[i].jb * dt[i].hb;

if (dt[i].t > 500000)

{

dt[i].diskon = 0.2;

dt[i].ket = "Dapat diskon 20%";

}

else if(dt[i].t > 200000 && dt[i].t < 500000)

{

dt[i].diskon = 0.15;

dt[i].ket = "Dapat diskon 15%";

}

else 

{

dt[i].diskon = 1;

dt[i].ket = "Tidak dapat diskon";

}

dt[i].tb = dt[i].t * dt[i].diskon;

}

cout<<"                                        DATA PELANGGAN                                                  "<<endl;

cout<<"================================================================================================================="<<endl;

cout<<"| Nama Pembeli    |  Barang     | Jumblah Barang |  Harga Barang  |   TOTAL BAYAR     |    KETERANGAN           |"<<endl;

cout<<"================================================================================================================="<<endl;

for(i=0;i<n;i++)

{

cout<<setiosflags(ios::left)<<"| "<<setw(16) <<dt[i].nama;

cout<<"| "<<setw(12);cout<< dt[i].nb;

    cout<<"| "<<setw(15);cout<< dt[i].jb;

    cout<<"| "<<setw(15);cout<< dt[i].hb;

    cout<<"| "<<setw(18);cout<< dt[i].tb;

    cout<<"| "<<setw(24);cout<< dt[i].ket<<"|"<<endl;     

    cout<<"================================================================================================================="<<endl;

}

cout<<endl;

cout<<" Apakah ingin Menghitung Lagi [Y/N] : ";cin>>ulang;

}while (ulang == 'y' || ulang == 'Y');

cout<<endl;

system("cls");

}

else if (pilihan == 2)

{

program dt[20];

char a;

cin.ignore();

atas1:

system("cls");

cout<< "Masukan Nilai x  : ";cin>>dt[i].x;

if(dt[i].x * dt[i].x  < 40)

{

dt[i].y = 3 * dt[i].x - 5;

}

else

{

dt[i].y = dt[i].x + 4;

}

dt[i].z = 2 * dt[i].y;

if( dt[i].z % 4 == 0)

{

dt[i].w = (3 * dt[i].z)/ 4;

}

else

{

dt[i].w = (5 * dt[i].z - 6)/4;

}

cout<<endl;

cout<<"x = "<<dt[i].x<<endl;

cout<<"y = "<<dt[i].y<<endl;

cout<<"w = "<<dt[i].w<<endl;

cout<<"z = "<<dt[i].z<<endl;

cout<<endl;

cout<<"Apakah ingin Menghitung Lagi [Y/N] : ";cin>>a;

if(a=='Y' ||  a=='y')

goto atas1;

system("cls");

}

else if (pilihan==3)

{

program dt[20];

char a;

cin.ignore();

atas2:

system("cls");

cout<< "Masukan Nilai x  : ";cin>>dt[i].x;

if(dt[i].x % 2 == 0)

{

dt[i].y = (dt[i].x / 2)+3;

}

else

{

dt[i].y = 2 * dt[i].x - 1;

}

if( dt[i].y % 2 == 0)

{

dt[i].z = dt[i].y * dt[i].y  +1 ;

}

else

{

dt[i].z = 5 * dt[i].y - 10;

}

cout<<endl;

cout<<"x = "<<dt[i].x<<endl;

cout<<"y = "<<dt[i].y<<endl;

cout<<"z = "<<dt[i].z<<endl;

cout<<endl;

cout<<"Apakah ingin Menghitung Lagi [Y/N] : ";cin>>a;

if(a=='Y' ||  a=='y')

goto atas2;

system("cls");

    }

   

else if(pilihan==4)

{

program dt[20];

int i, n;

char ulang;

    do

{

system("cls");

cout<<"Masukkan Jumblah pembeli  : ";cin>>n;cin.ignore();

for(i=0;i<n;i++)

{

cout<< "Data ke-"<<i+1<<endl;

cout<< "Masukan Nama pembeli   : "; getline(cin, dt[i].nama);

cout<< "Masukan Nama barang    : "; cin>> dt[i].nb;

cout<< "Masukan Jumblah barang : "; cin>> dt[i].jb;

cout<< "Masukan Harga barang   : "; cin>> dt[i].hb;cin.ignore();

dt[i].t = dt[i].jb * dt[i].hb;

if (dt[i].t > 1500000)

{

dt[i].diskon = 0.25;

dt[i].ket = "Dapat Diskon 25%";

dt[i].tb = dt[i].diskon * dt[i].t;

}

else if(dt[i].t > 800000 && dt[i].t < 1500000)

dt[i].diskon = 0.15;

dt[i].ket = "Dapat Diskon 15%";

dt[i].tb = dt[i].diskon * dt[i].t;

}

else if(dt[i].t >= 500000 && dt[i].t < 800000)

dt[i].diskon = 0.05;

dt[i].ket = "Dapat Diskon 15%";

dt[i].tb = dt[i].diskon * dt[i].t;

}

else

{

dt[i].diskon = 1;

dt[i].ket = "Tidak dapat diskon";

}

    //dt[i].tb = dt[i].diskon * dt[i].t;

}

cout<<"                                        DATA BELANJA                                            "<<endl;

cout<<"============================================================================================================="<<endl;

cout<<"| NAMA PEMBELI      |  BARANG      | JUMBLAH BARANG | HARGA BARANG |  TOTAL BAYAR     |    KETERANGAN       |"<<endl;

cout<<"============================================================================================================="<<endl;

for(i=0;i<n;i++)

{

cout<<setiosflags(ios::left)<<"| "<<setw(18) <<dt[i].nama;

cout<<"| "<<setw(13);cout<< dt[i].nb;

    cout<<"| "<<setw(15);cout<< dt[i].jb;

    cout<<"| "<<setw(13);cout<< dt[i].hb *  dt[i].jb;

    cout<<"| "<<setw(17);cout<< dt[i].tb;

    cout<<"| "<<setw(20);cout<< dt[i].ket<<"|"<<endl;     

    cout<<"============================================================================================================="<<endl;

}

cout<<endl;

cout<<" Apakah ingin Menghitung Lagi [Y/N] : ";cin>>ulang;

}while (ulang == 'y' || ulang == 'Y');

cout<<endl;

system("cls");

}

else if (pilihan==5)

{

cout << "Anda Telah Keluar...!!!"<< endl;

exit(5);

    }

   

else

{

cout << "Kode Yang Anda Masukan Salah...!!!" << endl;

}

}

}

else

{

    cout<<""<<endl;

    cout<<""<<endl;

    cout<<"Gagal Masuk, Password atau Username Yang Anda Input Tidak Sesuai"<<endl;

}

i++;

}while(i<=3);

cout<<""<<endl;

cout<<"Anda telah 3x Memasukan Username dan Password yang salah"<<endl;

cout<<"Dengan Ini Saya Nyatakan Akun Anda Resmi Diblokir"<<endl;   

cout<<endl;

bawah:

getch();


}

No comments:

Post a Comment