Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
6.9 kB
3
Indexable
Never
#include <iostream>
#include <cstring>
#include <conio.h>

using namespace std;

#define MAX 20
typedef struct {
    int tgl;
    int bln;
    int thn;
}TANGGAL;

typedef struct {
    char noID[5];
    char name[30];
    char gender[20];
    TANGGAL date;
}KTP;

typedef struct {
    KTP ktp[MAX];
    int jmlh;
}DATAKTP;

DATAKTP dataKTP;
DATAKTP *p;
char male[10] = "Laki-Laki";
char female[10] = "Perempuan";
char genders;
bool loop = false, found;

void clearScreen() {
    cout << "\033[2J\033[1;1H";
}

void masukinLahcoehg(DATAKTP* data) {
    cout << "Masukkan jumlah data baru: ";
    int jmh= 0;
    cin >> jmh;
    jmh += data->jmlh;
    for (int i = data->jmlh; i < jmh ; ++i) {
        cout << "Data ke-" << i + 1 << endl;

        sprintf(data->ktp[i].noID, "%d", i + 1);
        cout << "Nomor ID : " << data->ktp[i].noID << endl;
        cout << "Masukkan nama : ";
        cin.ignore();
        cin.getline(data->ktp[i].name, sizeof(data->ktp[i].name));
        loop = false;
        do {
            cout << "Masukkan jenis kelamin (P/L) : ";
            cin >> genders;
            if (genders == 'L' || genders == 'l'){
                strcpy(data->ktp[i].gender, male);
                loop =true;
            }else if (genders == 'P' || genders == 'p'){
                strcpy(data->ktp[i].gender, female);
                loop =true;
            }
        }while (!loop);
        cout << "Masukkan tanggal lahir (tgl bln thn): ";
        cin >> data->ktp[i].date.tgl >> data->ktp[i].date.bln >> data->ktp[i].date.thn;
        data->jmlh += 1;
    }
    if (data->jmlh > MAX){
        cout<<"kapasitas habis!!!"<<endl;
    }
    cout << "Tekan tombol apa pun untuk melanjutkan...";
    getch();
    clearScreen();
}
void printData(DATAKTP* data, int i){
    cout << "\nData ke-" << i + 1 << endl;
    cout << "Nomor ID: " << data->ktp[i].noID << endl;
    cout << "Nama: " << data->ktp[i].name << endl;
    cout << "Jenis Kelamin: " << data->ktp[i].gender << endl;
    cout << "Tanggal Lahir: " << data->ktp[i].date.tgl << "/" << data->ktp[i].date.bln << "/" << data->ktp[i].date.thn << endl;
}
void liatSemuabray(DATAKTP* dataktp){
    if(dataktp->jmlh <= 0){
        cout  <<"Data kosong!!!..."<<endl;

    }{
        for(int i = 0; i < dataktp->jmlh; ++i){
            printData(dataktp, i);
        }
    }
    cout << "Tekan tombol apa pun untuk melanjutkan...";
    getch();
    clearScreen();
}
void seberapaTuaLu(DATAKTP* data){
    if(data->jmlh <= 0){
        cout  <<"Data kosong!!!..."<<endl;
    }else{
        int searchData;
        cout << "Mencari data berdasarkan Tahun" << endl;
        cout << "Masukan Tahun : ";
        cin >> searchData;
        found = false;
        for (int i = 0; i < data->jmlh; ++i) {
            if (searchData == data->ktp[i].date.thn){
                printData(data, i);
                found = true;
            }

        }
        if (!found){
            cout << "Data tidak ditemukan";
        }
    }
        getch();
        clearScreen();
}
void luLakiApaCewe(DATAKTP* data){
    found = false;
    if(data->jmlh <= 0){
        cout  <<"Data kosong!!!..."<<endl;
    }else{
        cout << "---Menampilkan data sesuai gender (L/P)--- "<<endl;
        loop = false;
        do {
            cout << "Masukkan jenis kelamin (P/L) : ";
            cin >> genders;
            if (genders == 'L' || genders == 'l'){
                for (int i = 0; i < data->jmlh; ++i) {
                    if(strcmp(data->ktp[i].gender, male) == 0){
                        printData(data, i);
                    found = true;
                    }
                }
                loop = true;
            }else if (genders == 'P' || genders == 'p'){
                for (int i = 0; i < data->jmlh; ++i) {
                    if(strcmp(data->ktp[i].gender, female) == 0){
                        printData(data, i);
                        found = true;
                    }
                }
                loop = true;
            }if (!found){
                cout <<"Data tidak ditemukan..."<<endl;
            }
        }while (!loop);
    }
        cout << "Tekan tombol apa pun untuk melanjutkan...";
        getch();
        clearScreen();
}
void editData(DATAKTP* dataEdit, int i){
    cout << "Masukkan nama : ";
    cin.ignore();
    cin.getline(dataEdit->ktp[i].name, sizeof(dataEdit->ktp[i].name));
    loop = false;
    do {
        cout << "Masukkan jenis kelamin (P/L) : ";
        cin >> genders;
        if (genders == 'L' || genders == 'l'){
            strcpy(dataEdit->ktp[i].gender, male);
            loop =true;
        }else if (genders == 'P' || genders == 'p'){
            strcpy(dataEdit->ktp[i].gender, female);
            loop =true;
        }
    }while (!loop);
    cout << "Masukkan tanggal lahir (tgl bln thn): ";
    cin >> dataEdit->ktp[i].date.tgl >> dataEdit->ktp[i].date.bln >> dataEdit->ktp[i].date.thn;
}
void ngapainNgab(DATAKTP* data){
    found= false;
    if(data->jmlh <= 0){
        cout  <<"Data kosong!!!..."<<endl;
    }else{
        char idSearch[5];
        cout <<"--edit data dengan id---"<<endl;
        cout <<"Masukan id Yang ingin dicari : ";
        cin>>idSearch;
        loop = false;
        do {
            for (int i = 0; i < data->jmlh; ++i) {
                if (strcmp(data->ktp[i].noID, idSearch) == 0){
                    editData(data, i);
                    found = true;
                    break;
                }
                loop = true;
            }
            if (!found){
                cout <<"Data tidak ditemukan..."<<endl;
            }
        } while (!loop);
    }
    cout << "Tekan tombol apa pun untuk melanjutkan...";
    getch();
    clearScreen();
}
int main() {
    p = &dataKTP;
    int x;
    do {
        cout << "---menu---"<< endl;
        cout << "Maksimal 10 Data"<< endl;
        cout << "---menu---"<< endl;
        cout << "1: sini masukin" << endl;
        cout << "2: mau liat?" << endl;
        cout << "3: kepo bet" << endl;
        cout << "4: lu laki?" << endl;
        cout << "5: anjay id" << endl;
        cout << "6. Exit....." << endl;
        cout << "Masukkan perintah:" << endl;
        cin >> x;

        switch (x) {
            case 1:
                masukinLahcoehg(p);
                break;
            case 2:
                liatSemuabray(p);
                break;
            case 3:
                seberapaTuaLu(p);
                break;
            case 4:
                luLakiApaCewe(p);
                break;
            case 5:
                ngapainNgab(p);
            default:
                break;
        }
    } while (x != 6);
//        getch();
}
Leave a Comment